diff --git a/miniupnpc/connecthostport.c b/miniupnpc/connecthostport.c index ea6e4e5..9a459e7 100644 --- a/miniupnpc/connecthostport.c +++ b/miniupnpc/connecthostport.c @@ -48,6 +48,12 @@ #define PRINT_SOCKET_ERROR(x) perror(x) #endif +#ifdef _MSC_VER +#define MSC_CAST_INT (int) +#else +#define MSC_CAST_INT +#endif + #if defined(__amigaos__) || defined(__amigaos4__) #define herror(A) printf("%s\n", A) #endif @@ -183,7 +189,7 @@ SOCKET connecthostport(const char * host, unsigned short port, #endif return INVALID_SOCKET; } - s = -1; + s = INVALID_SOCKET; for(p = ai; p; p = p->ai_next) { s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); @@ -208,7 +214,7 @@ SOCKET connecthostport(const char * host, unsigned short port, PRINT_SOCKET_ERROR("setsockopt"); } #endif /* #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT */ - n = connect(s, p->ai_addr, p->ai_addrlen); + n = connect(s, p->ai_addr, MSC_CAST_INT p->ai_addrlen); #ifdef MINIUPNPC_IGNORE_EINTR /* EINTR The system call was interrupted by a signal that was caught * EINPROGRESS The socket is nonblocking and the connection cannot @@ -261,4 +267,3 @@ SOCKET connecthostport(const char * host, unsigned short port, #endif /* #ifdef USE_GETHOSTBYNAME */ return s; } - diff --git a/miniupnpc/minisoap.c b/miniupnpc/minisoap.c index 520c930..e76558a 100644 --- a/miniupnpc/minisoap.c +++ b/miniupnpc/minisoap.c @@ -79,11 +79,10 @@ int soapPostSubmit(SOCKET fd, const char * body, const char * httpversion) { - int bodysize; char headerbuf[512]; int headerssize; char portstr[8]; - bodysize = (int)strlen(body); + int bodysize = (int)strlen(body); /* We are not using keep-alive HTTP connections. * HTTP/1.1 needs the header Connection: close to do that. * This is the default with HTTP/1.0 diff --git a/miniupnpc/minissdpc.c b/miniupnpc/minissdpc.c index d76b242..979505e 100644 --- a/miniupnpc/minissdpc.c +++ b/miniupnpc/minissdpc.c @@ -60,6 +60,12 @@ struct sockaddr_un { #define closesocket close #endif +#ifdef _MSC_VER +#define MSC_CAST_INT (int) +#else +#define MSC_CAST_INT +#endif + #include "miniupnpc_socketdef.h" #if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) && !defined(__GNU__) && !defined(__FreeBSD_kernel__) @@ -561,18 +567,18 @@ ssdpDiscoverDevices(const char * const deviceTypes[], dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 ); if (dwRetVal == NO_ERROR) { #ifdef DEBUG - printf("\tNum Entries: %ld\n", pIPAddrTable->dwNumEntries); + printf("\tNum Entries: %lu\n", pIPAddrTable->dwNumEntries); #endif for (i=0; i < (int) pIPAddrTable->dwNumEntries; i++) { #ifdef DEBUG - printf("\n\tInterface Index[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwIndex); + printf("\n\tInterface Index[%d]:\t%lu\n", i, pIPAddrTable->table[i].dwIndex); IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwAddr; printf("\tIP Address[%d]: \t%s\n", i, inet_ntoa(IPAddr) ); IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask; printf("\tSubnet Mask[%d]: \t%s\n", i, inet_ntoa(IPAddr) ); IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr; - printf("\tBroadCast[%d]: \t%s (%ld)\n", i, inet_ntoa(IPAddr), pIPAddrTable->table[i].dwBCastAddr); - printf("\tReassembly size[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwReasmSize); + printf("\tBroadCast[%d]: \t%s (%lu)\n", i, inet_ntoa(IPAddr), pIPAddrTable->table[i].dwBCastAddr); + printf("\tReassembly size[%d]:\t%lu\n", i, pIPAddrTable->table[i].dwReasmSize); printf("\tType and State[%d]:", i); printf("\n"); #endif @@ -592,7 +598,6 @@ ssdpDiscoverDevices(const char * const deviceTypes[], } } free(pIPAddrTable); - pIPAddrTable = NULL; } } #endif /* _WIN32 */ @@ -780,7 +785,7 @@ ssdpDiscoverDevices(const char * const deviceTypes[], break; } for(p = servinfo; p; p = p->ai_next) { - n = sendto(sudp, bufr, n, 0, p->ai_addr, p->ai_addrlen); + n = sendto(sudp, bufr, n, 0, p->ai_addr, MSC_CAST_INT p->ai_addrlen); if (n < 0) { #ifdef DEBUG char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; diff --git a/miniupnpc/minissdpc.h b/miniupnpc/minissdpc.h index 167d897..c99f929 100644 --- a/miniupnpc/minissdpc.h +++ b/miniupnpc/minissdpc.h @@ -32,13 +32,13 @@ MINIUPNP_LIBSPEC int connectToMiniSSDPD(const char * socketpath); MINIUPNP_LIBSPEC int -disconnectFromMiniSSDPD(int fd); +disconnectFromMiniSSDPD(int s); MINIUPNP_LIBSPEC int -requestDevicesFromMiniSSDPD(int fd, const char * devtype); +requestDevicesFromMiniSSDPD(int s, const char * devtype); MINIUPNP_LIBSPEC struct UPNPDev * -receiveDevicesFromMiniSSDPD(int fd, int * error); +receiveDevicesFromMiniSSDPD(int s, int * error); #endif /* !(defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__)) */ diff --git a/miniupnpc/miniupnpc.c b/miniupnpc/miniupnpc.c index 5d93ef9..5e2653e 100644 --- a/miniupnpc/miniupnpc.c +++ b/miniupnpc/miniupnpc.c @@ -416,7 +416,7 @@ static char * build_absolute_url(const char * baseurl, const char * descURL, const char * url, unsigned int scope_id) { - int l, n; + size_t l, n; char * s; const char * base; char * p; @@ -573,7 +573,6 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, int ndev = 0; int i; int state = -1; /* state 1 : IGD connected. State 2 : IGD. State 3 : anything */ - int n_igd = 0; char extIpAddr[16]; char myLanAddr[40]; int status_code = -1; @@ -588,12 +587,10 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, /* counting total number of devices in the list */ for(dev = devlist; dev; dev = dev->pNext) ndev++; - if(ndev > 0) - { - desc = calloc(ndev, sizeof(struct xml_desc)); - if(!desc) - return -1; /* memory allocation error */ - } + /* ndev is always > 0 */ + desc = calloc(ndev, sizeof(struct xml_desc)); + if(!desc) + return -1; /* memory allocation error */ /* Step 1 : downloading descriptions and testing type */ for(dev = devlist, i = 0; dev; dev = dev->pNext, i++) { @@ -617,7 +614,6 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:")) { desc[i].is_igd = 1; - n_igd++; if(lanaddr) strncpy(lanaddr, myLanAddr, lanaddrlen); } @@ -685,14 +681,9 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, } state = 0; free_and_return: - if(desc) { - for(i = 0; i < ndev; i++) { - if(desc[i].xml) { - free(desc[i].xml); - } - } - free(desc); - } + for(i = 0; i < ndev; i++) + free(desc[i].xml); + free(desc); return state; } @@ -717,7 +708,6 @@ UPNP_GetIGDFromUrl(const char * rootdescurl, memset(urls, 0, sizeof(struct UPNPUrls)); parserootdesc(descXML, descXMLsize, data); free(descXML); - descXML = NULL; GetUPNPUrls(urls, data, rootdescurl, 0); return 1; } else { diff --git a/miniupnpc/miniwget.c b/miniupnpc/miniwget.c index a46ba76..5c135f4 100644 --- a/miniupnpc/miniwget.c +++ b/miniupnpc/miniwget.c @@ -243,7 +243,7 @@ getHTTPResponse(SOCKET s, int * size, int * status_code) /* reading chunk size */ if(chunksize_buf_index == 0) { /* skipping any leading CR LF */ - if(i