现在的位置: 首页 > 综合 > 正文

Ubuntu中网络编程的环境配置

2018年02月02日 ⁄ 综合 ⁄ 共 2433字 ⁄ 字号 评论关闭

《UNP》中源代码的编译和使用 (2010-10-16 21:13)转载  
分类: 网络相关    
最近看了下《UNIX网络编程》,就想把里面的源代码搞过来运行下。以前也搞过,不过老是忘记使用代码的步骤了,所以就记录下,防止每次还要弄半天。

  

从网上下载压缩包解压到自己设定的目录下面,我的是/home/**/myprogram/UNP/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这个助手  
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 ../libfree # continue building the basic library  
    make

  

    cd ../libroute # only if your system supports 4.4BSD style routing sockets  
    make # only if your system supports 4.4BSD style routing sockets

  

    cd ../libxti # only if your system supports XTI  
    make # only if your system supports XTI

  

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

  

If all that works, you  
其实需要执行的就是前三步,其实就是为了生成libunp.a。复制这个静态库到/usr/lib/和/usr/lib64/中,因为后来编译程序的话需要用到这个静态库。还得在环境变量中将这两个路径加上。

  

接下来的是头文件unp.h的问题,这个文件在这个解压缩目录的lib文件夹中。

  

因为里面所有的文件都包含了#include“unp.h”这一句话,为了方便可以有两种方法:  
一:    
1.将lib下面的unp.h复制到/usr/include文件夹下面,并保证环境变量中有/usr/include;    
2. 因为unp.h中有#include "../config.h",所以得把解压缩目录下面的config.h复制到/usr/include中,并将unp.h中的#include "../config.h"改成 #include "config.h"。    
3在unp.h中添加一行:    
#define MAX_LINE 2048

  

二:  
1.将Lib文件夹下面的unp.h移到unpv13e中,    
2.参照上面的第二条;    
3.参照上面的第三条;    
4.以后在子文件夹里面编译程序,把#include"unp.h"改为#include"../unp.h"

  

做完上面,我们就可以编译单个程序了,比如intro/byteorder.c。

  

root@**-desktop:/home/**/myprogram/UNP/unpv13e/intro# gcc -W -o byteorder byteorder.c -lunp  
root@**-desktop:/home/**/myprogram/UNP/unpv13e/intro# ./byteorder    
i686-pc-linux-gnu: little-endian

  

呵呵,就这样!

抱歉!评论已关闭.