LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 516|回复: 1

what wrong with "gethostbyname()" funcation ?

[复制链接]
发表于 2004-4-29 18:07:45 | 显示全部楼层 |阅读模式
source :
  1. #include <sys/socket.h>
  2. #include <sys/types.h>
  3. #include <netinet/in.h>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. int
  7. main(void)
  8. {
  9.    const char        *host_name="a_host";
  10.    struct hostent    *pr;
  11.    char              **ppr;
  12.    char              str[INET6_ADDRSTRLEN];
  13.    if((pr=gethostbyname(host_name))==NULL) {
  14.           perror("gethostbyname error");
  15.           exit(1);
  16.    }
  17.    printf("offical hostname is %s\n",pr->h_name) ; /* print the officl hostname */
  18.    for(ppr=pr->h_aliases; *ppr !=NULL; ppr++)      /* print the alias hostname */
  19.           printf(" host aliases is    %s\n",*ppr);
  20.    printf(" the addrles length is %d\n",pr->h_length);
  21.    swith(pr->h_addrtype) {
  22.           case AF_INET :
  23. #ifdef    AF_INET6
  24.           case AF_INET6 :
  25. #endif
  26.              ppr=pr->h_addr_list ;
  27.              for( ; *ppr != NULL ; ppr++)
  28.                     printf( "other adddress list is %s\n",
  29.                            inet_ntop(pr->h_addrtype,*ppr,str,sizeof(str)) );
  30.              break;
  31.           default :
  32.                     printf("unknown address type \n");
  33.                     break;
  34.    }
  35. }
复制代码

this is error message  
  1. In file included from gethostbyname.c:1:
  2. /usr/include/sys/socket.h:20: syntax error before `sa_family_t'
  3. /usr/include/sys/socket.h:20: warning: data definition has no type or storage class
  4. /usr/include/sys/socket.h:131: syntax error before `u_char'
  5. /usr/include/sys/socket.h:142: syntax error before `u_short'
  6. /usr/include/sys/socket.h:156: syntax error before `u_char'
  7. /usr/include/sys/socket.h:158: `int64_t' undeclared here (not in a function)
  8. /usr/include/sys/socket.h:158: `u_char' undeclared here (not in a function)
  9. /usr/include/sys/socket.h:158: size of array `__ss_pad1' is too large
  10. /usr/include/sys/socket.h:159: syntax error before `int64_t'
  11. /usr/include/sys/socket.h:160: `u_char' undeclared here (not in a function)
  12. /usr/include/sys/socket.h:160: `int64_t' undeclared here (not in a function)
  13. /usr/include/sys/socket.h:160: `u_char' undeclared here (not in a function)
  14. /usr/include/sys/socket.h:160: `int64_t' undeclared here (not in a function)
  15. /usr/include/sys/socket.h:327: syntax error before `pid_t'
  16. /usr/include/sys/socket.h:332: syntax error before `gid_t'
  17. /usr/include/sys/socket.h:367: syntax error before `u_short'
  18. /usr/include/sys/socket.h:375: syntax error before `caddr_t'
  19. /usr/include/sys/socket.h:379: syntax error before `caddr_t'
  20. In file included from gethostbyname.c:1:
  21. /usr/include/sys/socket.h:412: syntax error before `recv'
  22. /usr/include/sys/socket.h:412: syntax error before `size_t'
  23. /usr/include/sys/socket.h:412: warning: data definition has no type or storage class
  24. /usr/include/sys/socket.h:413: syntax error before `recvfrom'
  25. /usr/include/sys/socket.h:413: syntax error before `size_t'
  26. /usr/include/sys/socket.h:413: warning: data definition has no type or storage class
  27. /usr/include/sys/socket.h:414: syntax error before `recvmsg'
  28. /usr/include/sys/socket.h:414: warning: data definition has no type or storage class
  29. /usr/include/sys/socket.h:415: syntax error before `send'
  30. /usr/include/sys/socket.h:415: syntax error before `size_t'
  31. /usr/include/sys/socket.h:415: warning: data definition has no type or storage class
  32. /usr/include/sys/socket.h:416: syntax error before `sendto'
  33. /usr/include/sys/socket.h:417: syntax error before `size_t'
  34. /usr/include/sys/socket.h:417: warning: data definition has no type or storage class
  35. /usr/include/sys/socket.h:418: syntax error before `sendmsg'
  36. /usr/include/sys/socket.h:418: warning: data definition has no type or storage class
  37. /usr/include/sys/socket.h:419: syntax error before `off_t'
  38. gethostbyname.c: In function `main':
  39. gethostbyname.c:13: warning: assignment makes pointer from integer without a cast
  40. gethostbyname.c:17: dereferencing pointer to incomplete type
  41. gethostbyname.c:18: dereferencing pointer to incomplete type
  42. gethostbyname.c:20: dereferencing pointer to incomplete type
  43. gethostbyname.c:21: dereferencing pointer to incomplete type
  44. gethostbyname.c:21: syntax error before `{'
  45. gethostbyname.c:29: dereferencing pointer to incomplete type
  46. gethostbyname.c:30: break statement not within loop or switch
  47. gethostbyname.c:31: default label not within a switch statement
  48. gethostbyname.c:33: break statement not within loop or switch
  49. gethostbyname.c: At top level:
  50. gethostbyname.c:35: syntax error before `}'
复制代码
 楼主| 发表于 2004-4-29 18:47:31 | 显示全部楼层
argv type is ?? how to set the argv 1 ?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表