《Unix网络编程》环境搭建

Ubuntu《Unix网络编程》环境搭建

下载文件

为了方便获取,我上传到了github

git clone https://github.com/orangeQWJ/unpv13e.git 

解压缩

tar -xzvf unpv13e/unpv13e.tar.gz 

按照README 依次执行

cd unpv13e
./configure
cd lib
make
cd ../libfree
make                 #报错 error: argument 'size' doesn't match prototype size_t size:

修改inet_ntop.c文件

	将60行的 size_t size 改成  socklen_t size

添加到共享库目录

sudo cp libunp.a /usr/lib                         # libunp.a 文件位于unpv13e目录下
sudo  cp libunp.a /usr/lib64/ 

修改unp.h

 unp.h 位于unpv13e/lib/

config.h 位于unpv13e/

将unp.h中将#include "../config.h"改成#include "config.h" 这样以后将unp.h 和config.h 一起放在源代码同级目录下   便可在程序中调用			
#include"unp.h" 
在unp.h中添加一行: #define MAX_LINE 2048	

程序各文件相对位置

case1:

在这里插入图片描述

不需要修改源代码
case 2:

在这里插入图片描述

	c文件如下更改 #include "../unp.h"   (c语言知识)

编译执行

gcc daytimetcpcli.c  -o   ONE  -lunp    # -lunp不能省略
./ONE  127.0.0.1

在这里插入图片描述

小问题

		程序报错

					connet error: Connection refused

需要打开本地服务器的daytime功能
sudo apt-get install xinetd

修改

sudo  vim /etc/xinetd.d/daytime   # 需要管理员权限

在这里插入图片描述

将两个disable 以后的yes 改成no

serice xinetd restart   #重启服务后运行程序即可
发布了3 篇原创文章 · 获赞 4 · 访问量 210

猜你喜欢

转载自blog.csdn.net/weixin_42007043/article/details/104758316