|
source :- #include <sys/socket.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdio.h>
- int
- main(void)
- {
- const char *host_name="a_host";
- struct hostent *pr;
- char **ppr;
- char str[INET6_ADDRSTRLEN];
- if((pr=gethostbyname(host_name))==NULL) {
- perror("gethostbyname error");
- exit(1);
- }
- printf("offical hostname is %s\n",pr->h_name) ; /* print the officl hostname */
- for(ppr=pr->h_aliases; *ppr !=NULL; ppr++) /* print the alias hostname */
- printf(" host aliases is %s\n",*ppr);
- printf(" the addrles length is %d\n",pr->h_length);
- swith(pr->h_addrtype) {
- case AF_INET :
- #ifdef AF_INET6
- case AF_INET6 :
- #endif
- ppr=pr->h_addr_list ;
- for( ; *ppr != NULL ; ppr++)
- printf( "other adddress list is %s\n",
- inet_ntop(pr->h_addrtype,*ppr,str,sizeof(str)) );
- break;
- default :
- printf("unknown address type \n");
- break;
- }
- }
复制代码
this is error message - In file included from gethostbyname.c:1:
- /usr/include/sys/socket.h:20: syntax error before `sa_family_t'
- /usr/include/sys/socket.h:20: warning: data definition has no type or storage class
- /usr/include/sys/socket.h:131: syntax error before `u_char'
- /usr/include/sys/socket.h:142: syntax error before `u_short'
- /usr/include/sys/socket.h:156: syntax error before `u_char'
- /usr/include/sys/socket.h:158: `int64_t' undeclared here (not in a function)
- /usr/include/sys/socket.h:158: `u_char' undeclared here (not in a function)
- /usr/include/sys/socket.h:158: size of array `__ss_pad1' is too large
- /usr/include/sys/socket.h:159: syntax error before `int64_t'
- /usr/include/sys/socket.h:160: `u_char' undeclared here (not in a function)
- /usr/include/sys/socket.h:160: `int64_t' undeclared here (not in a function)
- /usr/include/sys/socket.h:160: `u_char' undeclared here (not in a function)
- /usr/include/sys/socket.h:160: `int64_t' undeclared here (not in a function)
- /usr/include/sys/socket.h:327: syntax error before `pid_t'
- /usr/include/sys/socket.h:332: syntax error before `gid_t'
- /usr/include/sys/socket.h:367: syntax error before `u_short'
- /usr/include/sys/socket.h:375: syntax error before `caddr_t'
- /usr/include/sys/socket.h:379: syntax error before `caddr_t'
- In file included from gethostbyname.c:1:
- /usr/include/sys/socket.h:412: syntax error before `recv'
- /usr/include/sys/socket.h:412: syntax error before `size_t'
- /usr/include/sys/socket.h:412: warning: data definition has no type or storage class
- /usr/include/sys/socket.h:413: syntax error before `recvfrom'
- /usr/include/sys/socket.h:413: syntax error before `size_t'
- /usr/include/sys/socket.h:413: warning: data definition has no type or storage class
- /usr/include/sys/socket.h:414: syntax error before `recvmsg'
- /usr/include/sys/socket.h:414: warning: data definition has no type or storage class
- /usr/include/sys/socket.h:415: syntax error before `send'
- /usr/include/sys/socket.h:415: syntax error before `size_t'
- /usr/include/sys/socket.h:415: warning: data definition has no type or storage class
- /usr/include/sys/socket.h:416: syntax error before `sendto'
- /usr/include/sys/socket.h:417: syntax error before `size_t'
- /usr/include/sys/socket.h:417: warning: data definition has no type or storage class
- /usr/include/sys/socket.h:418: syntax error before `sendmsg'
- /usr/include/sys/socket.h:418: warning: data definition has no type or storage class
- /usr/include/sys/socket.h:419: syntax error before `off_t'
- gethostbyname.c: In function `main':
- gethostbyname.c:13: warning: assignment makes pointer from integer without a cast
- gethostbyname.c:17: dereferencing pointer to incomplete type
- gethostbyname.c:18: dereferencing pointer to incomplete type
- gethostbyname.c:20: dereferencing pointer to incomplete type
- gethostbyname.c:21: dereferencing pointer to incomplete type
- gethostbyname.c:21: syntax error before `{'
- gethostbyname.c:29: dereferencing pointer to incomplete type
- gethostbyname.c:30: break statement not within loop or switch
- gethostbyname.c:31: default label not within a switch statement
- gethostbyname.c:33: break statement not within loop or switch
- gethostbyname.c: At top level:
- gethostbyname.c:35: syntax error before `}'
复制代码 |
|