Changeset 14597
- Timestamp:
- 03/12/12 01:41:31 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
titan/titan/sock.h
r14573 r14597 455 455 char *get_ip(char *host) 456 456 { 457 struct hostent *hent; 458 int iplen = 16; 459 char *ip = NULL; 457 struct hostent hent; 458 struct hostent *result = NULL; 459 int ret = 0, err = 0, iplen = 16; 460 char *ip = NULL, *buf = NULL; 460 461 461 462 if(host == NULL) return NULL; … … 469 470 memset(ip, 0, iplen); 470 471 471 if((hent = gethostbyname(host)) == NULL) 472 { 472 buf = malloc(MINMALLOC); 473 if(buf == NULL) 474 { 475 err("no mem"); 473 476 free(ip); 477 return NULL; 478 } 479 memset(buf, 0, MINMALLOC); 480 481 ret = gethostbyname_r(host, &hent, buf, MINMALLOC, &result, &err); 482 //if((hent = gethostbyname(host)) == NULL) 483 if(ret != 0 || result == NULL) 484 { 485 free(ip); 486 free(buf); 474 487 perr("can't get ip"); 475 488 return NULL; … … 477 490 478 491 //snprintf(ip, iplen, "%s", inet_ntoa(*((struct in_addr*)hent->h_addr))); 479 if(inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, iplen) == NULL) 492 //snprintf(ip, iplen, "%s", inet_ntoa(*((struct in_addr*)result->h_addr))); 493 494 //if(inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, iplen) == NULL) 495 if(inet_ntop(AF_INET, (void *)result->h_addr_list[0], ip, iplen) == NULL) 480 496 { 481 497 free(ip); 498 free(buf); 482 499 perr("can't resolve host"); 483 500 return NULL; 484 501 } 485 502 503 free(buf); 486 504 return ip; 487 505 }
Note: See TracChangeset
for help on using the changeset viewer.