diff --git a/minimal-examples/ws-client/minimal-ws-client-echo/README.md b/minimal-examples/ws-client/minimal-ws-client-echo/README.md index af8847af0..51538968c 100644 --- a/minimal-examples/ws-client/minimal-ws-client-echo/README.md +++ b/minimal-examples/ws-client/minimal-ws-client-echo/README.md @@ -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 |Bind the client connection to interface iface ``` $ ./lws-minimal-ws-client-echo diff --git a/minimal-examples/ws-client/minimal-ws-client-echo/minimal-ws-client-echo.c b/minimal-examples/ws-client/minimal-ws-client-echo/minimal-ws-client-echo.c index 25a243fb4..4158e1624 100644 --- a/minimal-examples/ws-client/minimal-ws-client-echo/minimal-ws-client-echo.c +++ b/minimal-examples/ws-client/minimal-ws-client-echo/minimal-ws-client-echo.c @@ -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 */ diff --git a/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c b/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c index d83279855..4a0d6d769 100644 --- a/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c +++ b/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c @@ -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);