zoukankan      html  css  js  c++  java
  • 【unp】unix网络编程卷1-->环境搭建(ubuntu14.04)

    学习unp网络编程,树上的例子均存在#include "unp.h",故需要对环境进行配置。

    1. 到资源页下载unpv13e 

    2. 解压并将unpv13e 移动到相应的文件夹下

    3. 编译

    1 >$ cd unpv13e   
    2 >~unpv13e/$ ./configure  
    3   
    4 >~unpv13e/$ cd lib  
    5 >~unpv13e/lib/$ make  
    6   
    7 >~unpv13e/lib/$ cd ../libfree  
    8 >~unpv13e/libfree/$ make  

    如若出现以下问题:

     1 gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o inet_ntop.o inet_ntop.c  
     2 inet_ntop.c: In function ‘inet_ntop’:  
     3 inet_ntop.c:60:9: error: argument ‘size’ doesn’t match prototype  
     4   size_t size;  
     5          ^  
     6 In file included from inet_ntop.c:27:0:  
     7 /usr/include/arpa/inet.h:64:20: error: prototype declaration  
     8  extern const char *inet_ntop (int __af, const void *__restrict __cp,  
     9                     ^  
    10 make: *** [inet_ntop.o] Error 1  

    则需要:

     1 >~unpv13e/libfree/$ vim inet_ntop.c  //将第60行的 size_t size 改成 socklen_t size;  
     2 >~unpv13e/libfree/$ make // 改变完后重新make  
     3 >~unpv13e/libfree/$ cd ../libgai  
     4 >~unpv13e/libgai/$ make   //以下只是warning, 乎略之  
     5 /usr/include/arpa/inet.h: In function ‘inet_ntop’:  
     6 inet_ntop.c:152:23: warning: ‘best.len’ may be used uninitialized in this function [-Wmaybe-uninitialized]  
     7    if (best.base == -1 || cur.len > best.len)  
     8                        ^  
     9 inet_ntop.c:123:28: note: ‘best.len’ was declared here  
    10   struct { int base, len; } best, cur;  
    11                             ^  
    12 gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o inet_pton.o inet_pton.c  
    13 ar rv ../libunp.a in_cksum.o inet_ntop.o inet_pton.o  
    14 a - in_cksum.o  
    15 a - inet_ntop.o  
    16 a - inet_pton.o  
    17 ranlib ../libunp.a 

    至此,编译成功生成静态库libunp.a

    4. 将生成的libunp.a复制到/usr/lib下

    1 >~unpv13e/libgai/$ cd ..  
    2 >~unpv13e/$ sudo cp libunp.a /usr/lib  


    5. 修改unpv13e/lib/unp.h并复制

    1 >~unpv13e/$ vim lib/unp.h  // 将#include "../config.h" 改成 #include "config.h"  
    2 >~unpv13e/$  sudo cp lib/unp.h /usr/include  
    3 >~unpv13e/$ sudo cp config.h /usr/include  


    6. 编译例子

    1 >~unpv13e/$  cd intro  
    2 >~unpv13e/$  gcc daytimetcpcli.c -o cli -lunp  



    编译成功则大功告成。

    无欲速,无见小利。欲速,则不达;见小利,则大事不成。
  • 相关阅读:
    OAuth客户端调用
    OAuth中client id的处理
    Task作为返回值以及Task<TResult>作为返回值
    Netscaler立身之本—NAT
    Citrix Netscaler负载均衡算法
    Netscaler重置密码的方法
    Netscaler的超高端口复用助力应对公网地址紧张
    Netscaler工作流程
    深入理解Netscaler INat
    Citrix Netscaler版本管理和选择
  • 原文地址:https://www.cnblogs.com/ch122633/p/8324031.html
Copyright © 2011-2022 走看看