《UNIX网络编程卷1》第一例及问题

来源:互联网 发布:js实现格式化html代码 编辑:程序博客网 时间:2024/04/30 06:01

《UNIX网络编程卷1》一上来就给了一个例子,新手不容易看懂,估计作者也没有打算让人看懂,作了详尽的解释。新手都想运行这个程序,我也是。
首先,给的程序都是在unix下运行的。这里有全书代码。
我的环境是VMware Workstation 12.5.0 + ubuntu 16.04 LTS,已经装了gcc。

  • 先按照/unpv13e/unpv13e/README文件里面的流程走一遍:
tsc@tsc:~/bin/unpv13e/unpv13e$ ./configurechecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking for gcc... gcc......tsc@tsc:~/bin/unpv13e/unpv13e$ cd libtsc@tsc:~/bin/unpv13e/unpv13e/lib$ make...tsc@tsc:~/bin/unpv13e/unpv13e/lib$ cd ../libfreetsc@tsc:~/bin/unpv13e/unpv13e/libfree$ makegcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o inet_ntop.o inet_ntop.cinet_ntop.c: In function ‘inet_ntop’:inet_ntop.c:60:9: error: argument ‘size’ doesn’t match prototype  size_t size;         ^In file included from inet_ntop.c:27:0:/usr/include/arpa/inet.h:64:20: error: prototype declaration extern const char *inet_ntop (int __af, const void *__restrict __cp,                    ^<builtin>: recipe for target 'inet_ntop.o' failedmake: *** [inet_ntop.o] Error 1tsc@tsc:~/bin/unpv13e/unpv13e/libfree$ cd ../libroutetsc@tsc:~/bin/unpv13e/unpv13e/libroute$ makegcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o get_rtaddrs.o get_rtaddrs.cIn file included from get_rtaddrs.c:1:0:unproute.h:3:45: fatal error: net/if_dl.h: 没有那个文件或目录compilation terminated.<builtin>: recipe for target 'get_rtaddrs.o' failedmake: *** [get_rtaddrs.o] Error 1tsc@tsc:~/bin/unpv13e/unpv13e/libroute$ cd ../libxtibash: cd: ../libxti: 没有那个文件或目录tsc@tsc:~/bin/unpv13e/unpv13e/libroute$ cd ../introtsc@tsc:~/bin/unpv13e/unpv13e/intro$ make daytimetcpclitsc@tsc:~/bin/unpv13e/unpv13e/intro$ ./daytimetcpcli 127.0.0.1connect error: Connection refused

可以看到提示了错误connect error: Connection refused,这里有讨论这个错误的。接下来:

  • 先编译和运行daytimetcpsrv:
tsc@tsc:~/bin/unpv13e/unpv13e/intro$ make daytimetcpsrvgcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o daytimetcpsrv.o daytimetcpsrv.cgcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv daytimetcpsrv.o ../libunp.a -lpthreadtsc@tsc:~/bin/unpv13e/unpv13e/intro$ sudo ./daytimetcpsrv

参考:make的作用

  • 再编译和运行daytimetcpcli:
tsc@tsc:~/bin/unpv13e/unpv13e/intro$ ./daytimetcpcli 127.0.0.1Fri Mar  3 20:37:48 2017

可以看到,给出了系统当前时间,第一例运行成功。

0 0