mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
minimal-ws-client-echo: add -i iface option to allow control of client iface bind
This commit is contained in:
parent
1e00d1d05a
commit
2cb6732629
3 changed files with 18 additions and 2 deletions
|
@ -20,6 +20,7 @@ Commandline option|Meaning
|
|||
-u url|URL path part to connect to
|
||||
-o|Finish after one connection
|
||||
--ssl|Open client connection with ssl
|
||||
-i <iface>|Bind the client connection to interface iface
|
||||
|
||||
```
|
||||
$ ./lws-minimal-ws-client-echo
|
||||
|
|
|
@ -24,13 +24,20 @@ static struct lws_protocols protocols[] = {
|
|||
|
||||
static struct lws_context *context;
|
||||
static int interrupted, port = 7681, options = 0;
|
||||
static const char *url = "/", *ads = "localhost";
|
||||
static const char *url = "/", *ads = "localhost", *iface = NULL;
|
||||
|
||||
/* pass pointers to shared vars to the protocol */
|
||||
|
||||
static const struct lws_protocol_vhost_options pvo_ads = {
|
||||
static const struct lws_protocol_vhost_options pvo_iface = {
|
||||
NULL,
|
||||
NULL,
|
||||
"iface", /* pvo name */
|
||||
(void *)&iface /* pvo value */
|
||||
};
|
||||
|
||||
static const struct lws_protocol_vhost_options pvo_ads = {
|
||||
&pvo_iface,
|
||||
NULL,
|
||||
"ads", /* pvo name */
|
||||
(void *)&ads /* pvo value */
|
||||
};
|
||||
|
@ -119,6 +126,9 @@ int main(int argc, const char **argv)
|
|||
if ((p = lws_cmdline_option(argc, argv, "-s")))
|
||||
ads = p;
|
||||
|
||||
if ((p = lws_cmdline_option(argc, argv, "-i")))
|
||||
iface = p;
|
||||
|
||||
lwsl_user("options %d, ads %s\n", options, ads);
|
||||
|
||||
memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */
|
||||
|
|
|
@ -45,6 +45,7 @@ struct vhd_minimal_client_echo {
|
|||
int *options;
|
||||
const char **url;
|
||||
const char **ads;
|
||||
const char **iface;
|
||||
int *port;
|
||||
};
|
||||
|
||||
|
@ -68,6 +69,7 @@ connect_client(struct vhd_minimal_client_echo *vhd)
|
|||
if ((*vhd->options) & 2)
|
||||
i.ssl_connection |= LCCSCF_USE_SSL;
|
||||
i.vhost = vhd->vhost;
|
||||
i.iface = *vhd->iface;
|
||||
//i.protocol = ;
|
||||
i.pwsi = &vhd->client_wsi;
|
||||
|
||||
|
@ -134,6 +136,9 @@ callback_minimal_client_echo(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
vhd->url = (const char **)lws_pvo_search(
|
||||
(const struct lws_protocol_vhost_options *)in,
|
||||
"url")->value;
|
||||
vhd->iface = (const char **)lws_pvo_search(
|
||||
(const struct lws_protocol_vhost_options *)in,
|
||||
"iface")->value;
|
||||
|
||||
if (connect_client(vhd))
|
||||
schedule_callback(wsi, LWS_CALLBACK_USER, 1);
|
||||
|
|
Loading…
Add table
Reference in a new issue