免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4618 | 回复: 4
打印 上一主题 下一主题

[C] linux c TCP/IP编程编译问题求助。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-03-25 22:00 |只看该作者 |倒序浏览
本帖最后由 julynada 于 2010-03-25 22:12 编辑

TCP_IP_IN_C.rar (44.9 KB, 下载次数: 39) 最近在看一本书,里面的代码GetAddrInfo.c编译不过。
代码下载地址:
http://cs.ecs.baylor.edu/~donaho ... kets2/textcode.html

Cygwin下报错信息
  1. cc -g -Wall -std=c99    GetAddrInfo.c   -o GetAddrInfo
  2. GetAddrInfo.c: In function `main':
  3. GetAddrInfo.c:16: error: storage size of 'addrCriteria' isn't known
  4. GetAddrInfo.c:20: error: `IPPROTO_TCP' undeclared (first use in this function)
  5. GetAddrInfo.c:20: error: (Each undeclared identifier is reported only once
  6. GetAddrInfo.c:20: error: for each function it appears in.)
  7. GetAddrInfo.c:25: warning: implicit declaration of function `getaddrinfo'
  8. GetAddrInfo.c:27: warning: implicit declaration of function `gai_strerror'
  9. GetAddrInfo.c:27: warning: passing arg 2 of `DieWithUserMessage' makes pointer from integer without a cast
  10. GetAddrInfo.c:30: error: dereferencing pointer to incomplete type
  11. GetAddrInfo.c:31: error: dereferencing pointer to incomplete type
  12. GetAddrInfo.c:35: warning: implicit declaration of function `freeaddrinfo'
  13. GetAddrInfo.c:16: warning: unused variable `addrCriteria'
  14. make: *** [GetAddrInfo] Error 1
复制代码
HELP!!!{:3_201:}

RHEL5下报错信息!
  1. cc -g -Wall -std=c99    GetAddrInfo.c   -o GetAddrInfo
  2. GetAddrInfo.c: In function 'main':
  3. GetAddrInfo.c:16: error: storage size of 'addrCriteria' isn't known
  4. GetAddrInfo.c:25: warning: implicit declaration of function 'getaddrinfo'
  5. GetAddrInfo.c:27: warning: implicit declaration of function 'gai_strerror'
  6. GetAddrInfo.c:27: warning: passing argument 2 of 'DieWithUserMessage' makes poit
  7. GetAddrInfo.c:30: error: dereferencing pointer to incomplete type
  8. GetAddrInfo.c:31: error: dereferencing pointer to incomplete type
  9. GetAddrInfo.c:35: warning: implicit declaration of function 'freeaddrinfo'
  10. GetAddrInfo.c:16: warning: unused variable 'addrCriteria'
  11. make: *** [GetAddrInfo] Error 1
复制代码

论坛徽章:
0
2 [报告]
发表于 2010-03-26 00:12 |只看该作者
你不include头文件的么?

论坛徽章:
0
3 [报告]
发表于 2010-03-29 17:29 |只看该作者
你不include头文件的么?
greensnow 发表于 2010-03-26 00:12



    {:3_189:}

论坛徽章:
0
4 [报告]
发表于 2010-03-29 17:36 |只看该作者
回复 2# greensnow

有include头文件啊!是书附带的代码,我没改过啊!谁能在cygwin或者RHEL下编译通过麻烦把gcc的命令行发一下给我学习。{:3_199:}
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <netdb.h>
  5. #include "Practical.h"

  6. int main(int argc, char *argv[]) {

  7.   if (argc != 3) // Test for correct number of arguments
  8.     DieWithUserMessage("Parameter(s)", "<Address/Name> <Port/Service>");

  9.   char *addrString = argv[1];   // Server address/name
  10.   char *portString = argv[2];   // Server port/service

  11.   // Tell the system what kind(s) of address info we want
  12.   struct addrinfo addrCriteria;                   // Criteria for address match
  13.   memset(&addrCriteria, 0, sizeof(addrCriteria)); // Zero out structure
  14.   addrCriteria.ai_family = AF_UNSPEC;             // Any address family
  15.   addrCriteria.ai_socktype = SOCK_STREAM;         // Only stream sockets
  16.   addrCriteria.ai_protocol = IPPROTO_TCP;         // Only TCP protocol

  17.   // Get address(es) associated with the specified name/service
  18.   struct addrinfo *addrList; // Holder for list of addresses returned
  19.   // Modify servAddr contents to reference linked list of addresses
  20.   int rtnVal = getaddrinfo(addrString, portString, &addrCriteria, &addrList);
  21.   if (rtnVal != 0)
  22.     DieWithUserMessage("getaddrinfo() failed", gai_strerror(rtnVal));

  23.   // Display returned addresses
  24.   for (struct addrinfo *addr = addrList; addr != NULL; addr = addr->ai_next) {
  25.     PrintSocketAddress(addr->ai_addr, stdout);
  26.     fputc('\n', stdout);
  27.   }

  28.   freeaddrinfo(addrList); // Free addrinfo allocated in getaddrinfo()

  29.   exit(0);
  30. }
复制代码

论坛徽章:
0
5 [报告]
发表于 2010-03-29 19:02 |只看该作者
可能IPv6的一些宏没有,去搜下getaddinfo,把它换掉试试
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP