miniupnpc: More error return checks in upnpc.c

This commit is contained in:
Thomas Bernard 2012-06-24 00:44:22 +02:00
parent 590f1e3f37
commit 8c22bf187d
2 changed files with 37 additions and 31 deletions

View File

@ -1,6 +1,9 @@
$Id: Changelog.txt,v 1.171 2012/06/20 21:05:56 nanard Exp $ $Id: Changelog.txt,v 1.173 2012/06/23 22:36:34 nanard Exp $
miniUPnP client Changelog. miniUPnP client Changelog.
2012/06/23:
More error return checks in upnpc.c
2012/06/20: 2012/06/20:
fixed CMakeLists.txt fixed CMakeLists.txt

View File

@ -1,4 +1,4 @@
/* $Id: upnpc.c,v 1.95 2012/05/02 20:14:43 nanard Exp $ */ /* $Id: upnpc.c,v 1.96 2012/06/23 18:25:35 nanard Exp $ */
/* Project : miniupnp /* Project : miniupnp
* Author : Thomas Bernard * Author : Thomas Bernard
* Copyright (c) 2005-2012 Thomas Bernard * Copyright (c) 2005-2012 Thomas Bernard
@ -52,44 +52,47 @@ static void DisplayInfos(struct UPNPUrls * urls,
unsigned int brUp, brDown; unsigned int brUp, brDown;
time_t timenow, timestarted; time_t timenow, timestarted;
int r; int r;
UPNP_GetConnectionTypeInfo(urls->controlURL, if(UPNP_GetConnectionTypeInfo(urls->controlURL,
data->first.servicetype, data->first.servicetype,
connectionType); connectionType) != UPNPCOMMAND_SUCCESS)
if(connectionType[0])
printf("Connection Type : %s\n", connectionType);
else
printf("GetConnectionTypeInfo failed.\n"); printf("GetConnectionTypeInfo failed.\n");
UPNP_GetStatusInfo(urls->controlURL, data->first.servicetype, else
status, &uptime, lastconnerr); printf("Connection Type : %s\n", connectionType);
printf("Status : %s, uptime=%us, LastConnectionError : %s\n", if(UPNP_GetStatusInfo(urls->controlURL, data->first.servicetype,
status, uptime, lastconnerr); status, &uptime, lastconnerr) != UPNPCOMMAND_SUCCESS)
printf("GetStatusInfo failed.\n");
else
printf("Status : %s, uptime=%us, LastConnectionError : %s\n",
status, uptime, lastconnerr);
timenow = time(NULL); timenow = time(NULL);
timestarted = timenow - uptime; timestarted = timenow - uptime;
printf(" Time started : %s", ctime(&timestarted)); printf(" Time started : %s", ctime(&timestarted));
UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, data->CIF.servicetype, if(UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, data->CIF.servicetype,
&brDown, &brUp); &brDown, &brUp) != UPNPCOMMAND_SUCCESS) {
printf("MaxBitRateDown : %u bps", brDown); printf("GetLinkLayerMaxBitRates failed.\n");
if(brDown >= 1000000) { } else {
printf(" (%u.%u Mbps)", brDown / 1000000, (brDown / 100000) % 10); printf("MaxBitRateDown : %u bps", brDown);
} else if(brDown >= 1000) { if(brDown >= 1000000) {
printf(" (%u Kbps)", brDown / 1000); printf(" (%u.%u Mbps)", brDown / 1000000, (brDown / 100000) % 10);
} else if(brDown >= 1000) {
printf(" (%u Kbps)", brDown / 1000);
}
printf(" MaxBitRateUp %u bps", brUp);
if(brUp >= 1000000) {
printf(" (%u.%u Mbps)", brUp / 1000000, (brUp / 100000) % 10);
} else if(brUp >= 1000) {
printf(" (%u Kbps)", brUp / 1000);
}
printf("\n");
} }
printf(" MaxBitRateUp %u bps", brUp);
if(brUp >= 1000000) {
printf(" (%u.%u Mbps)", brUp / 1000000, (brUp / 100000) % 10);
} else if(brUp >= 1000) {
printf(" (%u Kbps)", brUp / 1000);
}
printf("\n");
r = UPNP_GetExternalIPAddress(urls->controlURL, r = UPNP_GetExternalIPAddress(urls->controlURL,
data->first.servicetype, data->first.servicetype,
externalIPAddress); externalIPAddress);
if(r != UPNPCOMMAND_SUCCESS) if(r != UPNPCOMMAND_SUCCESS) {
printf("GetExternalIPAddress() returned %d\n", r); printf("GetExternalIPAddress failed. (errorcode=%d)\n", r);
if(externalIPAddress[0]) } else {
printf("ExternalIPAddress = %s\n", externalIPAddress); printf("ExternalIPAddress = %s\n", externalIPAddress);
else }
printf("GetExternalIPAddress failed.\n");
} }
static void GetConnectionStatus(struct UPNPUrls * urls, static void GetConnectionStatus(struct UPNPUrls * urls,