Commit f11c071d authored by Damien Fouilleul's avatar Damien Fouilleul

- win32 replacements for inet_pton/inet_ntop

parent 8b8ea5e9
...@@ -648,30 +648,34 @@ static const char *MakeRandMulticast (int family, char *buf, size_t buflen) ...@@ -648,30 +648,34 @@ static const char *MakeRandMulticast (int family, char *buf, size_t buflen)
#ifdef AF_INET6 #ifdef AF_INET6
case AF_INET6: case AF_INET6:
{ {
struct in6_addr addr; struct sockaddr_in6 addr;
memset(&addr, 0, sizeof(addr));
memcpy (&addr, "\xff\x38\x00\x00" "\x00\x00\x00\x00" memcpy (&addr, "\xff\x38\x00\x00" "\x00\x00\x00\x00"
"\x00\x00\x00\x00", 12); "\x00\x00\x00\x00", 12);
rand |= 0x80000000; rand |= 0x80000000;
memcpy (addr.s6_addr + 12, &(uint32_t){ htonl (rand) }, 4); memcpy (addr.sin6_addr.s6_addr + 12, &(uint32_t){ htonl (rand) }, 4);
#if defined(WIN32) || defined(UNDER_CE) #if defined(WIN32) || defined(UNDER_CE)
if( 0 == WSAAddressToStringA((LPSOCKADDR)&addr, sizeof(struct in6_addr), NULL, buf, &buflen) ) addr.sin6_family = AF_INET6;
if( 0 == WSAAddressToStringA((LPSOCKADDR)&addr, sizeof(struct sockaddr_in6), NULL, buf, &buflen) )
{ {
buf[buflen] = '\0'; buf[buflen] = '\0';
return buf; return buf;
} }
return NULL; return NULL;
#else #else
return inet_ntop (family, &addr, buf, buflen); return inet_ntop (family, &(addr.sin_addr), buf, buflen);
#endif #endif
} }
#endif #endif
case AF_INET: case AF_INET:
{ {
struct in_addr addr; struct sockaddr_in addr;
addr.s_addr = htonl ((rand & 0xffffff) | 0xe8000000); memset(&addr, 0, sizeof(addr));
addr.sin_addr.s_addr = htonl ((rand & 0xffffff) | 0xe8000000);
#if defined(WIN32) || defined(UNDER_CE) #if defined(WIN32) || defined(UNDER_CE)
if( 0 == WSAAddressToStringA((LPSOCKADDR)&addr, sizeof(struct in_addr), NULL, buf, &buflen) ) addr.sin_family = AF_INET;
if( 0 == WSAAddressToStringA((LPSOCKADDR)&addr, sizeof(struct sockaddr_in), NULL, buf, &buflen) )
{ {
buf[buflen] = '\0'; buf[buflen] = '\0';
return buf; return buf;
......
...@@ -949,10 +949,15 @@ static int ParseSDPConnection (const char *str, struct sockaddr_storage *addr, ...@@ -949,10 +949,15 @@ static int ParseSDPConnection (const char *str, struct sockaddr_storage *addr,
# endif # endif
*addrlen = sizeof (struct sockaddr_in6); *addrlen = sizeof (struct sockaddr_in6);
#if defined(WIN32) || defined(UNDER_CE)
if( WSAStringToAddressA(host, AF_INET6, NULL,
(LPSOCKADDR)addr, addrlen) )
return -1;
#else
if (inet_pton (AF_INET6, host, if (inet_pton (AF_INET6, host,
&((struct sockaddr_in6 *)addr)->sin6_addr) <= 0) &((struct sockaddr_in6 *)addr)->sin6_addr) <= 0)
return -1; return -1;
#endif
*number = (res >= 3) ? n1 : 1; *number = (res >= 3) ? n1 : 1;
break; break;
#endif #endif
...@@ -964,9 +969,15 @@ static int ParseSDPConnection (const char *str, struct sockaddr_storage *addr, ...@@ -964,9 +969,15 @@ static int ParseSDPConnection (const char *str, struct sockaddr_storage *addr,
# endif # endif
*addrlen = sizeof (struct sockaddr_in); *addrlen = sizeof (struct sockaddr_in);
#if defined(WIN32) || defined(UNDER_CE)
if( WSAStringToAddressA(host, AF_INET, NULL,
(LPSOCKADDR)addr, addrlen) )
return -1;
#else
if (inet_pton (AF_INET, host, if (inet_pton (AF_INET, host,
&((struct sockaddr_in *)addr)->sin_addr) <= 0) &((struct sockaddr_in *)addr)->sin_addr) <= 0)
return -1; return -1;
#endif
*number = (res >= 4) ? n2 : 1; *number = (res >= 4) ? n2 : 1;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment