Win32 : use InetPton() etc. to silence MSVC warnings

This commit is contained in:
Thomas Bernard 2018-07-14 12:53:42 +02:00
parent fe73488e88
commit 8babc5d013
1 changed files with 16 additions and 5 deletions

View File

@ -544,8 +544,10 @@ ssdpDiscoverDevices(const char * const deviceTypes[],
* SSDP multicast traffic */ * SSDP multicast traffic */
/* Get IP associated with the index given in the ip_forward struct /* Get IP associated with the index given in the ip_forward struct
* in order to give this ip to setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF) */ * in order to give this ip to setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF) */
if(!ipv6 if(!ipv6) {
&& (GetBestRoute(inet_addr("223.255.255.255"), 0, &ip_forward) == NO_ERROR)) { IN_ADDR addr;
InetPtonA(AF_INET, "223.255.255.255", &addr);
if (GetBestRoute(addr.S_un.S_addr, 0, &ip_forward) == NO_ERROR) {
DWORD dwRetVal = 0; DWORD dwRetVal = 0;
PMIB_IPADDRTABLE pIPAddrTable; PMIB_IPADDRTABLE pIPAddrTable;
DWORD dwSize = 0; DWORD dwSize = 0;
@ -571,13 +573,17 @@ ssdpDiscoverDevices(const char * const deviceTypes[],
#endif #endif
for (i=0; i < (int) pIPAddrTable->dwNumEntries; i++) { for (i=0; i < (int) pIPAddrTable->dwNumEntries; i++) {
#ifdef DEBUG #ifdef DEBUG
char buffer[16];
printf("\n\tInterface Index[%d]:\t%lu\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; IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwAddr;
printf("\tIP Address[%d]: \t%s\n", i, inet_ntoa(IPAddr) ); InetNtopA(AF_INET, &IPAddr, buffer, sizeof(buffer));
printf("\tIP Address[%d]: \t%s\n", i, buffer );
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask; IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask;
printf("\tSubnet Mask[%d]: \t%s\n", i, inet_ntoa(IPAddr) ); InetNtopA(AF_INET, &IPAddr, buffer, sizeof(buffer));
printf("\tSubnet Mask[%d]: \t%s\n", i, buffer );
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr; IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr;
printf("\tBroadCast[%d]: \t%s (%lu)\n", i, inet_ntoa(IPAddr), pIPAddrTable->table[i].dwBCastAddr); InetNtopA(AF_INET, &IPAddr, buffer, sizeof(buffer));
printf("\tBroadCast[%d]: \t%s (%lu)\n", i, buffer, pIPAddrTable->table[i].dwBCastAddr);
printf("\tReassembly size[%d]:\t%lu\n", i, pIPAddrTable->table[i].dwReasmSize); printf("\tReassembly size[%d]:\t%lu\n", i, pIPAddrTable->table[i].dwReasmSize);
printf("\tType and State[%d]:", i); printf("\tType and State[%d]:", i);
printf("\n"); printf("\n");
@ -599,6 +605,7 @@ ssdpDiscoverDevices(const char * const deviceTypes[],
} }
free(pIPAddrTable); free(pIPAddrTable);
} }
}
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
@ -656,7 +663,11 @@ ssdpDiscoverDevices(const char * const deviceTypes[],
#endif #endif
} else { } else {
struct in_addr mc_if; struct in_addr mc_if;
#if defined(_WIN32)
InetPtonA(AF_INET, multicastif, &mc_if);
#else
mc_if.s_addr = inet_addr(multicastif); /* ex: 192.168.x.x */ mc_if.s_addr = inet_addr(multicastif); /* ex: 192.168.x.x */
#endif
if(mc_if.s_addr != INADDR_NONE) if(mc_if.s_addr != INADDR_NONE)
{ {
((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = mc_if.s_addr; ((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = mc_if.s_addr;