One of UNIX Network Programming: Code environment to build

All switched article: https://zcheng.ren  internal article. 
This way there are a lot of great God, I hope to be able to read this term "UNIX Network Programming Volume: Sockets Networking API", the full text of this blog Transfers from the bloggers, but for which a supplementary explanation wrong place, measured success.

First, download the source code and compile 
the source code Download: http://www.unpbook.com/  , download files get unpv13e.tar.gz

Compilation step: 
decompression zxvf unpv13e.tar.gz

tar zxvf unpv13e.tar.gz

 

Enter unpv13e folder

cd ./unpv13e
./configure     //如果权限不够可以chmod改权限

 

Compiled lib file

cd lib
make          //出现大量warning,忽略之
cd ../libfree
make         //若出现错误,看后面横线内解决办法。无则跳过

 


Error follows: 
inet_ntop.c: the In function 'inet_ntop': 
inet_ntop.c: 60:. 9: error: argument 'size' does match the prototype Not 
size_t size; 
case in libfree directory, modified

vim inet_ntop.c  //将第60行的 size_t size 改成 socklen_t size;  

 

That re-make to fix the error.


Continue with the following command:

cd ../libgai
make

 

Second, the environment to build 
modify unp.h, the #include "../config.h" changed to #include "config.h", as follows:

1、cd .. //回到主目录
2、sudo vim lib/unp.h

 

Continue, copy header files to include

sudo cp config.h /usr/local/include
sudo cp lib/unp.h /usr/local/include

 

Copy in the library

sudo cp libunp.a /usr/local/lib

 

This code on unix network programming book can be compiled.

Third, the test sample code 
to examples intro / daytimetcpcli.c example: 
Compile daytimetcpcli.c file

cd ./intro  
gcc daytimetcpcli.c -o daytimetcpcli -lunp

 

run

./daytimetcpcli 127.0.0.1

 

When the test will receive an error

connect error:Connection refused

 

Ubuntu system needs to open at daytime, control may be implemented by a service connection request xinetd.

No xinetd.d, you need to install

sudo apt-get install xinetd

 

Then edit the daytime

vim daytime

 

The two later disable the file into yes no, save and exit 
reboot xinted.d

service xinetd restart

 

Test daytimetcpcli example again,

./daytimetcpcli 127.0.0.1

 

Get the right result

24 SEP 2017 17:35:47 CST

 

Published 78 original articles · won praise 9 · views 10000 +

Guess you like

Origin blog.csdn.net/heguangsui123/article/details/102777151