unix网络编程起步

来源:互联网 发布:网络平台合作方案 编辑:程序博客网 时间:2024/05/17 05:04

首先去www.unpbook.com 下载源代码

编译代码

  1. 解压 tar包, tar -xvz -f
  2. cd unpv13e/lib , make代码,报错信息get_ifi_info.c:63:34: error: ‘AF_LINK’ undeclared (first use in this function)如下:
    报错截图
    原因在于有一个变量没有定义,在标准库里也找不到相关定义,于是自己grep代码在,/usr/include/net/if_dl.h找到了关键字,网上搜索是定义为18,就在该文件中增加宏定义,解决问题,但明显应该linux环境下没有用到类似link_level sockaddr.
    #define AF_LINK 18
  3. cd unpv13e/libfree,make代码,报错信息inet_ntop.c:60:9: error: argument ‘size’ doesn’t match prototype如下:
    报错截图
    这里跟/usr/include/arpa/inet.h 中的申明中类型不一样,把libfree/inet_ntop.c中 size_t改为socklen_t就好。
  4. cd intro , make daytimetcpcli
  5. ./daytimecpcli 127.0.0.1, 这时候报错连接拒绝,是因为Linux系统中默认没有安装daytime服务,可以下载yum install xinetd,编辑/etc/xinetd.d/daytime-stream,把disable 关闭,然后开启服务xinetd -d ,再次运行程序返回数据。
#This is the configuration for the tcp/stream daytime service.                                                                                               service daytime{#This is for quick on or off of the service    disable     = no
原创粉丝点击