unix网路编程第一章 之环境搭建

来源:互联网 发布:品牌女装淘宝店铺 编辑:程序博客网 时间:2024/06/06 03:54

在进行本书的学习之前,我们首先进行环境的搭建

下载源代码http://download.csdn.net/detail/ymsdu2004/4906181

在当前工作目录下解压

cd unpv13e

[root@localhost unpv13e]# ./configure

[root@localhost unpv13e]# cd lib

[root@localhost lib]# make

 cd ../libfree

[root@localhost libfree]# make

(注:如果出现以下错误

inet_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,                    ^make: *** [inet_ntop.o] Error 1

则需修改
inet_ntop.c文件
[root@localhost libfree]#vim inet_ntop.c  //将第60行的 size_t size 改成 socklen_t size; 
[root@localhost libfree]# make  //改后重新make

将生成的libunp.a复制到/usr/lib下

[root@localhost libfree]# cd ..
[root@localhost unpv13e]# sudo cp libunp.a /usr/lib

 修改unpv13e/lib/unp.h并复制

@localhost unpv13e]# vim lib/unp.h  //// 将#include "../config.h" 改成 #include "config.h" 

[root@localhost unpv13e]# sudo cp lib/unp.h /usr/include
[root@localhost unpv13e]# sudo cp config.h /usr/include

 [root@localhost intro]# make daytimetcpsrv

[root@localhost intro]# sudo ./daytimetcpsrv

在另外一个终端

[root@localhost intro]# gcc daytimetcpcli.c -o cli -lunp

[root@localhost intro]# ./cli 127.0.0.1 //运行客户端程序 y