最近在学习《UNIX网络编程》,书上将经常使用的头文件都放在unp.h里,须要本身编译一下代码搭建环境。html
$ ./configure $ cd lib $ make $ cd ../libfree $ make
此时,会在unpv13e文件夹下产生一个libunp.a的库文件编程
$ cd ../intro # build and test a basic client program $ make daytimetcpcli $ ./daytimetcpcli 127.0.0.1
成功以后会显示以下:bash
$ ./daytimetcpcli 127.0.0.1 02 MAY 2015 12:05:03 CST
$ gcc daytimetcpcli.c -lunp
出现以下报错:网络
inet_ntop.c:61: error: argument 'size' doesn't match prototype /usr/include/arpa/inet.h:153: error: prototype declaration
处理:
修改libfree文件夹下的inet_ntop.c第61行 size_t size ->改为 socklen_t sizetcp
出现以下报错:学习
[root@localhost intro]# ./daytimetcpcli 127.0.0.1 connect error: Connection refused
处理:测试
disable yes
为disable no
$ /etc/xinetd.d/ restart
$ netstat -ant
开启daytime服务后,会有13这个端口ui
tcp 0 0 0.0.0.0:13 0.0.0.0:* LISTEN
出现以下报错:prototype
gcc -g -O2 -D_REENTRANT -Wall -c -o connect_nonb.o connect_nonb.c In file included from connect_nonb.c:1: unp.h:114: error: redefinition of ‘struct in_pktinfo’ make: *** [connect_nonb.o] 错误 1
处理:
结构in_pktinfo已经包含在标准头文件bits/in.h中了, 它又经过 netinet/in.h 在unp.h中被包括进来. 只要将 unp.h 中的结构定义comment out注释掉,而后从新编译libunp.arest