unpv3源码在64位Linux上编译
Contents
[NOTE] Updated August 12, 2015. This article may have outdated content or subject matter.
-
从unpbook.com下载源代码
-
解压,安装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 cd ../libroute # only if your system supports 4.4BSD style routing sockets make # only if your system supports 4.4BSD style routing sockets cd ../libxti # only if your system supports XTI make # only if your system supports XTI cd ../intro # build and test a basic client program make daytimetcpcli ./daytimetcpcli 127.0.0.1
-
在libfree里面编译时会出现下面的错误:
⇒ make gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_ntop.o inet_ntop.c inet_ntop.c: 在函数‘inet_ntop’中: inet_ntop.c:62: 错误:实参‘size’与原型不符 /usr/include/arpa/inet.h:65: 错误:原型声明 make: *** [inet_ntop.o] 错误 1
-
上面的错误说明已经说的很清楚了,到/usr/include/arpa/inet.h里面看到size的类型是socklen_t而不是size_t,将inet_ntop.c中62行里面的size类型改成socklen_t,就可以编译通过了。
-
在libroute里面也会编译出错,这个不用管。
-
在libgai里面make,在上一级目录会生成libunp.a静态库,拷贝到/usr/lib文件夹下面
# cd libgai # make ar rv ../libunp.a ranlib ../libunp.a # cd .. # cp libunp.a /usr/lib # cp libunp.a /usr/lib64
-
将lib下 的unp.h和上一级目录下config.h拷贝到/usr/include下面,先将unp.h里面的
#include "../config.h"
改成#include "config.h"
# cp lib/unp.h /usr/include # cp config.h /usr/include
-
现在可以开始编译第一个程序了:
gcc daytimetcpcli.c -o test -lunp
,直接运行会出错,因为linux没有安装xinetd,安装好后将/etc/xinetd.h下面的daytime-stream和daytime-dgram里面的disable的值改为no,再启动服务就可以了。# yum install xinetd # /etc/init.d/xinetd start
-
最后的运行结果如下:
./test 127.0.0.1 12 AUG 2015 14:43:11 CST
参考
Author beyondkmp
LastMod 2015-08-12