|
- #include <unistd.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- #include <stdio.h>
- #include <sys/socket.h>
- int main(void)
- {
- struct hostent *hptr;
- char **phptr;
- if((hptr = gethostbyaddr("218.30.12.178",4,AF_INET))<0) {
- perror("gethostbyaddr error");
- exit(1);
- }
- printf("hostname:%s\n", hptr->h_name);
- for(phptr=hptr->h_aliases; *phptr != NULL ; phptr++)
- printf("hostalias:%s\n", *phptr);
- printf("address type:%d\n", hptr->h_addrtype);
- printf("address length:%d\n", hptr->h_length);
- for(phptr=hptr->h_addr_list;*phptr != NULL ; phptr++)
- printf("address:%s\n", inet_ntoa(*(struct in_addr *)*phptr));
- exit(0);
- }
- # ./a.out
- Segmentation fault (core dumped)
复制代码
help
:help :help |
|