《UNIX網絡編程卷1》第一例及問題

《UNIX網絡編程卷1》一上來就給了一個例子,新手不容易看懂,估計做者也沒有打算讓人看懂,做了詳盡的解釋。新手都想運行這個程序,我也是。
首先,給的程序都是在unix下運行的。這裏有全書代碼。
個人環境是VMware Workstation 12.5.0 + ubuntu 16.04 LTS,已經裝了gcc。linux

  • 先按照/unpv13e/unpv13e/README文件裏面的流程走一遍:
tsc@tsc:~/bin/unpv13e/unpv13e$ ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
...
...
tsc@tsc:~/bin/unpv13e/unpv13e$ cd lib
tsc@tsc:~/bin/unpv13e/unpv13e/lib$ make
...
tsc@tsc:~/bin/unpv13e/unpv13e/lib$ cd ../libfree
tsc@tsc:~/bin/unpv13e/unpv13e/libfree$ make
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
tsc@tsc:~/bin/unpv13e/unpv13e/libfree$ cd ../libroute
tsc@tsc:~/bin/unpv13e/unpv13e/libroute$ make
gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o get_rtaddrs.o get_rtaddrs.c
In file included from get_rtaddrs.c:1:0:
unproute.h:3:45: fatal error: net/if_dl.h: 沒有那個文件或目錄
compilation terminated.
<builtin>: recipe for target 'get_rtaddrs.o' failed
make: *** [get_rtaddrs.o] Error 1

tsc@tsc:~/bin/unpv13e/unpv13e/libroute$ cd ../libxti
bash: cd: ../libxti: 沒有那個文件或目錄
tsc@tsc:~/bin/unpv13e/unpv13e/libroute$ cd ../intro
tsc@tsc:~/bin/unpv13e/unpv13e/intro$ make daytimetcpcli

tsc@tsc:~/bin/unpv13e/unpv13e/intro$ ./daytimetcpcli 127.0.0.1
connect error: Connection refused

能夠看到提示了錯誤connect error: Connection refused這裏有討論這個錯誤的。接下來:shell

  • 先編譯和運行daytimetcpsrv:
tsc@tsc:~/bin/unpv13e/unpv13e/intro$ make daytimetcpsrv
gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o daytimetcpsrv.o daytimetcpsrv.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv daytimetcpsrv.o ../libunp.a -lpthread
tsc@tsc:~/bin/unpv13e/unpv13e/intro$ sudo ./daytimetcpsrv

參考:make的做用編程

  • 再編譯和運行daytimetcpcli:
tsc@tsc:~/bin/unpv13e/unpv13e/intro$ ./daytimetcpcli 127.0.0.1
Fri Mar  3 20:37:48 2017

能夠看到,給出了系統當前時間,第一例運行成功。ubuntu

相關文章
相關標籤/搜索