| OLD | NEW |
| 1 #define _GNU_SOURCE | 1 #define _GNU_SOURCE |
| 2 | 2 |
| 3 #include <sys/socket.h> | 3 #include <sys/socket.h> |
| 4 #include <netdb.h> | 4 #include <netdb.h> |
| 5 #include <string.h> | 5 #include <string.h> |
| 6 #include <netinet/in.h> | 6 #include <netinet/in.h> |
| 7 | 7 |
| 8 struct hostent* gethostbyname(const char* name) { | 8 struct hostent* gethostbyname(const char* name) { |
| 9 return gethostbyname2(name, AF_INET); | 9 return gethostbyname2(name, AF_INET); |
| 10 } | 10 } |
| 11 | |
| 12 #if 0 | |
| 13 struct hostent *gethostbyname(const char *name) | |
| 14 { | |
| 15 static struct hostent h; | |
| 16 static char *h_aliases[3]; | |
| 17 static char h_canon[256]; | |
| 18 static char *h_addr_list[10]; | |
| 19 static char h_addr_data[10][4]; | |
| 20 static const struct addrinfo hint = { | |
| 21 .ai_family = AF_INET, .ai_flags = AI_CANONNAME | |
| 22 }; | |
| 23 struct addrinfo *ai, *p; | |
| 24 int i; | |
| 25 | |
| 26 switch (getaddrinfo(name, 0, &hint, &ai)) { | |
| 27 case EAI_NONAME: | |
| 28 h_errno = HOST_NOT_FOUND; | |
| 29 break; | |
| 30 case EAI_AGAIN: | |
| 31 h_errno = TRY_AGAIN; | |
| 32 break; | |
| 33 case EAI_FAIL: | |
| 34 h_errno = NO_RECOVERY; | |
| 35 break; | |
| 36 default: | |
| 37 case EAI_MEMORY: | |
| 38 case EAI_SYSTEM: | |
| 39 h_errno = NO_DATA; | |
| 40 break; | |
| 41 case 0: | |
| 42 break; | |
| 43 } | |
| 44 | |
| 45 strcpy(h_canon, ai->ai_canonname); | |
| 46 h.h_name = h_canon; | |
| 47 h.h_aliases = h_aliases; | |
| 48 h.h_aliases[0] = h_canon; | |
| 49 h.h_aliases[1] = strcmp(h_canon, name) ? (char *)name : 0; | |
| 50 h.h_length = 4; | |
| 51 h.h_addr_list = h_addr_list; | |
| 52 for (i=0, p=ai; i<sizeof h_addr_data/4 && p; i++, p=p->ai_next) { | |
| 53 h.h_addr_list[i] = h_addr_data[i]; | |
| 54 memcpy(h.h_addr_list[i], | |
| 55 &((struct sockaddr_in *)p->ai_addr)->sin_addr, 4); | |
| 56 } | |
| 57 h.h_addr_list[i] = 0; | |
| 58 h.h_addrtype = AF_INET; | |
| 59 freeaddrinfo(ai); | |
| 60 return &h; | |
| 61 } | |
| 62 #endif | |
| OLD | NEW |