Unix网络编程第三版源码编译

笔记_UNIX环境网络编程卷二进程间通信_中文第二版.pdf 笔记_UNIX环境网络编程卷二进程间通信_中文第二版 立即下载
环境:
$ cat /etc/issue
Ubuntu 12.04.1 LTS \n \l

$ cat /proc/version
Linux version 3.2.0-48-generic (buildd@komainu) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #74-Ubuntu SMP Thu Jun 6 19:43:26 UTC 2013

$ uname -a
Linux ubuntu-server 3.2.0-48-generic #74-Ubuntu SMP Thu Jun 6 19:43:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


下载:
$ git clone https://github.com/maxliaops/Unix-Network-Programming.git

配置:
$ cd Unix-Network-Programming/
$ chmod 755 configure
$ ./configure
主要的工作是检查系统是否有源码编译所依赖的各种资源(系统版本是否匹配、编译器、库文件、头文件以及结构体定义等等)
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for ranlib... ranlib
checking for pthread_create in -lpthread... yes
checking for t_open in -lnsl... no
checking for library containing socket... none required
checking for /usr/local/bind/lib/libbind.a... no
checking for /home/liaops/libbind.a... no
checking for /home/liaops/libresolv.a... no
checking for res_init in -lresolv... no
checking for t_open in -lxti... no
checking for /home/liaops/libunp.a... no
checking for /home/liaops/libunpxti.a... no
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/socket.h... yes
checking for sys/time.h... yes
checking for time.h... yes
checking for netinet/in.h... yes
checking for arpa/inet.h... yes
checking for errno.h... yes
checking for fcntl.h... yes
checking for netdb.h... yes
checking for signal.h... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for sys/stat.h... yes
checking for sys/uio.h... yes
checking for unistd.h... yes
checking for sys/wait.h... yes
checking for sys/un.h... yes
checking for sys/param.h... yes
checking for sys/select.h... yes
checking for sys/sysctl.h... yes
checking for poll.h... yes
checking for sys/event.h... no
checking for strings.h... yes
checking for sys/ioctl.h... yes
checking for sys/filio.h... no
checking for sys/sockio.h... no
checking for pthread.h... yes
checking for net/if_dl.h... no
checking for xti.h... no
checking for xti_inet.h... no
checking for netconfig.h... no
checking for netdir.h... no
checking for stropts.h... yes
checking whether time.h and sys/time.h may both be included... yes
checking if uint8_t defined... yes
checking if int16_t defined... yes
checking if uint16_t defined... yes
checking if int32_t defined... yes
checking if uint32_t defined... yes
checking if size_t defined... yes
checking if ssize_t defined... yes
checking if socklen_t defined... yes
checking if sa_family_t defined... yes
checking if t_scalar_t defined... no
checking if t_uscalar_t defined... yes
checking for struct sockaddr.sa_len... no
checking for struct sockaddr_storage... yes
checking for struct sockaddr_storage.ss_family... yes
checking for struct msghdr.msg_control... yes
checking for struct ifreq.ifr_mtu... yes
checking for getaddrinfo function prototype in netdb.h... yes
checking for getnameinfo function prototype in netdb.h... yes
checking for gethostname function prototype in unistd.h... yes
checking for getrusage function prototype in sys/resource.h... yes
checking for hstrerror function prototype in netdb.h... yes
checking for if_nametoindex function prototype in net/if.h... yes
checking for inet_aton function prototype in arpa/inet.h... yes
checking for inet_pton function prototype in arpa/inet.h... yes
checking for pselect function prototype in sys/select.h... yes
checking for snprintf function prototype in stdio.h... yes
checking for sockatmark function prototype in sys/socket.h... yes
checking for struct addrinfo... yes
checking for struct if_nameindex... yes
checking for struct sockaddr_dl... no
checking for struct timespec... yes
checking for /dev/tcp... no
checking for /dev/xti/tcp... no
checking for /dev/streams/xtiso/tcp... no
checking for bzero... yes
checking for getaddrinfo... yes
checking for gethostname... yes
checking for gethostbyname2... yes
checking for gethostbyname_r... yes
checking for getnameinfo... yes
checking for hstrerror... yes
checking for if_nametoindex... yes
checking for inet_aton... yes
checking for inet_pton... yes
checking for inet6_rth_init... yes
checking for kqueue... no
checking for kevent... no
checking for mkstemp... yes
checking for poll... yes
checking for pselect... yes
checking for snprintf... yes
checking for sockatmark... yes
checking for vsnprintf... yes
checking for IPv4 support... yes
checking for IPv6 support... yes
checking for Unix domain sockets... yes
checking for multicast support... yes
checking for -I/home/liaops/doc/unp2ev1/src/include... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating Make.defines
config.status: creating config.h



编译库:

编译所有例程都需要用到的基础库
$ cd lib
$ make

得到静态库文件:libudp.a

查看符号表 (主要是想看一下这个库的各个源文件调用了哪些Linux系统调用)
$ nm -g libunp.a

从中可以发现以下几个文件比较重要,主要是对常用的API进行了一层包装。
wrapsock.o:     对套接字socket的包装
    accept
    bind
    connect
    err_quit
    err_sys
    getenv
    getpeername
    getsockname
    getsockopt
    inet6_rth_add
    inet6_rth_getaddr
    inet6_rth_init
    inet6_rth_reverse
    inet6_rth_segments
    inet6_rth_space
    listen
    poll
    recv
    recvfrom
    recvmsg
    select
    send
    sendmsg
    sendto
    setsockopt
    shutdown
    sockatmark
    socket
    socketpair
    strtol
wrapstdio.o:    对标准IO库中文件相关函数的包装
    fclose
    fdopen
    ferror
    fgets
    fopen
    fputs
wrappthread.o:  对线程库pthread的包装
    pthread_cond_broadcast
    pthread_cond_signal
    pthread_cond_timedwait
    pthread_cond_wait
    pthread_create
    pthread_detach
    pthread_join
    pthread_key_create
    pthread_kill
    pthread_mutex_init
    pthread_mutex_lock
    pthread_mutex_unlock
    pthread_mutexattr_init
    pthread_mutexattr_setpshared
    pthread_once
    pthread_setspecific
wrapunix.o:     对其他常用Linux/Unix系统调用的包装
    __strdup
    calloc
    close
    dup2
    err_quit
    err_sys
    fcntl
    fork
    gettimeofday
    ioctl
    malloc
    mkstemp
    mmap
    open
    pipe
    read
    sigaddset
    sigdelset
    sigemptyset
    sigfillset
    sigismember
    sigpending
    sigprocmask
    sysconf
    sysctl
    unlink
    wait
    waitpid
    write

问题:为什么要对这些API接口进行包装,是否多此一举?




继续编译基本库
$ cd ../libfree/
$ make
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o in_cksum.o in_cksum.c
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:61: error: argument ‘size’ doesn’t match prototype
/usr/include/arpa/inet.h:65: error: prototype declaration
make: *** [inet_ntop.o] Error 1

出现错误!

Fix:
inet_ntop.c第61行 size_t size ->改成 socklen_t size)

再次编译
$ make
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_ntop.o inet_ntop.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_pton.o inet_pton.c
ar rv ../libunp.a in_cksum.o inet_ntop.o inet_pton.o
a - in_cksum.o
a - inet_ntop.o
a - inet_pton.o
ranlib ../libunp.a

貌似这次编译的内容并到了libunp.a中,没有生成新的库文件。


$ cd ../libgai
$ make
ar rv ../libunp.a
ranlib ../libunp.a


拷贝生成的库文件到系统库目录
$ cd ..
$ sudo cp libunp.a /usr/lib
$ sudo cp libunp.a /usr/lib32

以后编译代码的时候加上-lunp链接我们的库。

修改unp.h并将其和config.h拷贝到/usr/include中




编译并测试一个基本的客户端例程

$ cd intro/
$ make daytimetcpcli
gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcli.o daytimetcpcli.c
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli daytimetcpcli.o ../libunp.a -lpthread

编译成功后,在当前目录会生成可执行镜像daytimetcpcli

运行daytimetcpcli
$ ./daytimetcpcli
usage: a.out <IPaddress>

$ ./daytimetcpcli 127.0.0.1
connect error: Connection refused

Fix:
开启daytime服务

$ 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

sudo ./daytimetcpsrv &

再次运行daytimetcpcli
$ ./daytimetcpcli 127.0.0.1
Mon Mar 3 22:47:35 2014

UNIX网络编程 卷1第三版 PDF中文 带源码 2of2 UNIX网络编程 卷1 中文版 PDF高清带索引 附带源码 By W. Richard Stevens, Bill Fenner, Andrew M. Rudoff 立即下载

相关推荐

UNIX网络编程第三版

全面深入地介绍了如何使用套接字API进行网络编程。全书不但介绍了基本编程内容,还涵盖了与套接字编程相关的高级主题,对于客户/服务器程序的各种设计方法也作了完整的探讨,最后还深入分析了流这种设备驱动机制。

UNIX网络编程卷1:套接字联网API(第3版) 中文高清带完整书签 PDF

《UNIX网络编程 卷1:套接字联网API(第3版)》┊(美)W. Richard Stevens Bill Fenner Andrew M. Rudoff[.PDF]

嵌入式C 8954

UNIX网络编程卷1.pdf

UNIX网络编程卷1.pdf socket

UNIX网络编程卷1(第三版)关于源程序编译出错问题的详细解决方法

 环境说明(应该也使用于其他Linux版本): Linux系统: Ubuntu10.04 gcc  版本: gcc –version的结果 gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3 参考3中提供了 sys/event.h,sockio.h,ioccom.h等头文件下载, filio.h头文件没找到,但不影响编译运行,filio.h

jin的专栏 3271

UNIX网络编程 卷1 (目录版)

unix网络编程(第三版),本人亲自撰写PDF目录,使用得心应手!

UNIX网络编程_卷2

进程间通信几乎是所有Unix程序性能的关键,理解进程间通信也是理解如何开发不同主机间网络应用程序的必要条件

《Unix网络编程》第一卷第三版 源码编译ubuntu

QUICK AND DIRTY Execute the following from the src/ directory: ./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

weixin_45363995的博客 306

《UNIX网络编程 卷1:套接字联网API》.pdf

《UNIX网络编程 卷1:套接字联网API》.pdf

《Unix网络编程》卷一第三版源码配置

转自:UNIX网络编程卷1:源码配置 本节主要介绍UNIX网络编程卷1(第三版)在Ubuntu16.04的配置问题,并运行一个简单时间获取客户程序。 首先下载源文件,链接如下:http://www.unpbook.com/src.html 将下载好的压缩文件unpv13e.tar.gz解压,解压后文件为unpv13e. 解压后进入源码目录,打开README文件: 按照提示...

weixin_34390996的博客 236

深度探索:非线性随机森林(Nonlinear Random Forest,NL-RF)原理及应用

非线性随机森林(NL-RF)旨在通过结合集成方法与高级技术来捕捉和建模数据中的非线性关系,从而改善传统随机森林在处理复杂非线性数据结构时的表现。

qq_51320133的博客 2068

自动换挡频率计的设计精髓:如何用数字电路优雅地解决量程切换难题

本文深入解析了自动换挡频率计的设计精髓,重点探讨如何利用数字电路优雅解决量程切换难题。通过74系列通用数字集成电路构建智能化的自动量程切换系统,详细介绍了状态检测、决策逻辑和档位执行等核心模块的设计方法,并对比了不同实现方案的优劣,为电子测量领域的工程师提供了实用的硬件设计参考。

weixin_27869497的博客 409

Unix网络编程第三版中代码环境搭建

最近在啃《Unix网络编程第三版 卷1》,其中出现了很多关于unp.h的地方,应该是书中自带的文件,搜索了一下,下载了源代码来自己编译。 谷歌搜索unpv13e.tar.gz 下载该库文件   编译步骤 tar zxvf unpv13e.tar.gz ./configure cd lib make cd ../libfree make cd ../libgai make cd

u012916334的专栏 751

用Typora画流程图和序列图:Mermaid语法实战教程(含常见报错解决)

本文是一份详细的Typora与Mermaid语法实战教程,教你如何在Markdown文档中高效绘制流程图和序列图。文章涵盖从环境配置、核心语法到复杂图表构建的全过程,并重点解析了常见报错原因与解决方案,助你将可视化图表无缝融入文档工作流。

weixin_29279101的博客 302

Unix网络编程卷1 第一章读书笔记以及习题

1 下载源码并且配置环境 对于想学习网络编程的同学来说,《UNIX网络编程》这书肯定是不二选择。所谓实践是检验真理的唯一标志,特别是对于编程来讲,再多的理论经验也比不过code一次。《UNIX网络编程》这本书提供连源码下载,第三版本的源码我是在 GitHub上面下载的。 但是源码归源码,下载了如果不会使用那也是瞎扯。下面简单介绍一下在本节主要介绍UNIX网络编程卷(第三版)在Ubuntu1...

ProgramVAE的博客 965

Netapp FAS2750更换磁盘后不同步问题处理

netapp fas2750磁盘更换后不同步问题处理

jetliu05的博客 1257

逆变器技术解析:DDSRF双解耦在正负序分离中的关键作用

本文深入解析了DDSRF双解耦技术在逆变器正负序分离中的关键作用。通过建立正反旋转坐标系并利用交叉反馈解耦网络,DDSRF能快速、精准地分离电网电压中的正负序分量,从而显著提升锁相环在电网不平衡条件下的精度与系统稳定性,是现代高性能并网逆变器的核心算法之一。

m3n5b7v8c9x的博客 413
上一篇: Java网页抓取
下一篇: Linux桌面发行版与Andoid GUI系统组件对比
Rain松
博客等级 码龄15年 361粉丝 111原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值