"UNIX Network Programming Volume 1" Source code can be downloaded from www.unpbook.com. The directory after decompression is unpv13e.
1. Compiling
To enter the unpv13e directory, compile as follows:
1./Configure2 3 cd Lib4 Make //may encounter problems: redefinition of ' struct in_pktinfo '5 6Cd.. /Libfree7 Make 8 9Cd.. /LibrouteTen Make //This step can be error, can be ignored, only indicates that your system does not support 4.4BSD, does not affect the study of the book One ACd.. /Libgai - Make
For the above question ' redefinition of ' struct in_pktinfo ', we need to comment out the "struct in_pktinfo" struct declaration in Unpv13e/key/unp.h and Unpv13e/sctp/unp.h , as it has been included in the standard header file Bits/in.h. A recompile is required after the modification.
The above steps will generate a static library Libunp.a.
2. Copy the generated libunp.a static library to/usr/lib/and/usr/lib64/
1 CD. // 2sudocp libunp.a/usr/3sudocp
3. Modify the Unpv13e/lib/unp.h and copy it and config.h to/usr/include
1 // 2sudocp lib/unp.h/usr/3sudocp
4. Running the example (UNPV13E/INTRO/DAYTIMETCPCLI.C)
1) compile with static link library:-l parameter plus Libunp.a remove Lib and back. A. Finally get the parameter-LUNP
1 CD./2gcc
2) test the resulting executable file to get the current date of the machine:
1 127.0. 0.1
The following error occurs when you test:
1 Connect Error:connection refused
3) This error indicates that the daytime service program is not open and can be xinetd to control the service connection request. The following opens the daytime service program via XINETD.
1 sudo cd/etc/xinetd.d/2sudo vim daytime
If the Xinetd.d folder is empty, you will need to install the XINETD service first:
1 sudo Yum Install xinetd.x86_64
Change disable = Yes in Daytime-stream and daytime-dgram two files to disable = No, save exit and restart XINETD:
1 Service xinetd restart
4) Test This example again to display the local time successfully:
1 127.0. 0.1 2 A - : CST
Reference blog:
"Network Programming" on UNIX Network programming volume 1 Unp.h and source code compilation problem
Unix NetWork programming--Environment Building (solve unp.h and other source code compilation problems)
CentOS Open Daytime Server
"Learning Environment Building" of UNIX Network Programming Volume 1 (CentOS 7)