UNIX网络编程卷1(第三版)一个简单的时间获取服务器的程序

#1.解压文件进入主目录 cd intro

#2.直接编译 gcc -o 1.out daytimetcpcli.c #错误提示如下: daytimetcpcli.c:1:17: fatal error: unp.h: No such file or directory #include "unp.h" ^ compilation terminated. #在../key目录下找到unp.h。继续提醒没有<sys/fiflo.h>从网上下载继续出问题。

#3.看到目录下有make文件,make一下:显示如下: peace@peace:~/workspace/unpv13e/unpv13e/intro$ make Makefile:1: ../Make.defines: No such file or directory make: *** No rule to make target '../Make.defines'. Stop.

从网下在下来源码然后编译就出了问题,百度,发现很多人跟我遇到同样的问题,还是参考下网友的经验,从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时出现了下面的错误

错误提示inet_ntop.c中60行声明与原型申明/usr/include/arpa/inet.h不匹配。(#include一般所在文件都在/usr/include中)
经查验,最后一个参数,在inet.h中定义socklen_t,而inet_ntop.c中定义为size_t。在inet_ntop.c中加入如下代码即可:(插入到所有头文件之后)

#define size_t socklen_t 

然后make通过。

接着编译

原来是daytime服务没有开启!

在后台运行./daytimetcpsvr,让服务器端后台执行,这里是借助srv程序来开启系统的daytime服务程序。

至此,unix网络编程卷一的第一个例子完美运行。

猜你喜欢

转载自blog.csdn.net/dop102/article/details/89706100