testasync.c: select 1st device
This commit is contained in:
parent
bbb27ab97d
commit
73223d8e20
|
@ -37,6 +37,7 @@ int main(int argc, char * * argv)
|
||||||
char ip_address[64];
|
char ip_address[64];
|
||||||
int r, n;
|
int r, n;
|
||||||
upnpc_t upnp;
|
upnpc_t upnp;
|
||||||
|
upnpc_device_t * device = NULL;
|
||||||
const char * multicastif = NULL;
|
const char * multicastif = NULL;
|
||||||
enum methods next_method_to_call = EGetExternalIP;
|
enum methods next_method_to_call = EGetExternalIP;
|
||||||
enum methods last_method = ENothing;
|
enum methods last_method = ENothing;
|
||||||
|
@ -82,18 +83,22 @@ int main(int argc, char * * argv)
|
||||||
break;
|
break;
|
||||||
if(upnp.state == EReady) {
|
if(upnp.state == EReady) {
|
||||||
char * p;
|
char * p;
|
||||||
printf("Process UPnP IGD Method results : HTTP %d\n", upnp.device_list->http_response_code); /* XXX */
|
if(device == NULL) {
|
||||||
if(upnp.device_list->http_response_code == 200) {
|
/* select one device */
|
||||||
|
device = upnp.device_list; /* pick up the first one */
|
||||||
|
}
|
||||||
|
printf("Process UPnP IGD Method results : HTTP %d\n", device->http_response_code);
|
||||||
|
if(device->http_response_code == 200) {
|
||||||
switch(last_method) {
|
switch(last_method) {
|
||||||
case EGetExternalIP:
|
case EGetExternalIP:
|
||||||
p = GetValueFromNameValueList(&upnp.device_list->soap_response_data, "NewExternalIPAddress");
|
p = GetValueFromNameValueList(&device->soap_response_data, "NewExternalIPAddress");
|
||||||
printf("ExternalIPAddress = %s\n", p);
|
printf("ExternalIPAddress = %s\n", p);
|
||||||
/* p = GetValueFromNameValueList(&pdata, "errorCode");*/
|
/* p = GetValueFromNameValueList(&pdata, "errorCode");*/
|
||||||
break;
|
break;
|
||||||
case EGetRates:
|
case EGetRates:
|
||||||
p = GetValueFromNameValueList(&upnp.device_list->soap_response_data, "NewLayer1DownstreamMaxBitRate");
|
p = GetValueFromNameValueList(&device->soap_response_data, "NewLayer1DownstreamMaxBitRate");
|
||||||
printf("DownStream MaxBitRate = %s\t", p);
|
printf("DownStream MaxBitRate = %s\t", p);
|
||||||
p = GetValueFromNameValueList(&upnp.device_list->soap_response_data, "NewLayer1UpstreamMaxBitRate");
|
p = GetValueFromNameValueList(&device->soap_response_data, "NewLayer1UpstreamMaxBitRate");
|
||||||
printf("UpStream MaxBitRate = %s\n", p);
|
printf("UpStream MaxBitRate = %s\n", p);
|
||||||
break;
|
break;
|
||||||
case EAddPortMapping:
|
case EAddPortMapping:
|
||||||
|
@ -104,10 +109,10 @@ int main(int argc, char * * argv)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("SOAP error :\n");
|
printf("SOAP error :\n");
|
||||||
printf(" faultcode='%s'\n", GetValueFromNameValueList(&upnp.device_list->soap_response_data, "faultcode"));
|
printf(" faultcode='%s'\n", GetValueFromNameValueList(&device->soap_response_data, "faultcode"));
|
||||||
printf(" faultstring='%s'\n", GetValueFromNameValueList(&upnp.device_list->soap_response_data, "faultstring"));
|
printf(" faultstring='%s'\n", GetValueFromNameValueList(&device->soap_response_data, "faultstring"));
|
||||||
printf(" errorCode=%s\n", GetValueFromNameValueList(&upnp.device_list->soap_response_data, "errorCode"));
|
printf(" errorCode=%s\n", GetValueFromNameValueList(&device->soap_response_data, "errorCode"));
|
||||||
printf(" errorDescription='%s'\n", GetValueFromNameValueList(&upnp.device_list->soap_response_data, "errorDescription"));
|
printf(" errorDescription='%s'\n", GetValueFromNameValueList(&device->soap_response_data, "errorDescription"));
|
||||||
}
|
}
|
||||||
if(next_method_to_call == ENothing)
|
if(next_method_to_call == ENothing)
|
||||||
break;
|
break;
|
||||||
|
@ -116,22 +121,22 @@ int main(int argc, char * * argv)
|
||||||
switch(next_method_to_call) {
|
switch(next_method_to_call) {
|
||||||
case EGetExternalIP:
|
case EGetExternalIP:
|
||||||
printf("GetExternalIPAddress\n");
|
printf("GetExternalIPAddress\n");
|
||||||
upnpc_get_external_ip_address(upnp.device_list);
|
upnpc_get_external_ip_address(device);
|
||||||
next_method_to_call = EGetRates;
|
next_method_to_call = EGetRates;
|
||||||
break;
|
break;
|
||||||
case EGetRates:
|
case EGetRates:
|
||||||
printf("GetCommonLinkProperties\n");
|
printf("GetCommonLinkProperties\n");
|
||||||
upnpc_get_link_layer_max_rate(upnp.device_list);
|
upnpc_get_link_layer_max_rate(device);
|
||||||
next_method_to_call = EAddPortMapping;
|
next_method_to_call = EAddPortMapping;
|
||||||
break;
|
break;
|
||||||
case EAddPortMapping:
|
case EAddPortMapping:
|
||||||
if(getnameinfo((struct sockaddr *)&upnp.device_list->selfaddr, upnp.device_list->selfaddrlen,
|
if(getnameinfo((struct sockaddr *)&device->selfaddr, device->selfaddrlen,
|
||||||
ip_address, sizeof(ip_address), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV) < 0) {
|
ip_address, sizeof(ip_address), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV) < 0) {
|
||||||
fprintf(stderr, "getnameinfo() failed\n");
|
fprintf(stderr, "getnameinfo() failed\n");
|
||||||
}
|
}
|
||||||
printf("our IP address is %s\n", ip_address);
|
printf("our IP address is %s\n", ip_address);
|
||||||
printf("AddPortMapping\n");
|
printf("AddPortMapping\n");
|
||||||
upnpc_add_port_mapping(upnp.device_list, /* XXX */
|
upnpc_add_port_mapping(device,
|
||||||
NULL /* remote_host */, 40002 /* ext_port */,
|
NULL /* remote_host */, 40002 /* ext_port */,
|
||||||
42042 /* int_port */, ip_address /* int_client */,
|
42042 /* int_port */, ip_address /* int_client */,
|
||||||
"TCP" /* proto */, "this is a test" /* description */,
|
"TCP" /* proto */, "this is a test" /* description */,
|
||||||
|
|
Loading…
Reference in New Issue