net: http_server: Allow service to be created with NULL host
Allow NULL host parameter when creating HTTP service. This means that the socket is created without specifying binding address. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
7e20a86e6a
commit
3949873886
1 changed files with 4 additions and 3 deletions
|
|
@ -108,14 +108,14 @@ int http_server_init(struct http_server_ctx *ctx)
|
||||||
memset(&addr_storage, 0, sizeof(struct sockaddr_storage));
|
memset(&addr_storage, 0, sizeof(struct sockaddr_storage));
|
||||||
|
|
||||||
/* Set up the server address struct according to address family */
|
/* Set up the server address struct according to address family */
|
||||||
if (IS_ENABLED(CONFIG_NET_IPV6) &&
|
if (IS_ENABLED(CONFIG_NET_IPV6) && svc->host != NULL &&
|
||||||
zsock_inet_pton(AF_INET6, svc->host, &addr.addr6->sin6_addr) == 1) {
|
zsock_inet_pton(AF_INET6, svc->host, &addr.addr6->sin6_addr) == 1) {
|
||||||
af = AF_INET6;
|
af = AF_INET6;
|
||||||
len = sizeof(*addr.addr6);
|
len = sizeof(*addr.addr6);
|
||||||
|
|
||||||
addr.addr6->sin6_family = AF_INET6;
|
addr.addr6->sin6_family = AF_INET6;
|
||||||
addr.addr6->sin6_port = htons(*svc->port);
|
addr.addr6->sin6_port = htons(*svc->port);
|
||||||
} else if (IS_ENABLED(CONFIG_NET_IPV4) &&
|
} else if (IS_ENABLED(CONFIG_NET_IPV4) && svc->host != NULL &&
|
||||||
zsock_inet_pton(AF_INET, svc->host, &addr.addr4->sin_addr) == 1) {
|
zsock_inet_pton(AF_INET, svc->host, &addr.addr4->sin_addr) == 1) {
|
||||||
af = AF_INET;
|
af = AF_INET;
|
||||||
len = sizeof(*addr.addr4);
|
len = sizeof(*addr.addr4);
|
||||||
|
|
@ -209,7 +209,8 @@ int http_server_init(struct http_server_ctx *ctx)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DBG("Initialized HTTP Service %s:%u", svc->host, *svc->port);
|
LOG_DBG("Initialized HTTP Service %s:%u",
|
||||||
|
svc->host ? svc->host : "<any>", *svc->port);
|
||||||
|
|
||||||
ctx->fds[count].fd = fd;
|
ctx->fds[count].fd = fd;
|
||||||
ctx->fds[count].events = ZSOCK_POLLIN;
|
ctx->fds[count].events = ZSOCK_POLLIN;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue