刚开始学,下载了源代码,直接进intro里make不行,上网查了下,发现给了一个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会报错,说
ethan@ethan-virtual-machine:~/unp/unpv13e/libfree$ make
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: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,
^
<builtin>: recipe for target 'inet_ntop.o' failed
make: *** [inet_ntop.o] Error 1
查了下,inet_ntop函数的声明是
const char *
inet_ntop(af, src, dst, size)
int af;
const void *src;
char *dst;
size_t size;
{
switch (af) {
case AF_INET:
return (inet_ntop4(src, dst, size));
case AF_INET6:
return (inet_ntop6(src, dst, size));
default:
errno = EAFNOSUPPORT;
return (NULL);
}
/* NOTREACHED */
}
而/usr/include/arpa/inet.h中的声明是
extern const char *inet_ntop (int __af, const void *__restrict __cp,
char *__restrict __buf, socklen_t __len)
__THROW;
参数类型不一致。
解决方法:《UNIX网络编程》源码编译
修改44 45 60 89 113行的size_t为socklen_t
修改后make,然后运行,又出现了的错误,需要打开服务器程序才可以
connect error: Connection refused
编译daytimetcpsrv程序并运行
make daytimetcpsrv
sudo ./daytimetcpsrv
然后再打开一个终端运行daytimetcpcli就可以了
ethan@ethan-virtual-machine:~/unp/unpv13e/intro$ ./daytimetcpcli 127.0.0.1
Thu Dec 6 22:05:27 2018
啊 心累。。