配置:
$ 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. 【unix网络编程第三版】阅读笔记(三):基本套接字编程

    unp第三章主要介绍了基本套接字编程函数.主要有:socket(),bind(),connect(),accept(),listen()等. 本博文也直接进入正题,对这几个函数进行剖析和讲解. 1. ...

  2. 【unix网络编程第三版】阅读笔记(五):I/O复用:select和poll函数

    本博文主要针对UNP一书中的第六章内容来聊聊I/O复用技术以及其在网络编程中的实现 1. I/O复用技术 I/O多路复用是指内核一旦发现进程指定的一个或者多个I/O条件准备就绪,它就通知该进程.I/O ...

  3. 【UNIX网络编程第三版】阅读笔记(一):代码环境搭建

    粗略的阅读过<TCP/IP详解>和<计算机网络(第五版)>后,开始啃这本<UNIX网络编程卷一:套接字联网API>,目前linux下的编程不算太了解,在阅读的过程中 ...

  4. 【unix网络编程第三版】ubuntu端口占用问题

    <unix网络编程>一书中的代码并不是能直接运行,有时候需要结合各方面的知识来解决,大家在这本书的时候,一定要把代码都跑通,不难你会错过很多学习的机会! 1.问题描述 本人在阅读<U ...

  5. 【unix网络编程第三版】阅读笔记(二):套接字编程简介

    unp第二章主要将了TCP和UDP的简介,这些在<TCP/IP详解>和<计算机网络>等书中有很多细致的讲解,可以参考本人的这篇博客[计算机网络 第五版]阅读笔记之五:运输层,这 ...

  6. unix网络编程第三版源代码ubuntu下配置的问题解决

    第一步:首先下载本书配套的源码unpv13e.tar.gz 第二步:解压后进入根文件夹有一个README 4 Execute the following from the src/ directory ...

  7. 【unix网络编程第三版】阅读笔记(四):TCP客户/服务器实例

    本篇博客主要记录一个完整的TCP客户/服务器实例的编写,以及从这个实例中引发的对僵死进程的处理等问题. 1. TCP客户/服务器功能需求 本实例完成以下功能: (1) 客户从标准输入读入一行文本,并写 ...

  8. UNIX 网络编程第三版

    第五章p102: ps -t  pts/6 -o pid,ppid,tty,stat,args,wchan 在我的系统上运行时出现:TTY not found linux发行版为mint17.1 改用 ...

  9. vcmi(魔法门英雄无敌3 - 开源复刻版) 源码编译

    vcmi源码编译 windows+cmake+mingw ##1 准备 HoMM3 gog.com CMake 官网 vcmi 源码 下载 QT5 with mingw 官网 Boost 源码1.55 ...

随机推荐

  1. Openstack(十五)快速添加新计算节点

    当后期添加新物理服务器作为计算节点,如果按照上面的过程安装配置的话会非常的慢,但是可以通过复制配置文件的方式快速添加. 15.1计算节点服务安装 #提前将yum仓库.防火墙.selinux.主机名.时 ...

  2. 【译】3 ways to define a JavaScript class

    本文真没啥难点,我就是为了检验我英语水平退化了没哈哈虽然我英语本来就渣翻译起来也像大白话.将原文看了一遍也码完翻译了一遍差不多一个小时,其中批注部分是自己的理解如有疏漏或误解还请指出感激不尽呐,比如J ...

  3. (2)R中的数据类型和数据结构

    R中的数据结构主要面向<线性代数>中的一些概念,如向量.矩阵等.值得注意的是,R中其实没有简单数据(数值型.逻辑型.字符型等),对于简单类型会自动看做长度为1的向量.比如: > b= ...

  4. .NET 海量数据处理,并处理事务问题

    1.下面是一个C#的控制台以代码来说明处理 using System.Data.SqlClient; class Program { static void Main() { string conne ...

  5. JDBC 连接Oracle 数据库,JDBC 连接Mysql 数据库

    首先是JDBC 连接Oracle  数据库 package com.util; import com.pojo.UserInfo; import java.sql.*; public class DB ...

  6. nginx重启 failed (98: Address already in use)

    启动nginx服务,无法正常启动,一查log日志,发现如题错误信息. 问题描述:地址已被使用.可能nginx服务卡死了,导致端口占用,出现此错误. 查看端口 netstat -ntpl 杀掉进程   ...

  7. c++第二十一天

    p115~p118: 1.区分int *p[4];和int (*p)[4];.前者是整型指针的数组,后者是指向含有4个整数的数组. 2.规避上述问题的方法就是:使用 auto和 decltype. 3 ...

  8. 20145329 《网络对抗技术》PC平台逆向破解

    shellcode注入 实践是在非常简单的一个预设条件下完成的: (1)关闭堆栈保护 (2)关闭堆栈执行保护 (3)关闭地址随机化 (4)在x32环境下 (5)在Linux实践环境 shellcode ...

  9. 如何在命令提示符下编译运行含有Package的java文件

    这篇是大二自学Java的时候记下的笔记,中午回顾印象笔记的时候意外看到了这篇.看到多年前写下的文字,我想起那时候我对Java的懵懵懂懂,每天晚上在图书馆照着书写书上的示例代码,为一个中文分号绞尽脑汁, ...

  10. pycharm 模板添加作者时间信息

    在pycharm使用过程中,对于每次新建文件的shebang行和关于代码编写者的一些个人信息快捷填写,使用模板的方式比较方便. 方法如下: 1.打开pycharm,选择File-Settings 2. ...