前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >《UNIX网络编程》源码编译

《UNIX网络编程》源码编译

原创
作者头像
jackieluo
修改2018-08-02 13:53:14
1.4K0
修改2018-08-02 13:53:14
举报
文章被收录于专栏:Jackie技术随笔Jackie技术随笔

本书源码下载地址

浏览器下载

《UNIX网络编程》源码地址

wget

wget http://www.unpbook.com/unpv13e.tar.gz

开始编译

cd unpv13e/

按照README的指引进行

./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

size_t未定义问题

注意,在编译libfree时,可能会出现编译错误

CentOS:

inet_ntop.c: In function ‘inet_ntop’:
inet_ntop.c:60:9: error: argument ‘size’ doesn’t match prototype
  size_t size;

MacOS:

inet_ntop.c:56:1: error: conflicting types for 'inet_ntop'
inet_ntop(af, src, dst, size)
^
/usr/include/arpa/inet.h:77:13: note: previous declaration is here
const char      *inet_ntop(int, const void *, char *, socklen_t);
                 ^

解决方法:

vim inet_ntop.c

把61行的size_t size改成socklen_t size后重新编一下

运行示例程序

试着编译运行一下第一章的获取服务器时间的程序

cd ../intro    # build and test a basic client program
make daytimetcpcli
./daytimetcpcli 127.0.0.1

Connection refused错误

这里可能会报错:

connect error: Connection refused

再开个窗口,编译运行一下同一个目录里的服务器程序

make daytimetcpsrv
sudo ./daytimetcpsrv

然后在另外的会话运行一下刚刚的客户端程序

./daytimetcpcli 127.0.0.1
Thu Aug  2 13:20:53 2018

发现正常运行

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 本书源码下载地址
    • 浏览器下载
      • wget
      • 开始编译
        • size_t未定义问题
        • 运行示例程序
          • Connection refused错误
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档