《UNIX网络编程》源码地址
wget http://www.unpbook.com/unpv13e.tar.gzcd unpv13e/按照README的指引进行
./configure # try to figure out all implementation differences
cd lib # build the basic library that all programs need
make # use "gmake" everywhere on BSD/OS systems
cd ../libfree # continue building the basic library
make注意,在编译libfree时,可能会出现编译错误
CentOS:
inet_ntop.c: In function ‘inet_ntop’:
inet_ntop.c:60:9: error: argument ‘size’ doesn’t match prototype
size_t size;MacOS:
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);
^解决方法:
vim inet_ntop.c把61行的size_t size改成socklen_t size后重新编一下
试着编译运行一下第一章的获取服务器时间的程序
cd ../intro # build and test a basic client program
make daytimetcpcli
./daytimetcpcli 127.0.0.1这里可能会报错:
connect error: Connection refused再开个窗口,编译运行一下同一个目录里的服务器程序
make daytimetcpsrv
sudo ./daytimetcpsrv然后在另外的会话运行一下刚刚的客户端程序
./daytimetcpcli 127.0.0.1
Thu Aug 2 13:20:53 2018发现正常运行
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。