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