UNIX网络编程之旅-配置unp.h头文件环境

最近在学习Unix网络编程(UNP),书中steven在处理网络编程时只用了一个#include “unp.h”  相当有个性并且也很便捷

于是我把第三版的源代码编译实现了这个过程,算是一种个性化的开发环境的搭建吧,顺便把过程记录下来,以便自己以后查阅。

 

首先去网上找到源代码包unpv.13e.tar.gz 一找一大堆

解压缩到你的某个目录,unpv13e里面大致有这些目录

├── aclocal.m4 
├── advio 
├── bcast 
├── config.guess 
├── config.h 
├── config.h.in 
├── config.log 
├── config.status 
├── config.sub 
├── configure 
├── configure.in 
├── debug 
├── DISCLAIMER 
├── icmpd 
├── inetd 
├── install-sh 
├── intro 
├── ioctl 
├── ipopts 
├── key 
├── lib 
├── libfree 
├── libgai 
├── libroute 
├── libunp.a(就是为了生成这个文件) 
├── Make.defines 
├── Make.defines.in 
├── Makefile 
├── Makefile.in 
├── mcast 
├── mysdr 
├── names 
├── nonblock 
├── oob 
├── ping 
├── README 
├── route 
├── rtt 
├── sctp 
├── select 
├── server 
├── sigio 
├── sock 
├── sockopt 
├── sparc64-unknown-freebsd5.1 
├── ssntp 
├── streams 
├── tcpcliserv 
├── test 
├── threads 
├── traceroute 
├── udpcksum 
├── udpcliserv 
├── unixdomain 
├── unpv13e 
└── VERSION

 

首先查看README 一般情况下我们只需要进行第一步和第二步 其他的是一些与其他架构有关的情况不管

执行下面两部生成libunp.a

1.   ./configure

2.     cd lib 

make (在lib上层目录中生成libunp.a)

 

生成libunp.a。复制这个静态库到/usr/lib/和/usr/lib64/中,因为后来编译程序的话需要用到这个静态库。还得在环境变量中将这两个路径加上。

 

接下来找到unp.h和config.h

1.我在我的主目录下新建了一个unp目录,专门处理unp的例子。然后把lib下的unp.h和上层目录的config.h放入unp目录,然后在unp目录下新建各个要实践的程序的章节目录 比如一开头的time server例子我就新建了个time server目录,在里面写书中的例子程序

:)

3.unp.h中将#include "../config.h"改成#include "config.h"

2.在unp.h中需要添加一行: 
#define MAX_LINE 2048

 

头文件为

#include "../unp.h"即可

 

如果书写的程序出现err_sys()等err函数找不到的情况 这是因为steven大神对错误处理进行了封装 可以搜索apueerror.h这个文件(有兴趣的同学可以研究下封装代码 篇幅小不难的) 然后放入unp目录 接着在程序中 #include "apueerror.h"即可

 

至此环境搭建结束,大家可以开始UNP编程之旅了,祝大家早日学成!~~~  哈哈

 

参考文章(包含apue编程环境搭建):

http://my.chinaunix.net/space.php?uid=11765716&do=blog&id=193676



/* 另一个版本解决方案*/

我这几天也在看他的书,也遇到了和你一样的问题
首先解释下unpv12e
其中v1是指<UNIX网络编程>的第一卷(还有第二卷关于进程的)
2e表示2nd edition第二版,所以你找到那两个包都是第二版的,一个是第一卷,一个是第二卷
建议你找个unpv13e的,因为比较新,所以兼容问题比较少吧

找到的代码包unpv13e,然后按照下列步骤操作就可以了
0. To extract the source directories from the unpv12e.tar.gz tar file,
  execute:

cd <some-directory-of-your-choosing>
gunzip -c unpv12e.tar.gz | tar -xvf -

  This creates a directory named unpv12e/ containing about 40 other
  directories. The names of these 40 other directories are what appears
  in the horizontal rules that start and end each source code listing
  in the book. For example, the file unpv12e/intro/daytimetcpcli.c
  corresponds to the source code in Figure 1.5 (Page 6) of the book.

1. There is a "unp.h" header that appears in every one of the 40 directories.
  If you need to make any changes to this "unp.h" header, notice that it
  is a hard link in each directory, so you only need to change it once.
  Hard links are also used with the other "unp*.h" headers.

2. I used the GNU autoconf package to generate a shell script named
  "configure" that you must execute. This script will try and figure
  out lots of characteristics of your system.

  This script builds two important files "Make.defines" and "config.h".
  Each "Makefile" in each of the 40 directories includes "Make.defines",
  and the first #include done by "unp.h" is of "config.h".

  These two files *must* be set correctly for your system, or you will
  not be able to build the source code.

3. Go into the "lib/" directory and type "make". This builds the library
  "libunp.a" that is required by almost all of the programs. There may
  be compiler warnings (see NOTES below).

  Go into the "libfree/" directory and type "make". This adds to the
  "libunp.a" library. Similarly go into the "libgai", "libroute" and
  "libxti" directories and "make". The "libroute" directory should only
  be used if your system supports 4.4BSD-style routing sockets. The
  "libxti" directory should only be used if your system supports XTI
  (not TLI).

4. Once the library is made, you can then go into any of the source code
  directories and make whatever program you are interested in. A good
  starting poing is the "intro" directory and "make daytimetcpcli".
这是一个README文档中摘抄的
我按照上面步骤操作后也有几个错误,正在解决中
就知道这些了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值