return 1;
}
+/**
+ * libwebsocket_canonical_hostname() - returns this host's hostname
+ *
+ * This is typically used by client code to fill in the host parameter
+ * when making a client connection. You can only call it after the context
+ * has been created.
+ *
+ * @this: Websocket context
+ */
+
+
+extern const char *
+libwebsocket_canonical_hostname(struct libwebsocket_context *this)
+{
+ return (const char *)this->canonical_hostname;
+}
+
+
static void sigpipe_handler(int x)
{
}
struct libwebsocket_context *this = NULL;
unsigned int slen;
char *p;
+ char hostname[1024];
+ struct hostent* he;
#ifdef LWS_OPENSSL_SUPPORT
SSL_METHOD *method;
this->http_proxy_port = 0;
this->http_proxy_address[0] = '\0';
+ /* find canonical hostname */
+
+ hostname[(sizeof hostname) - 1] = '\0';
+ gethostname(hostname, (sizeof hostname) - 1);
+ he = gethostbyname(hostname);
+ strncpy(this->canonical_hostname, he->h_name,
+ sizeof this->canonical_hostname - 1);
+ this->canonical_hostname[sizeof this->canonical_hostname - 1] = '\0';
+
/* split the proxy ads:port if given */
p = getenv("http_proxy");
const char *origin,
const char *protocol);
-void
+extern const char *
+libwebsocket_canonical_hostname(struct libwebsocket_context *this);
+
+extern void
libwebsocket_client_close(struct libwebsocket *wsi);
#endif
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
+#include <netdb.h>
#include <sys/types.h>
#include <sys/stat.h>
int fds_count;
int listen_port;
char http_proxy_address[256];
+ char canonical_hostname[1024];
unsigned int http_proxy_port;
#ifdef LWS_OPENSSL_SUPPORT
int use_ssl;
control for the input side.
</blockquote>
<hr>
+<h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
+<i>const char *</i>
+<b>libwebsocket_canonical_hostname</b>
+(<i>struct libwebsocket_context *</i> <b>this</b>)
+<h3>Arguments</h3>
+<dl>
+<dt><b>this</b>
+<dd>Websocket context
+</dl>
+<h3>Description</h3>
+<blockquote>
+<p>
+This is typically used by client code to fill in the host parameter
+when making a client connection. You can only call it after the context
+has been created.
+</blockquote>
+<hr>
<h2>libwebsocket_create_context - Create the websocket handler</h2>
<i>struct libwebsocket_context *</i>
<b>libwebsocket_create_context</b>
#include <getopt.h>
#include <string.h>
-
#include "../lib/libwebsockets.h"
#include <poll.h>
struct libwebsocket *wsi_dumb;
struct libwebsocket *wsi_mirror;
-
fprintf(stderr, "libwebsockets test client\n"
"(C) Copyright 2010 Andy Green <andy@warmcat.com> "
"licensed under LGPL2.1\n");
/* create a client websocket using dumb increment protocol */
wsi_dumb = libwebsocket_client_connect(context, address, port, use_ssl,
- "/", "http://host", "origin",
+ "/", libwebsocket_canonical_hostname(context), "origin",
protocols[PROTOCOL_DUMB_INCREMENT].name);
if (wsi_dumb == NULL) {
/* create a client websocket using mirror protocol */
wsi_mirror = libwebsocket_client_connect(context, address, port,
- use_ssl, "/", "http://host", "origin",
+ use_ssl, "/", libwebsocket_canonical_hostname(context), "origin",
protocols[PROTOCOL_LWS_MIRROR].name);
if (wsi_mirror == NULL) {
/* create a client websocket using dumb increment protocol */
- wsi_mirror = libwebsocket_client_connect(context, address, port, use_ssl,
- "/", "http://host", "origin",
- protocols[PROTOCOL_LWS_MIRROR].name);
+ wsi_mirror = libwebsocket_client_connect(context, address, port,
+ use_ssl, "/", libwebsocket_canonical_hostname(context),
+ "origin", protocols[PROTOCOL_LWS_MIRROR].name);
if (wsi_mirror == NULL) {
fprintf(stderr, "libwebsocket connect failed\n");