mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
just get hostname into canonical_hostname
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
475bbdc938
commit
adc71469da
1 changed files with 1 additions and 33 deletions
|
@ -1750,40 +1750,8 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
|
||||||
|
|
||||||
#ifndef LWS_NO_SERVER
|
#ifndef LWS_NO_SERVER
|
||||||
if (!(info->options & LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME)) {
|
if (!(info->options & LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME)) {
|
||||||
struct sockaddr sa;
|
|
||||||
context->service_buffer[0] = '\0';
|
|
||||||
|
|
||||||
/* find canonical hostname */
|
/* find canonical hostname */
|
||||||
|
gethostname((char *)context->canonical_hostname,
|
||||||
context->service_buffer[
|
|
||||||
sizeof(context->service_buffer) - 1] = '\0';
|
|
||||||
memset(&sa, 0, sizeof(sa));
|
|
||||||
sa.sa_family = AF_INET;
|
|
||||||
sa.sa_data[sizeof(sa.sa_data) - 1] = '\0';
|
|
||||||
gethostname((char *)context->service_buffer,
|
|
||||||
sizeof(context->service_buffer) - 1);
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
|
|
||||||
if (strlen((char *)context->service_buffer) <
|
|
||||||
sizeof(sa.sa_data) - 1) {
|
|
||||||
strcpy(sa.sa_data, (char *)context->service_buffer);
|
|
||||||
lwsl_debug("my host name is %s\n", sa.sa_data);
|
|
||||||
n = getnameinfo(&sa, sizeof(sa),
|
|
||||||
(char *)context->service_buffer,
|
|
||||||
sizeof(context->service_buffer) - 1,
|
|
||||||
NULL, 0, NI_NAMEREQD);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!n) {
|
|
||||||
strncpy(context->canonical_hostname,
|
|
||||||
(char *)context->service_buffer,
|
|
||||||
sizeof(context->canonical_hostname) - 1);
|
|
||||||
context->canonical_hostname[
|
|
||||||
sizeof(context->canonical_hostname) - 1] = '\0';
|
|
||||||
} else
|
|
||||||
strncpy(context->canonical_hostname,
|
|
||||||
(char *)context->service_buffer,
|
|
||||||
sizeof(context->canonical_hostname) - 1);
|
sizeof(context->canonical_hostname) - 1);
|
||||||
|
|
||||||
lwsl_notice(" canonical_hostname = %s\n",
|
lwsl_notice(" canonical_hostname = %s\n",
|
||||||
|
|
Loading…
Add table
Reference in a new issue