UNIX网络编程daytimetcpcli.c运行笔记

来源:互联网 发布:长袖连衣裙淘宝网秋季 编辑:程序博客网 时间:2024/05/22 01:28

由于这是该书运行的第一个程序,以此笔记记录如何运行该书上的代码,以及初次运行所发生的错误。

第一步:参照read me的步骤逐步照做。

cd unpv12e
    ./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 ../libgai   # the getaddrinfo() and getnameinfo() functions
    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 daytimetcpsrv

    make daytimetcpcli

其中,在编译基本库libfree时出错,

报错内容如下:

gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o in_cksum.o in_cksum.c

gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_ntop.o inet_ntop.c

inet_ntop.c: In function ‘inet_ntop’:

inet_ntop.c:61: error: argument ‘size’ doesn’t match prototype

/usr/include/arpa/inet.h:65: error: prototype declaration

make: *** [inet_ntop.o] Error 1


网上找的更正方法:

inet_ntop.c第61行 size_t size ->改成 socklen_t size)

PS:虽然不知道为什么要这么改,但是看起来好神奇的样子。

应该是将inet_ntop.c中的对象改成和.inet.h中的对象对应,等下可详细了解。

PS2:查看/usr/include/arpa/inet.h的源码可知,确实在inet.h第26行定义了socklen_t,为什么知道这么改呢?不过貌似inet.h中只定义了这一个对象,改成别的对象也不可能。

再次编译

$ make
第二步,分别运行daytimetcpsrv, daytimetcpcli
由于要打开端口,所以服务端程序需要用root权限执行,所以你可以先   

    sudo   ./daytimetcpsrv  (如果本身就是root就不需要sudo)

  然后再开一个终端运行   ./daytimetcpcli 127.0.0.1  就可以看到返回的时间了
运行结果如下:
metcpcli 127.0.0.1
Fri Jan 23 16:16:43 2015
0 0
原创粉丝点击