From 1217512a322fc77cead1cd8d690b3ebb44687d29 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 12 Dec 2014 18:58:06 +0100 Subject: [PATCH] miniupnpc-libevent: upnpc_set_local_address() --- miniupnpc-libevent/miniupnpc-libevent.c | 8 ++++++++ miniupnpc-libevent/miniupnpc-libevent.h | 4 ++++ miniupnpc-libevent/upnpc-libevent.c | 1 + 3 files changed, 13 insertions(+) diff --git a/miniupnpc-libevent/miniupnpc-libevent.c b/miniupnpc-libevent/miniupnpc-libevent.c index 9e4df05..d5dbfd8 100644 --- a/miniupnpc-libevent/miniupnpc-libevent.c +++ b/miniupnpc-libevent/miniupnpc-libevent.c @@ -680,6 +680,14 @@ int upnpc_start(upnpc_t * p) return UPNPC_OK; } +int upnpc_set_local_address(upnpc_t * p, const char * address, uint16_t port) +{ + if(!p || !address) return UPNPC_ERR_INVALID_ARGS; + p->local_address = strdup(address); /* TODO check error */ + p->local_port = port; + return UPNPC_OK; +} + static void upnpc_device_finalize(upnpc_device_t * d) { d->state = 0; diff --git a/miniupnpc-libevent/miniupnpc-libevent.h b/miniupnpc-libevent/miniupnpc-libevent.h index b52be1d..0b55f49 100644 --- a/miniupnpc-libevent/miniupnpc-libevent.h +++ b/miniupnpc-libevent/miniupnpc-libevent.h @@ -76,11 +76,15 @@ struct upnpc { upnpc_callback_fn ready_cb; upnpc_callback_fn soap_cb; void * cb_data; + char * local_address; + uint16_t local_port; }; int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif, upnpc_callback_fn ready_cb, upnpc_callback_fn soap_cb, void * cb_data); +int upnpc_set_local_address(upnpc_t * p, const char * address, uint16_t port); + int upnpc_start(upnpc_t * p); int upnpc_finalize(upnpc_t * p); diff --git a/miniupnpc-libevent/upnpc-libevent.c b/miniupnpc-libevent/upnpc-libevent.c index 9079a4c..d8326a6 100644 --- a/miniupnpc-libevent/upnpc-libevent.c +++ b/miniupnpc-libevent/upnpc-libevent.c @@ -215,6 +215,7 @@ int main(int argc, char * * argv) fprintf(stderr, "upnpc_init() failed\n"); return 1; } + upnpc_set_local_address(&upnp, local_address, 50000); if(upnpc_start(&upnp) != UPNPC_OK) { fprintf(stderr, "upnp_start() failed\n"); return 1;