UNIX网络编程 卷2 源代码使用

1. 下载源码,W. Richard Stevens的主页:http://www.kohala.com/start/

wget http://www.kohala.com/start/unpv22e/unpv22e.tar.gz -P /usr/local/src

2. 解压

tar xvf /usr/local/src/unpv22e.tar.gz -C /root/bin

3. 编译库文件

cd /root/bin/unpv22e/

./configure

编辑生成config.h文件,注释以下几行

vi config.h

56 // #define uint8_t unsigned char

57 // #define uint16_t unsigned short

58 // #define uint32_t unsigned int

添加MSG_R和MSG_W定义

vi config.h

66 // add by jcq

67 typedef unsigned long ulong_t;

68 #define MSG_R 0400

69 #define MSG_W 0200

添加_GNU_SOURCE定义

vi config.h

#define _GNU_SOURCE

修改warpunix.c中的MKtemp函数,使用mkstemp函数替换mktemp函数

cd lib

181 void

182 Mktemp(char *template)

183 {

184 if (mkstemp(template) == NULL || template[0] == 0)

185 err_quit("mktemp error");

186 }

编译生成libunpipc.a

cd lib

make

将生成的libunpipc.a复制到/usr/lib中。

[[email protected] myunp2]# vim ftok.c
[[email protected] myunp2]# gcc -o ftok ftok.c
/tmp/ccxRydhw.o: In function `main‘:
ftok.c:(.text+0x18): undefined reference to `err_quit‘
ftok.c:(.text+0x30): undefined reference to `Stat‘
ftok.c:(.text+0x48): undefined reference to `Ftok‘
collect2: 错误:ld 返回 1
[[email protected] myunp2]# gcc -o ftok ftok.c -lunpipc
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_open‘:
wrapunix.c:(.text+0x4d8): undefined reference to `mq_open‘
wrapunix.c:(.text+0x4f0): undefined reference to `mq_open‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_close‘:
wrapunix.c:(.text+0x52b): undefined reference to `mq_close‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_unlink‘:
wrapunix.c:(.text+0x55b): undefined reference to `mq_unlink‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_send‘:
wrapunix.c:(.text+0x5a3): undefined reference to `mq_send‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_receive‘:
wrapunix.c:(.text+0x5e3): undefined reference to `mq_receive‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_notify‘:
wrapunix.c:(.text+0x623): undefined reference to `mq_notify‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_getattr‘:
wrapunix.c:(.text+0x653): undefined reference to `mq_getattr‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_setattr‘:
wrapunix.c:(.text+0x68b): undefined reference to `mq_setattr‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_open‘:
wrapunix.c:(.text+0x9c8): undefined reference to `sem_open‘
wrapunix.c:(.text+0x9e0): undefined reference to `sem_open‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_close‘:
wrapunix.c:(.text+0xa1b): undefined reference to `sem_close‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_unlink‘:
wrapunix.c:(.text+0xa4b): undefined reference to `sem_unlink‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_init‘:
wrapunix.c:(.text+0xa8b): undefined reference to `sem_init‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_destroy‘:
wrapunix.c:(.text+0xabb): undefined reference to `sem_destroy‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_wait‘:
wrapunix.c:(.text+0xaeb): undefined reference to `sem_wait‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_trywait‘:
wrapunix.c:(.text+0xb1c): undefined reference to `sem_trywait‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_post‘:
wrapunix.c:(.text+0xb5b): undefined reference to `sem_post‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_getvalue‘:
wrapunix.c:(.text+0xb93): undefined reference to `sem_getvalue‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Shm_open‘:
wrapunix.c:(.text+0xccc): undefined reference to `shm_open‘
/usr/lib/libunpipc.a(wrapunix.o): In function `Shm_unlink‘:
wrapunix.c:(.text+0xd0b): undefined reference to `shm_unlink‘
collect2: 错误:ld 返回 1
[[email protected] myunp2]# gcc -lrt -o ftok ftok.c -lunpipc
[[email protected] myunp2]# man mq_open
Cannot open the message catalog "man" for locale "zh_CN.UTF-8"
(NLSPATH="/usr/share/locale/%l/LC_MESSAGES/%N")

Formatting page, please wait...

出现上面的错误,使用gcc 加选项-lrt解决。

时间: 2024-08-11 02:03:40

UNIX网络编程 卷2 源代码使用的相关文章

UNIX网络编程卷2 源码编译篇

W. Richard Stevens的主页: 源代码下载   >>  ~/Downloads/unpv22e.tar.gz; 1 tar -xzfv unpv22e.tar.gz 2 cd unpv22e 3 ./configure 4 cd lib 5 make make编译失败,因为需要对两个文件修改,unpv22e/config.h和unpv22e/wrapunix.c. 1 vi config.h 2 3 /*注释掉这三行*/ 4 // #define uint8_t unsigned

UNIX网络编程 卷1:套接字联网API

这篇是计算机类的优质预售推荐>>>><UNIX网络编程 卷1:套接字联网API> UNIX和网络专家W. Richard Stevens的传世之作,世界著名网络专家Bill Fenner和Andrew M. Rudoff执笔新版 编辑推荐 这是一部传世之作!顶级网络编程专家Bill Fenner和Andrew M. Rudoff应邀执笔,对W. Richard Stevens的经典作品进行修订.书中吸纳了近几年网络技术的发展,增添了IPv6.SCTP协议和密钥管理套接字

将UNIX网络编程卷2的库函数合并到卷1的库函数中

源起 前面讲述了unix网路编程卷1库函数的配置.但是卷2还有一个配置,而且其中的关于进程间通信的函数在卷1中也没有. 我们使用两个库函数不免有些不方便,现在将卷2中的在卷1中没有的函数都合并到卷1的库函数中. 1.创建unix网络编程卷2——进程间通信configure.h配置文件    cd 目录    ./configure    之后创建了configure.h文件. 2.合并unix网路编程卷1和卷2的configure.h文件    将上面生成的configure.h的头文件的宏定义

UNIX网络编程 卷2:进程间通信

这篇是计算机类的优质预售推荐>>>><UNIX网络编程 卷2:进程间通信(第2版)> UNIX和网络专家W. Richard Stevens的传世之作 编辑推荐 两卷本的<UNIX网络编程>是已故著名技术作家W. Richard Stevens的传世之作.卷2着重讨论怎样让应用程序与在其它机器上的应用程序进行对话. 良好的进程间通信(IPC)机制是提高UNIX程序性能的关键. 本书全面深入地解说了各种进程间通信形式,包括消息传递.同步.共享内存及远程过程调用

[转载] 读《UNIX网络编程 卷1:套接字联网API》

原文: http://cstdlib.com/tech/2014/10/09/read-unix-network-programming-1/ 文章写的很清楚, 适合初学者 最近看了<UNIX网络编程 卷1:套接字联网API>, 英文名叫Unix Network Programming啦,后来上网查了查, 一般都叫UNP逼格会高一点, 就像APUE一样. 他们的作者都是W. Richard Stevens. 另外,他也是TCP/IP Illustrated的作者. 靠,看完作者简介,简直崇拜得

《UNIX网络编程 卷1》之&quot;学习环境搭建&quot;(CentOS 7)

<UNIX网络编程 卷1>的源码可以从www.unpbook.com下载得到.解压之后的目录为unpv13e.  1. 编译 进入unpv13e目录,按如下步骤编译: 1 ./configure 2 3 cd lib 4 make // 可能遇到问题:redefinition of ‘struct in_pktinfo’ 5 6 cd ../libfree 7 make 8 9 cd ../libroute 10 make //这一步可能会出错,可忽略,只是表示你的系统不支持 4.4BSD,并

UNIX网络编程卷1 回射客户程序 TCP客户程序设计范式

本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 下面我会介绍同一个使用 TCP 协议的客户端程序的几个不同版本,分别是停等版本.select 加阻塞式 I/O 版本. 非阻塞式 I/O 版本.fork 版本.线程化版本.它们都由同一个 main 函数调用来实现同一个功能,即回射程序客户端. 它从标准输入读入一行文本,写到服务器上,读取服务器对该行的回射,并把回射行写到标准输出上. 其中,非阻塞式 I/O 版本是所有版本中执行速度最快的,

UNIX网络编程卷1 第一章 读书笔记。

基本没讲什么,一点点计算机网络发展史,一点点socket()简单介绍,最重要的是1.3节协议无关性. 协议无关性: 贯穿整本书的一个重要特性,他主要强调的是 socket是网络协议无关的编程接口. socket给出一个struct sockaddr结构,每一种协议都有自己特定的地址结构来记录协议中需要的基本信息,通过强制类型转换成struct sockaddr结构.这样可以屏蔽类型,把所有协议的API抽象成一个统一的接口,即套接字. 还有一个小技巧:包裹函数,就是把socket重新打包,以首字母

UNIX网络编程卷1 回射服务器程序 TCP服务器程序设计范式 四个版本

本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 这是一个简单的回射服务器程序.它将客户发送的数据读入缓冲区并回射其中内容 下面我会介绍同一个使用 TCP 协议的回射服务器程序的几个不同版本,分别是 fork 版本.select 版本.poll 版本.多线程版本 fork 版本:为每一个客户连接派生(fork) 一个子进程用来处理客户请求 /** * TCP/IPv4 协议相关 * **/ #include "unp.h" in