0x00 前言

文章中的文字可能存在语法错误以及标点错误,请谅解;

如果在文章中发现代码错误或其它问题请告知,感谢!

系统版本:Ubuntu 14.04_64

最后更新:2022-03-23

0x01配置步骤

1.下载&解压unpv13e

可以通过http://www.unpbook.com/unpv13e.tar.gz下载,也可以通过https://www.ituring.com.cn/book/164下载(本文选择此链接下载)。

下载完成后,解压源码传送到Ubuntu中。

2.查看unpv13e中README文件配置unp.h头文件

README内容如下,按照步骤一步一步配置:

QUICK AND DIRTY
===============Execute the following from the src/ directory:./configure    # try to figure out all implementation differencescd lib         # build the basic library that all programs needmake           # use "gmake" everywhere on BSD/OS systemscd ../libfree  # continue building the basic librarymakecd ../libroute # only if your system supports 4.4BSD style routing socketsmake           # only if your system supports 4.4BSD style routing socketscd ../libxti   # only if your system supports XTImake           # only if your system supports XTIcd ../intro    # build and test a basic client programmake daytimetcpcli./daytimetcpcli 127.0.0.1If all that works, you're all set to start compiling individual programs.Notice that all the source code assumes tabs every 4 columns, not 8.MORE DETAILS
============5.  If you need to make any changes to the "unp.h" header, notice that itis a hard link in each directory, so you only need to change it once.6.  Go into the "lib/" directory and type "make".  This builds the library"libunp.a" that is required by almost all of the programs.  There maybe compiler warnings (see NOTES below).  This step is where you'll findall of your system's dependencies, and you must just update your cf/files from step 1, rerun "config" and do this step again.6.  Go into the "libfree/" directory and type "make".  This adds to the"libunp.a" library.  The files in this directory do not #includethe "unp.h" header, as people may want to use these functionsindependent of the book's examples.8.  Once the library is made from steps 5 and 6, you can then go into anyof the source code directories and make whatever program you areinterested in.  Note that the horizontal rules at the beginning andend of each program listing in the book contain the directory name andfilename.BEWARE: Not all programs in each directory will compile on all systems(e.g., the file src/advio/recvfromflags.c will not compile unless yoursystem supports the IP_RECVDSTADDR socket option).  Also, not all filesin each directory are included in the book.  Beware of any files with"test" in the filename: they are probably a quick test program that Iwrote to check something, and may or may not work.NOTES
------ Many systems do not have correct function prototypes for the socketfunctions, and this can cause many warnings during compilation.For example, Solaris 2.5 omits the "const" from the 2nd argumentto connect().  Lots of systems use "int" for the length of socketaddress structures, while Posix.1g specifies "size_t".  Lots ofsystems still have the pointer argument to [sg]etsockopt() as a"char *" instead of a "void *", and this also causes warnings.- SunOS 4.1.x: If you are using Sun's acc compiler, you need to runthe configure program asCC=acc CFLAGS=-w CPPFLAGS=-w ./configureFailure to do this results in numerous system headers (<sys/sockio.h>)not being found during configuration, causing compile errors later.- If your system supports IPv6 and you want to run the examples in thebook using hostnames, you must install the latest BIND release.  Youcan get it from ftp://ftp.vix.com/pub/bind/release.  All you need fromthis release is a resolver library that you should then add to theLDLIBS and LDLIBS_THREADS lines.- IPv6 support is still in its infancy.  There may be differencesbetween the IPv6 sockets API specifications and what the vendorprovides.  This may require hand tweaking, but should get betterover time.- If your system supports an older draft of the Posix pthreads standard,but configure detects the support of pthreads, you will have to disablethis by hand.  Digital Unix V3.2C has this problem, for example, as itsupports draft 4, not the final draft.To fix this, remove wrappthread.o from LIB_OBJS in "Make.defines" anddon't try to build and run any of the threads programs.COMMON DIFFERENCES
------------------These are the common differences that I see in various headers that are
not "yet" at the level of Posix.1g or X/Open XNS Issue 5.- getsockopt() and setsockopt(): 5th argument is not correct type.- t_bind(): second argument is missing "const".- t_connect(): second argument is missing "const".- t_open(): first argument is missing "const".- t_optmsmg(): second argument is missing "const".- If your <xti.h> defines the members of the t_opthdr{} as longs,instead of t_uscalar_t, some of the printf formats of these valuemight generate warnings from your compiler, since you are printinga long without a corresponding long format specifier.

3.1配置脚本

在unpv13e打开终端,执行:

#./configure

3.2 创建lib库

#cd ./lib
#make

3.3创建libfree库

#cd ../libfree
#make

make时可能会有如下报错:
打开该目录下inet_ntop.c文件,定位60行修改为socklen_t size;,保存后执行make,通过:

const char *
inet_ntop(af, src, dst, size)int af;const void *src;char *dst;socklen_t size;

3.4创建libroute库

3.4步骤适用于支持4.4BSD系统,可直接跳到3.5。

#cd ../libroute
#make

make时可能会有如下报错:
新建if_dl.h文件,填写如下内容保存后将该if_dl.h文件移动到/usr/include/net目录下:

/** Copyright (c) 1990, 1993*  The Regents of the University of California.  All rights reserved.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:* 1. Redistributions of source code must retain the above copyright*    notice, this list of conditions and the following disclaimer.* 2. Redistributions in binary form must reproduce the above copyright*    notice, this list of conditions and the following disclaimer in the*    documentation and/or other materials provided with the distribution.* 3. All advertising materials mentioning features or use of this software*    must display the following acknowledgement:*  This product includes software developed by the University of*  California, Berkeley and its contributors.* 4. Neither the name of the University nor the names of its contributors*    may be used to endorse or promote products derived from this software*    without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE* ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF* SUCH DAMAGE.**  @(#)if_dl.h 8.1 (Berkeley) 6/10/93*//* * A Link-Level Sockaddr may specify the interface in one of two* ways: either by means of a system-provided index number (computed* anew and possibly differently on every reboot), or by a human-readable* string such as "il0" (for managerial convenience).* * Census taking actions, such as something akin to SIOCGCONF would return* both the index and the human name.* * High volume transactions (such as giving a link-level ``from'' address* in a recvfrom or recvmsg call) may be likely only to provide the indexed* form, (which requires fewer copy operations and less space).* * The form and interpretation  of the link-level address is purely a matter* of convention between the device driver and its consumers; however, it is* expected that all drivers for an interface of a given if_type will agree.*//** Structure of a Link-Level sockaddr:*/
struct sockaddr_dl {u_char  sdl_len;    /* Total length of sockaddr */u_char  sdl_family; /* AF_DLI */u_short sdl_index;  /* if != 0, system given index for interface */u_char  sdl_type;   /* interface type */u_char  sdl_nlen;   /* interface name length, no trailing 0 reqd. */u_char  sdl_alen;   /* link level address length */u_char  sdl_slen;   /* link layer selector length */char    sdl_data[12];   /* minimum work area, can be larger;contains both if name and ll address */
};#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))#ifndef KERNEL#include <sys/cdefs.h>__BEGIN_DECLS
void    link_addr __P((const char *, struct sockaddr_dl *));
char    *link_ntoa __P((const struct sockaddr_dl *));
__END_DECLS#endif /* !KERNEL */
#sudo mv if_dl.h /usr/include/net

3.5创建libxti库

3.5步骤适用于支持XTI系统,若不支持可直接跳到3.6。

#cd ../libxti
#make

3.6测试

#cd ../intro
#make daytimetcpsrv
#make daytimetcpcli
#./daytimetcpsrv &
#./daytimetcpcli 127.0.0.1

测试结果如下:

3.将unp.h及静态库添加编译路径

#cp unpv13e/lib/unp.h    /usr/include
#cp unpv13e/config.h    /usr/include
#cp unpv13e/libunp.a    /usr/lib

修改/usr/include路径下unp.h头文件中的第7行为:

#include <config.h>

测试:

#include<stdio.h>
#include<unp.h>
int main(){printf("hello world\n");return 0;
}

编译无错误则成功。

以上。

参考文档:
1.https://blog.csdn.net/ASCE_S/article/details/106969129

《UNIX网络编程》配置unp.h头文件相关推荐

  1. Unix网络编程之-------unp.h头文件详细配置-1

    unix网络编程unp.h最详细全面配置说明 今天开始学习Unix网络编程这本大神之作了,由于之前在学习另外一本杰作Unix环境高级编程,遇到过第一个程序编译报错的情况,知道这是大神自己写的头文件在我 ...

  2. UNIX网络编程之旅-配置unp.h头文件环境

    最近在学习Unix网络编程(UNP),书中steven在处理网络编程时只用了一个#include "unp.h"  相当有个性并且也很便捷 于是我把第三版的源代码编译实现了这个过程 ...

  3. Unix——《Unix网络编程》配置unp.h头文件

    <Unix网络编程 卷1>unp.h 头文件及其编译问题 本书源码下载地址 http://www.unpbook.com 解压tar -zxvf unpv13e.tar.gz 其实各个编译 ...

  4. [转载]配置unp.h头文件环境

    原文:http://blog.csdn.net/wd4084/article/details/6452574 最近在学习Unix网络编程(UNP),书中steven在处理网络编程时只用了一个#incl ...

  5. 04.配置unp.h头文件出现开启 xinetd daytime 服务时 /etc/xinetd.d下 没有daytime 文件的解决办法

    一.引言 最近在学习 <Unix网络编程 卷1:套接字联网 API>.在编译其第一份代码 daytimetcpcli.c 的时候,发现作者使用到了 daytime 服务.比如下面这行代码: ...

  6. 文件 单片机_单片机C语言编程中reg52.h头文件的作用

    前言:本人出于爱好将不定期发送电气电工.前端.单片机等内容,可能会无法顾及关注我的所有人需求,请大家按需收藏自己想要知识,有用则收之,无用则弃之,不系统更新,仅供零星学习O(∩_∩)O哈哈~ 在代码的 ...

  7. Unix网络编程unp.h问题以及Linux中的库

    Stevens的<UNIX网络编程 卷1:套接字连网API>是一本很著名的UNIX网络编程书籍.其中使用了一个unp.h的引用,如果没有设置相应的库的话,即使引入了头文件也是没用的.所以首 ...

  8. 《网络编程》关于 UNIX网络编程 卷1 的 unp.h 和源码编译问题

    本文针对<网络编程 卷1>unp.h 头文件及其编译问题进行记录,本书源码下载地址http://www.unpbook.com 首先进行编译,在目录 unpv13e下依次执行以下步骤: . ...

  9. 《Unix网络编程(第3版)》代码编译的一些问题

    现在学习<UNIX网络编程(第3版)>一书,书中源代码有一些默认情况下编译不能通过,要经过一些修改都行.这编文档将记录下我遇到的不能正常编译的程序的修改步骤. 28章:traceroute ...

最新文章

  1. 绘制三维散点图_质量工具--之散点图
  2. yarn、npm、cnpm三者区别
  3. 字体编辑器_FontLab 7 ——字体编辑器
  4. apache 部署python3_centos7.6+python3+apache2.4+django2.1.2网站部署总结
  5. python利用faker,输出企业名称、用户名称、手机号、地址信息等测试数据实例
  6. 网络通信 route(公司局域网配置)
  7. 图片随意移动,可以拖动图片计算
  8. html三列布局和两列布局,CSS 常见两列布局、三列布局
  9. html单元格选中状态,UITableViewCell 设置单元格选中后只显示一个打勾的状态
  10. 一个小问题(语法分析中的括号匹配)
  11. el-tooltip位置不灵活_小厨房里的收纳,贵在灵活
  12. easypr arm linux,zhangdy
  13. LINUX 线程启动回调函数
  14. html+css+js实现小游戏flybird(完整版)
  15. 巨潮网站爬虫程序修改
  16. 锐意创新,引领音视频未来
  17. firefox html5 pop,数组的push、unshift、pop、shift方法实现
  18. java哪些类重写equals方法_Java自定义类中重写equals方法
  19. 智能经济大局下,云智一体的“形胜”
  20. C++语法整理(From GitHub)

热门文章

  1. python(数据分析与可视化)六
  2. 模拟除法计算|L1-046 整除光棍 (20分)(思路)
  3. 一条狗的死亡,引发3亿网友愤怒!希望这条黑科技 “汪星人” 能从小培养人的爱心 | 钛空智慧星球推荐
  4. iOS模仿安卓Material Design的涟漪动画按钮
  5. 解决git commit提示Please tell me who you are
  6. 【智力题】:毒酒问题
  7. 安卓 SDK 开发使用 VirtualAPK 实现插件化
  8. 转转二手交易平台建设高效率循环经济链
  9. el-tooltip的使用(根据条件控制显示)
  10. socket 编程基础