由於這是該書運行的第一個程序,以此筆記記錄如何運行該書上的代碼,以及初次運行所發生的錯誤。
第一步:參照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中只定義了這一個對象,改成別的對象也不可能。
再次編譯
sudo ./daytimetcpsrv (如果本身就是root就不需要sudo)
然後再開一個終端運行 ./daytimetcpcli 127.0.0.1 就可以看到返回的時間了
Fri Jan 23 16:16:43 2015