add context construction option to skip server hostname lookup
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
15e31f373d
commit
788c4a8fa8
3 changed files with 36 additions and 24 deletions
|
@ -2596,35 +2596,43 @@ libwebsocket_create_context(int port, const char *interf,
|
|||
context->ssl_client_ctx = NULL;
|
||||
openssl_websocket_private_data_index = 0;
|
||||
#endif
|
||||
/* find canonical hostname */
|
||||
|
||||
hostname[(sizeof hostname) - 1] = '\0';
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_family = AF_INET;
|
||||
sa.sa_data[(sizeof sa.sa_data) - 1] = '\0';
|
||||
gethostname(hostname, (sizeof hostname) - 1);
|
||||
if (options & LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME) {
|
||||
|
||||
n = 0;
|
||||
strcpy(context->canonical_hostname, "unknown");
|
||||
|
||||
if (strlen(hostname) < sizeof(sa.sa_data) - 1) {
|
||||
strcpy(sa.sa_data, hostname);
|
||||
// fprintf(stderr, "my host name is %s\n", sa.sa_data);
|
||||
n = getnameinfo(&sa, sizeof(sa), hostname,
|
||||
(sizeof hostname) - 1, NULL, 0, 0);
|
||||
} else {
|
||||
|
||||
/* find canonical hostname */
|
||||
|
||||
hostname[(sizeof hostname) - 1] = '\0';
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_family = AF_INET;
|
||||
sa.sa_data[(sizeof sa.sa_data) - 1] = '\0';
|
||||
gethostname(hostname, (sizeof hostname) - 1);
|
||||
|
||||
n = 0;
|
||||
|
||||
if (strlen(hostname) < sizeof(sa.sa_data) - 1) {
|
||||
strcpy(sa.sa_data, hostname);
|
||||
// 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';
|
||||
} else
|
||||
strncpy(context->canonical_hostname, hostname,
|
||||
sizeof context->canonical_hostname - 1);
|
||||
|
||||
// fprintf(stderr, "context->canonical_hostname = %s\n",
|
||||
// context->canonical_hostname);
|
||||
}
|
||||
|
||||
if (!n) {
|
||||
strncpy(context->canonical_hostname, hostname,
|
||||
sizeof context->canonical_hostname - 1);
|
||||
context->canonical_hostname[
|
||||
sizeof context->canonical_hostname - 1] = '\0';
|
||||
} else
|
||||
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");
|
||||
|
|
|
@ -65,6 +65,7 @@ typedef int ssize_t;
|
|||
enum libwebsocket_context_options {
|
||||
LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK = 1,
|
||||
LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = 2,
|
||||
LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = 4,
|
||||
};
|
||||
|
||||
enum libwebsocket_callback_reasons {
|
||||
|
|
|
@ -258,6 +258,9 @@ else ignored
|
|||
<dd>user id to change to after setting listen socket, or -1.
|
||||
<dt><b>options</b>
|
||||
<dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
|
||||
<dt><b>user</b>
|
||||
<dd>optional user pointer that can be recovered via the context
|
||||
pointer using libwebsocket_context_user
|
||||
</dl>
|
||||
<h3>Description</h3>
|
||||
<blockquote>
|
||||
|
|
Loading…
Add table
Reference in a new issue