1、下載本書的頭文件及示例源碼
原書地址:http://www.unpbook.com/src.html
2、解壓unpv13e.tar.gz
3、切換到unpv13文件夾后依次執(zhí)行
./configure
cd lib
make
cd ../libfree
make
此處出現(xiàn)了報錯:
inet_ntop.c:56:1: error: conflicting types for 'inet_ntop'
inet_ntop(af, src, dst, size)
^
/usr/include/arpa/inet.h:77:13: note: previous declaration is here
const char *inet_ntop(int, const void *, char *, socklen_t);
^
1 error generated.
make: *** [inet_ntop.o] Error 1
解決辦法:
找到inet_ntop.c文件把#include <arpa/inet.h>這行注釋掉,再次執(zhí)行上述命令,成功!
接下來執(zhí)行
cd ../intro
make daytimetcpcli
最后執(zhí)行編譯好的daytime文件
./daytimetcpcli 127.0.0.1
運行結(jié)果:
connect error: Connection refused
daytime服務(wù)被mac關(guān)閉了,所以顯示為refused,暫時還沒找到開啟的方法。。。
我們再換個服務(wù)器試試
./daytimetcpcli 64.113.32.5
這回成功返回時間!
57179 15-06-06 16:28:22 50 1 0 57.8 UTC(NIST) *
小伙伴們也可以試試其他地址,在這里http://tf.nist.gov/tf-cgi/servers.cgi 可以找到各服務(wù)器地址
參考:
http://www.cppfans.org/1411.html
http://blog.csdn.net/zjf280441589/article/details/18660697