diff options
author | Andy Green <andy@warmcat.com> | 2012-05-03 12:32:38 +0800 |
---|---|---|
committer | Andy Green <andy.green@linaro.org> | 2012-05-03 12:32:38 +0800 |
commit | a69f051870b70bde33ef86b26fbff2a085e16fc1 (patch) | |
tree | a98c2233c834f7d63691ddc5e9fb59cf90d503b2 /lib/libwebsockets.c | |
parent | 8360a47011f6a3eb89c6ef9b593eb4bca935336b (diff) |
start migration to getnameinfo
Signed-off-by: Andy Green <andy.green@linaro.org>
Diffstat (limited to 'lib/libwebsockets.c')
-rw-r--r-- | lib/libwebsockets.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index f430d48..5a28f30 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -26,6 +26,8 @@ #else #include <ifaddrs.h> #include <sys/un.h> +#include <sys/socket.h> +#include <netdb.h> #endif #ifdef LWS_OPENSSL_SUPPORT @@ -2513,8 +2515,9 @@ libwebsocket_create_context(int port, const char *interf, unsigned int slen; char *p; char hostname[1024]; - struct hostent *he; +// struct hostent *he; struct libwebsocket *wsi; + struct sockaddr sa; #ifdef LWS_OPENSSL_SUPPORT SSL_METHOD *method; @@ -2584,10 +2587,20 @@ libwebsocket_create_context(int port, const char *interf, /* find canonical hostname */ hostname[(sizeof hostname) - 1] = '\0'; + sa.sa_family = AF_INET; + sa.sa_data[(sizeof sa.sa_data) - 1] = '\0'; gethostname(hostname, (sizeof hostname) - 1); - he = gethostbyname(hostname); - if (he) { - strncpy(context->canonical_hostname, he->h_name, + + n = 0; + + if (strlen(hostname) < sizeof(sa.sa_data) - 1) { +// fprintf(stderr, "my host name is %s\n", sa.sa_data); + n = getnameinfo(&sa, sizeof(sa), hostname, (sizeof hostname) - 1, + NULL, 0, 0); + } + + if (!n) { + strncpy(context->canonical_hostname, hostname, sizeof context->canonical_hostname - 1); context->canonical_hostname[ sizeof context->canonical_hostname - 1] = '\0'; @@ -2595,6 +2608,9 @@ libwebsocket_create_context(int port, const char *interf, strncpy(context->canonical_hostname, hostname, sizeof context->canonical_hostname - 1); +// fprintf(stderr, "context->canonical_hostname = %s\n", +// context->canonical_hostname); + /* split the proxy ads:port if given */ p = getenv("http_proxy"); |