/[jscoverage]/trunk/http-host.c
ViewVC logotype

Diff of /trunk/http-host.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 118 by siliconforks, Sat May 31 22:32:16 2008 UTC revision 129 by siliconforks, Mon Jun 2 23:15:29 2008 UTC
# Line 22  Line 22 
22  #include "http-server.h"  #include "http-server.h"
23    
24  #include <errno.h>  #include <errno.h>
 #include <netdb.h>  
25    
26  #include "util.h"  #include "util.h"
27    
28  int xgethostbyname(const char * host, struct in_addr * a) {  int xgethostbyname(const char * host, struct in_addr * a) {
29  #ifdef __CYGWIN__  #if defined(__CYGWIN__) || defined(__MINGW32__)
30    /* cygwin's gethostbyname is thread-safe */    /* gethostbyname is thread-safe */
31    struct hostent * p = gethostbyname(host);    struct hostent * p = gethostbyname(host);
32    if (p == NULL || p->h_addrtype != AF_INET) {    if (p == NULL || p->h_addrtype != AF_INET) {
33      return -1;      return -1;
34    }    }
35    *a = *((struct in_addr *) p->h_addr);    *a = *((struct in_addr *) p->h_addr);
36    return 0;    return 0;
37  #else  #elif HAVE_GETADDRINFO
38      struct addrinfo hints;
39      hints.ai_flags = 0;
40      hints.ai_family = PF_INET;
41      hints.ai_socktype = 0;
42      hints.ai_protocol = 0;
43      hints.ai_addrlen = 0;
44      hints.ai_addr = NULL;
45      hints.ai_canonname = NULL;
46      hints.ai_next = NULL;
47      struct addrinfo * p;
48      int result = getaddrinfo(host, NULL, &hints, &p);
49      if (result != 0 || p == NULL) {
50        return -1;
51      }
52      if (p->ai_family != PF_INET) {
53        freeaddrinfo(p);
54        return -1;
55      }
56      struct sockaddr_in * address_and_port = (struct sockaddr_in *) p->ai_addr;
57      *a = address_and_port->sin_addr;
58      freeaddrinfo(p);
59      return 0;
60    #elif HAVE_GETHOSTBYNAME_R
61    struct hostent h;    struct hostent h;
62    struct hostent * p;    struct hostent * p;
63    char * buffer;    char * buffer;
# Line 56  Line 78 
78    *a = *((struct in_addr *) p->h_addr);    *a = *((struct in_addr *) p->h_addr);
79    free(buffer);    free(buffer);
80    return 0;    return 0;
81    #else
82    #error "No thread-safe host lookup available"
83  #endif  #endif
84  }  }
85    
86    #ifndef HAVE_INET_ATON
87    int inet_aton(const char * name, struct in_addr * a) {
88      unsigned long result = inet_addr(name);
89      if (result == INADDR_NONE) {
90        return 0;
91      }
92      else {
93        a->s_addr = result;
94        return 1;
95      }
96    }
97    #endif

Legend:
Removed from v.118  
changed lines
  Added in v.129

  ViewVC Help
Powered by ViewVC 1.1.24