Improve ssdp part

Do not compile CreateClientRequestPacketUlaGua if IPv6 is disable.
Cast DestAddr->sa_family from sa_family_t into int when calling
CreateServicePacket as this function has been set back to accept int in
a692e591defe6ed9a617b9b4a083964a01f7bbab.
Use switch instead of if with AF_INET and AF_INET6.
Add missing casts from AF_INET and AF_INET6 into sa_family_t when using
them to set sin_family and sin6_family.
Add missing explicit casts into size_t or lu when using integer
constants with strlen or unsigned long indexes.
Set SSDP_PAUSE to be unsigned as it is used with usleep.
This commit is contained in:
Fabrice Fontaine 2012-03-14 20:35:34 +01:00
parent d48d73720b
commit 850e6b4849
5 changed files with 100 additions and 57 deletions

View File

@ -2,6 +2,21 @@
Version 1.6.16 Version 1.6.16
******************************************************************************* *******************************************************************************
2012-03-14 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Improve ssdp part
Do not compile CreateClientRequestPacketUlaGua if IPv6 is disable.
Cast DestAddr->sa_family from sa_family_t into int when calling
CreateServicePacket as this function has been set back to accept int in
a692e591defe6ed9a617b9b4a083964a01f7bbab.
Use switch instead of if with AF_INET and AF_INET6.
Add missing casts from AF_INET and AF_INET6 into sa_family_t when using
them to set sin_family and sin6_family.
Add missing explicit casts into size_t or lu when using integer
constants with strlen or unsigned long indexes.
Set SSDP_PAUSE to be unsigned as it is used with usleep.
2012-03-14 Fabrice Fontaine <fabrice.fontaine(at)orange.com> 2012-03-14 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Use switch insted of if with enums in ixml Use switch insted of if with enums in ixml

View File

@ -179,7 +179,7 @@
* *
* @{ * @{
*/ */
#define SSDP_PAUSE 100 #define SSDP_PAUSE 100u
/* @} */ /* @} */
/*! /*!

View File

@ -330,13 +330,16 @@ static int CreateClientRequestPacket(
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
strcpy(RqstBuf, command); strcpy(RqstBuf, command);
if (AddressFamily == AF_INET) { switch (AddressFamily) {
case AF_INET:
rc = snprintf(TempBuf, sizeof(TempBuf), "HOST: %s:%d\r\n", SSDP_IP, rc = snprintf(TempBuf, sizeof(TempBuf), "HOST: %s:%d\r\n", SSDP_IP,
SSDP_PORT); SSDP_PORT);
} else if (AddressFamily == AF_INET6) { break;
case AF_INET6:
rc = snprintf(TempBuf, sizeof(TempBuf), "HOST: [%s]:%d\r\n", rc = snprintf(TempBuf, sizeof(TempBuf), "HOST: [%s]:%d\r\n",
SSDP_IPV6_LINKLOCAL, SSDP_PORT); SSDP_IPV6_LINKLOCAL, SSDP_PORT);
} else { break;
default:
return UPNP_E_INVALID_ARGUMENT; return UPNP_E_INVALID_ARGUMENT;
} }
if (rc < 0 || (unsigned int) rc >= sizeof(TempBuf)) if (rc < 0 || (unsigned int) rc >= sizeof(TempBuf))
@ -377,6 +380,7 @@ static int CreateClientRequestPacket(
/*! /*!
* \brief * \brief
*/ */
#ifdef UPNP_ENABLE_IPV6
static int CreateClientRequestPacketUlaGua( static int CreateClientRequestPacketUlaGua(
/*! [in,out] . */ /*! [in,out] . */
char *RqstBuf, char *RqstBuf,
@ -398,13 +402,16 @@ static int CreateClientRequestPacketUlaGua(
if (RqstBufSize <= strlen(command)) if (RqstBufSize <= strlen(command))
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
strcpy(RqstBuf, command); strcpy(RqstBuf, command);
if (AddressFamily == AF_INET) { switch (AddressFamily) {
case AF_INET:
rc = snprintf(TempBuf, sizeof(TempBuf), "HOST: %s:%d\r\n", SSDP_IP, rc = snprintf(TempBuf, sizeof(TempBuf), "HOST: %s:%d\r\n", SSDP_IP,
SSDP_PORT); SSDP_PORT);
} else if (AddressFamily == AF_INET6) { break;
case AF_INET6:
rc = snprintf(TempBuf, sizeof(TempBuf), "HOST: [%s]:%d\r\n", rc = snprintf(TempBuf, sizeof(TempBuf), "HOST: [%s]:%d\r\n",
SSDP_IPV6_SITELOCAL, SSDP_PORT); SSDP_IPV6_SITELOCAL, SSDP_PORT);
} else { break;
default:
return UPNP_E_INVALID_ARGUMENT; return UPNP_E_INVALID_ARGUMENT;
} }
if (rc < 0 || (unsigned int) rc >= sizeof(TempBuf)) if (rc < 0 || (unsigned int) rc >= sizeof(TempBuf))
@ -440,6 +447,7 @@ static int CreateClientRequestPacketUlaGua(
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
#endif /* UPNP_ENABLE_IPV6 */
/*! /*!
* \brief * \brief
@ -547,13 +555,13 @@ int SearchByTarget(int Mx, char *St, void *Cookie)
#endif #endif
memset(&__ss_v4, 0, sizeof(__ss_v4)); memset(&__ss_v4, 0, sizeof(__ss_v4));
destAddr4->sin_family = AF_INET; destAddr4->sin_family = (sa_family_t)AF_INET;
inet_pton(AF_INET, SSDP_IP, &destAddr4->sin_addr); inet_pton(AF_INET, SSDP_IP, &destAddr4->sin_addr);
destAddr4->sin_port = htons(SSDP_PORT); destAddr4->sin_port = htons(SSDP_PORT);
#ifdef UPNP_ENABLE_IPV6 #ifdef UPNP_ENABLE_IPV6
memset(&__ss_v6, 0, sizeof(__ss_v6)); memset(&__ss_v6, 0, sizeof(__ss_v6));
destAddr6->sin6_family = AF_INET6; destAddr6->sin6_family = (sa_family_t)AF_INET6;
inet_pton(AF_INET6, SSDP_IPV6_SITELOCAL, &destAddr6->sin6_addr); inet_pton(AF_INET6, SSDP_IPV6_SITELOCAL, &destAddr6->sin6_addr);
destAddr6->sin6_port = htons(SSDP_PORT); destAddr6->sin6_port = htons(SSDP_PORT);
destAddr6->sin6_scope_id = gIF_INDEX; destAddr6->sin6_scope_id = gIF_INDEX;

View File

@ -197,7 +197,8 @@ static int NewRequestHandler(
return UPNP_E_OUTOF_SOCKET; return UPNP_E_OUTOF_SOCKET;
} }
if (DestAddr->sa_family == AF_INET) { switch (DestAddr->sa_family) {
case AF_INET:
inet_ntop(AF_INET, &((struct sockaddr_in *)DestAddr)->sin_addr, inet_ntop(AF_INET, &((struct sockaddr_in *)DestAddr)->sin_addr,
buf_ntop, sizeof(buf_ntop)); buf_ntop, sizeof(buf_ntop));
setsockopt(ReplySock, IPPROTO_IP, IP_MULTICAST_IF, setsockopt(ReplySock, IPPROTO_IP, IP_MULTICAST_IF,
@ -205,7 +206,8 @@ static int NewRequestHandler(
setsockopt(ReplySock, IPPROTO_IP, IP_MULTICAST_TTL, setsockopt(ReplySock, IPPROTO_IP, IP_MULTICAST_TTL,
(char *)&ttl, sizeof(int)); (char *)&ttl, sizeof(int));
socklen = sizeof(struct sockaddr_in); socklen = sizeof(struct sockaddr_in);
} else if (DestAddr->sa_family == AF_INET6) { break;
case AF_INET6:
inet_ntop(AF_INET6, inet_ntop(AF_INET6,
&((struct sockaddr_in6 *)DestAddr)->sin6_addr, &((struct sockaddr_in6 *)DestAddr)->sin6_addr,
buf_ntop, sizeof(buf_ntop)); buf_ntop, sizeof(buf_ntop));
@ -213,7 +215,8 @@ static int NewRequestHandler(
(char *)&gIF_INDEX, sizeof(gIF_INDEX)); (char *)&gIF_INDEX, sizeof(gIF_INDEX));
setsockopt(ReplySock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, setsockopt(ReplySock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
(char *)&hops, sizeof(hops)); (char *)&hops, sizeof(hops));
} else { break;
default:
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Invalid destination address specified."); "Invalid destination address specified.");
ret = UPNP_E_NETWORK_ERROR; ret = UPNP_E_NETWORK_ERROR;
@ -380,9 +383,11 @@ static void CreateServicePacket(
nts = "ssdp:byebye"; nts = "ssdp:byebye";
/* NOTE: The CACHE-CONTROL and LOCATION headers are not present in /* NOTE: The CACHE-CONTROL and LOCATION headers are not present in
* a shutdown msg, but are present here for MS WinMe interop. */ * a shutdown msg, but are present here for MS WinMe interop. */
if (AddressFamily == AF_INET) switch (AddressFamily) {
case AF_INET:
host = SSDP_IP; host = SSDP_IP;
else { break;
default:
if (isUrlV6UlaGua(location)) if (isUrlV6UlaGua(location))
host = "[" SSDP_IPV6_SITELOCAL "]"; host = "[" SSDP_IPV6_SITELOCAL "]";
else else
@ -445,18 +450,21 @@ int DeviceAdvertisement(char *DevType, int RootDev, char *Udn, char *Location,
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"In function DeviceAdvertisement\n"); "In function DeviceAdvertisement\n");
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
if (AddressFamily == AF_INET) { switch (AddressFamily) {
DestAddr4->sin_family = (unsigned short)AF_INET; case AF_INET:
DestAddr4->sin_family = (sa_family_t)AF_INET;
inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr);
DestAddr4->sin_port = htons(SSDP_PORT); DestAddr4->sin_port = htons(SSDP_PORT);
} else if (AddressFamily == AF_INET6) { break;
DestAddr6->sin6_family = (unsigned short)AF_INET6; case AF_INET6:
DestAddr6->sin6_family = (sa_family_t)AF_INET6;
inet_pton(AF_INET6, inet_pton(AF_INET6,
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
DestAddr6->sin6_port = htons(SSDP_PORT); DestAddr6->sin6_port = htons(SSDP_PORT);
DestAddr6->sin6_scope_id = gIF_INDEX; DestAddr6->sin6_scope_id = gIF_INDEX;
} else { break;
default:
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Invalid device address family.\n"); "Invalid device address family.\n");
} }
@ -533,7 +541,7 @@ int SendReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
goto error_handler; goto error_handler;
CreateServicePacket(MSGTYPE_REPLY, "upnp:rootdevice", CreateServicePacket(MSGTYPE_REPLY, "upnp:rootdevice",
Mil_Usn, Location, Duration, &msgs[0], Mil_Usn, Location, Duration, &msgs[0],
DestAddr->sa_family, PowerState, (int)DestAddr->sa_family, PowerState,
SleepPeriod, RegistrationState); SleepPeriod, RegistrationState);
} else { } else {
/* two msgs for embedded devices */ /* two msgs for embedded devices */
@ -543,7 +551,7 @@ int SendReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
if (!ByType) { if (!ByType) {
CreateServicePacket(MSGTYPE_REPLY, Udn, Udn, Location, CreateServicePacket(MSGTYPE_REPLY, Udn, Udn, Location,
Duration, &msgs[0], Duration, &msgs[0],
DestAddr->sa_family, PowerState, (int)DestAddr->sa_family, PowerState,
SleepPeriod, RegistrationState); SleepPeriod, RegistrationState);
} else { } else {
rc = snprintf(Mil_Usn, sizeof(Mil_Usn), "%s::%s", Udn, rc = snprintf(Mil_Usn, sizeof(Mil_Usn), "%s::%s", Udn,
@ -552,7 +560,7 @@ int SendReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
goto error_handler; goto error_handler;
CreateServicePacket(MSGTYPE_REPLY, DevType, Mil_Usn, CreateServicePacket(MSGTYPE_REPLY, DevType, Mil_Usn,
Location, Duration, &msgs[0], Location, Duration, &msgs[0],
DestAddr->sa_family, PowerState, (int)DestAddr->sa_family, PowerState,
SleepPeriod, RegistrationState); SleepPeriod, RegistrationState);
} }
} }
@ -595,7 +603,7 @@ int DeviceReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
goto error_handler; goto error_handler;
CreateServicePacket(MSGTYPE_REPLY, Mil_Nt, Mil_Usn, CreateServicePacket(MSGTYPE_REPLY, Mil_Nt, Mil_Usn,
Location, Duration, &szReq[0], Location, Duration, &szReq[0],
DestAddr->sa_family, PowerState, (int)DestAddr->sa_family, PowerState,
SleepPeriod, RegistrationState); SleepPeriod, RegistrationState);
} }
rc = snprintf(Mil_Nt, sizeof(Mil_Nt), "%s", Udn); rc = snprintf(Mil_Nt, sizeof(Mil_Nt), "%s", Udn);
@ -605,7 +613,7 @@ int DeviceReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn)) if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn))
goto error_handler; goto error_handler;
CreateServicePacket(MSGTYPE_REPLY, Mil_Nt, Mil_Usn, CreateServicePacket(MSGTYPE_REPLY, Mil_Nt, Mil_Usn,
Location, Duration, &szReq[1], DestAddr->sa_family, Location, Duration, &szReq[1], (int)DestAddr->sa_family,
PowerState, SleepPeriod, RegistrationState); PowerState, SleepPeriod, RegistrationState);
rc = snprintf(Mil_Nt, sizeof(Mil_Nt), "%s", DevType); rc = snprintf(Mil_Nt, sizeof(Mil_Nt), "%s", DevType);
if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Nt)) if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Nt))
@ -614,7 +622,7 @@ int DeviceReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn)) if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn))
goto error_handler; goto error_handler;
CreateServicePacket(MSGTYPE_REPLY, Mil_Nt, Mil_Usn, CreateServicePacket(MSGTYPE_REPLY, Mil_Nt, Mil_Usn,
Location, Duration, &szReq[2], DestAddr->sa_family, Location, Duration, &szReq[2], (int)DestAddr->sa_family,
PowerState, SleepPeriod, RegistrationState); PowerState, SleepPeriod, RegistrationState);
/* check error */ /* check error */
if ((RootDev && szReq[0] == NULL) || if ((RootDev && szReq[0] == NULL) ||
@ -651,18 +659,21 @@ int ServiceAdvertisement(char *Udn, char *ServType, char *Location,
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
szReq[0] = NULL; szReq[0] = NULL;
if (AddressFamily == AF_INET) { switch (AddressFamily) {
case AF_INET:
DestAddr4->sin_family = (sa_family_t)AddressFamily; DestAddr4->sin_family = (sa_family_t)AddressFamily;
inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr);
DestAddr4->sin_port = htons(SSDP_PORT); DestAddr4->sin_port = htons(SSDP_PORT);
} else if (AddressFamily == AF_INET6) { break;
case AF_INET6:
DestAddr6->sin6_family = (sa_family_t)AddressFamily; DestAddr6->sin6_family = (sa_family_t)AddressFamily;
inet_pton(AF_INET6, inet_pton(AF_INET6,
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
DestAddr6->sin6_port = htons(SSDP_PORT); DestAddr6->sin6_port = htons(SSDP_PORT);
DestAddr6->sin6_scope_id = gIF_INDEX; DestAddr6->sin6_scope_id = gIF_INDEX;
} else { break;
default:
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Invalid device address family.\n"); "Invalid device address family.\n");
} }
@ -699,7 +710,7 @@ int ServiceReply(struct sockaddr *DestAddr, char *ServType, char *Udn,
if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn)) if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn))
goto error_handler; goto error_handler;
CreateServicePacket(MSGTYPE_REPLY, ServType, Mil_Usn, CreateServicePacket(MSGTYPE_REPLY, ServType, Mil_Usn,
Location, Duration, &szReq[0], DestAddr->sa_family, Location, Duration, &szReq[0], (int)DestAddr->sa_family,
PowerState, SleepPeriod, RegistrationState); PowerState, SleepPeriod, RegistrationState);
if (szReq[0] == NULL) if (szReq[0] == NULL)
goto error_handler; goto error_handler;
@ -725,18 +736,21 @@ int ServiceShutdown(char *Udn, char *ServType, char *Location, int Duration,
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
szReq[0] = NULL; szReq[0] = NULL;
if (AddressFamily == AF_INET) { switch (AddressFamily) {
case AF_INET:
DestAddr4->sin_family = (sa_family_t)AddressFamily; DestAddr4->sin_family = (sa_family_t)AddressFamily;
inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr);
DestAddr4->sin_port = htons(SSDP_PORT); DestAddr4->sin_port = htons(SSDP_PORT);
} else if (AddressFamily == AF_INET6) { break;
case AF_INET6:
DestAddr6->sin6_family = (sa_family_t)AddressFamily; DestAddr6->sin6_family = (sa_family_t)AddressFamily;
inet_pton(AF_INET6, inet_pton(AF_INET6,
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
DestAddr6->sin6_port = htons(SSDP_PORT); DestAddr6->sin6_port = htons(SSDP_PORT);
DestAddr6->sin6_scope_id = gIF_INDEX; DestAddr6->sin6_scope_id = gIF_INDEX;
} else { break;
default:
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Invalid device address family.\n"); "Invalid device address family.\n");
} }
@ -775,18 +789,21 @@ int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *_Server,
msgs[1] = NULL; msgs[1] = NULL;
msgs[2] = NULL; msgs[2] = NULL;
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
if (AddressFamily == AF_INET) { switch (AddressFamily) {
case AF_INET:
DestAddr4->sin_family = (sa_family_t)AddressFamily; DestAddr4->sin_family = (sa_family_t)AddressFamily;
inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr);
DestAddr4->sin_port = htons(SSDP_PORT); DestAddr4->sin_port = htons(SSDP_PORT);
} else if (AddressFamily == AF_INET6) { break;
case AF_INET6:
DestAddr6->sin6_family = (sa_family_t)AddressFamily; DestAddr6->sin6_family = (sa_family_t)AddressFamily;
inet_pton(AF_INET6, inet_pton(AF_INET6,
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
DestAddr6->sin6_port = htons(SSDP_PORT); DestAddr6->sin6_port = htons(SSDP_PORT);
DestAddr6->sin6_scope_id = gIF_INDEX; DestAddr6->sin6_scope_id = gIF_INDEX;
} else { break;
default:
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Invalid device address family.\n"); "Invalid device address family.\n");
} }

View File

@ -133,7 +133,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
if (NumCopy != 0) if (NumCopy != 0)
imillisleep(SSDP_PAUSE); imillisleep(SSDP_PAUSE);
NumCopy++; NumCopy++;
for (i = 0;; i++) { for (i = 0lu;; i++) {
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Entering new device list with i = %lu\n\n", "Entering new device list with i = %lu\n\n",
i); i);
@ -156,7 +156,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
"Extracting UDN for %s\n", dbgStr); "Extracting UDN for %s\n", dbgStr);
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Extracting device type\n"); "Extracting device type\n");
tmpNode2 = ixmlNodeList_item(nodeList, 0); tmpNode2 = ixmlNodeList_item(nodeList, 0lu);
if (!tmpNode2) if (!tmpNode2)
continue; continue;
textNode = ixmlNode_getFirstChild(tmpNode2); textNode = ixmlNode_getFirstChild(tmpNode2);
@ -184,7 +184,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
__LINE__, "UDN not found!\n"); __LINE__, "UDN not found!\n");
continue; continue;
} }
tmpNode2 = ixmlNodeList_item(nodeList, 0); tmpNode2 = ixmlNodeList_item(nodeList, 0lu);
if (!tmpNode2) { if (!tmpNode2) {
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, UpnpPrintf(UPNP_CRITICAL, API, __FILE__,
__LINE__, "UDN not found!\n"); __LINE__, "UDN not found!\n");
@ -208,7 +208,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
if (AdFlag) { if (AdFlag) {
/* send the device advertisement */ /* send the device advertisement */
if (AdFlag == 1) { if (AdFlag == 1) {
DeviceAdvertisement(devType, i == 0, DeviceAdvertisement(devType, i == 0lu,
UDNstr, UDNstr,
SInfo->DescURL, Exp, SInfo->DescURL, Exp,
SInfo->DeviceAf, SInfo->DeviceAf,
@ -217,7 +217,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
SInfo->RegistrationState); SInfo->RegistrationState);
} else { } else {
/* AdFlag == -1 */ /* AdFlag == -1 */
DeviceShutdown(devType, i == 0, UDNstr, DeviceShutdown(devType, i == 0lu, UDNstr,
SERVER, SInfo->DescURL, SERVER, SInfo->DescURL,
Exp, SInfo->DeviceAf, Exp, SInfo->DeviceAf,
SInfo->PowerState, SInfo->PowerState,
@ -227,14 +227,14 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
} else { } else {
switch (SearchType) { switch (SearchType) {
case SSDP_ALL: case SSDP_ALL:
DeviceReply(DestAddr, devType, i == 0, DeviceReply(DestAddr, devType, i == 0lu,
UDNstr, SInfo->DescURL, UDNstr, SInfo->DescURL,
defaultExp, SInfo->PowerState, defaultExp, SInfo->PowerState,
SInfo->SleepPeriod, SInfo->SleepPeriod,
SInfo->RegistrationState); SInfo->RegistrationState);
break; break;
case SSDP_ROOTDEVICE: case SSDP_ROOTDEVICE:
if (i == 0) { if (i == 0lu) {
SendReply(DestAddr, devType, 1, SendReply(DestAddr, devType, 1,
UDNstr, UDNstr,
SInfo->DescURL, SInfo->DescURL,
@ -245,7 +245,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
} }
break; break;
case SSDP_DEVICEUDN: { case SSDP_DEVICEUDN: {
if (DeviceUDN && strlen(DeviceUDN) != 0) { if (DeviceUDN && strlen(DeviceUDN) != (size_t)0) {
if (strcasecmp(DeviceUDN, UDNstr)) { if (strcasecmp(DeviceUDN, UDNstr)) {
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"DeviceUDN=%s and search UDN=%s DID NOT match\n", "DeviceUDN=%s and search UDN=%s DID NOT match\n",
@ -264,9 +264,9 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
} }
} }
case SSDP_DEVICETYPE: { case SSDP_DEVICETYPE: {
if (!strncasecmp(DeviceType, devType, strlen(DeviceType) - 2)) { if (!strncasecmp(DeviceType, devType, strlen(DeviceType) - (size_t)2)) {
if (atoi(strrchr(DeviceType, ':') + 1) if (atoi(strrchr(DeviceType, ':') + 1)
< atoi(&devType[strlen(devType) - 1])) { < atoi(&devType[strlen(devType) - (size_t)1])) {
/* the requested version is lower than the device version /* the requested version is lower than the device version
* must reply with the lower version number and the lower * must reply with the lower version number and the lower
* description URL */ * description URL */
@ -279,7 +279,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
SInfo->SleepPeriod, SInfo->SleepPeriod,
SInfo->RegistrationState); SInfo->RegistrationState);
} else if (atoi(strrchr(DeviceType, ':') + 1) } else if (atoi(strrchr(DeviceType, ':') + 1)
== atoi(&devType[strlen(devType) - 1])) { == atoi(&devType[strlen(devType) - (size_t)1])) {
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"DeviceType=%s and search devType=%s MATCH\n", "DeviceType=%s and search devType=%s MATCH\n",
devType, DeviceType); devType, DeviceType);
@ -333,7 +333,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
"Service not found 3\n"); "Service not found 3\n");
continue; continue;
} }
for (j = 0;; j++) { for (j = 0lu;; j++) {
tmpNode = ixmlNodeList_item(nodeList, j); tmpNode = ixmlNodeList_item(nodeList, j);
if (!tmpNode) { if (!tmpNode) {
break; break;
@ -389,9 +389,9 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
break; break;
case SSDP_SERVICE: case SSDP_SERVICE:
if (ServiceType) { if (ServiceType) {
if (!strncasecmp(ServiceType, servType, strlen(ServiceType) - 2)) { if (!strncasecmp(ServiceType, servType, strlen(ServiceType) - (size_t)2)) {
if (atoi(strrchr(ServiceType, ':') + 1) < if (atoi(strrchr(ServiceType, ':') + 1) <
atoi(&servType[strlen(servType) - 1])) { atoi(&servType[strlen(servType) - (size_t)1])) {
/* the requested version is lower than the service version /* the requested version is lower than the service version
* must reply with the lower version number and the lower * must reply with the lower version number and the lower
* description URL */ * description URL */
@ -739,17 +739,20 @@ void readFromSSDPSocket(SOCKET socket)
(struct sockaddr *)&__ss, &socklen); (struct sockaddr *)&__ss, &socklen);
if (byteReceived > 0) { if (byteReceived > 0) {
requestBuf[byteReceived] = '\0'; requestBuf[byteReceived] = '\0';
if (__ss.ss_family == AF_INET) switch (__ss.ss_family) {
case AF_INET:
inet_ntop(AF_INET, inet_ntop(AF_INET,
&((struct sockaddr_in *)&__ss)->sin_addr, &((struct sockaddr_in *)&__ss)->sin_addr,
ntop_buf, sizeof(ntop_buf)); ntop_buf, sizeof(ntop_buf));
break;
#ifdef UPNP_ENABLE_IPV6 #ifdef UPNP_ENABLE_IPV6
else if (__ss.ss_family == AF_INET6) case AF_INET6:
inet_ntop(AF_INET6, inet_ntop(AF_INET6,
&((struct sockaddr_in6 *)&__ss)->sin6_addr, &((struct sockaddr_in6 *)&__ss)->sin6_addr,
ntop_buf, sizeof(ntop_buf)); ntop_buf, sizeof(ntop_buf));
break;
#endif /* UPNP_ENABLE_IPV6 */ #endif /* UPNP_ENABLE_IPV6 */
else { default:
memset(ntop_buf, 0, sizeof(ntop_buf)); memset(ntop_buf, 0, sizeof(ntop_buf));
strncpy(ntop_buf, "<Invalid address family>", strncpy(ntop_buf, "<Invalid address family>",
sizeof(ntop_buf) - 1); sizeof(ntop_buf) - 1);
@ -830,7 +833,7 @@ static int create_ssdp_sock_v4(
} }
#endif /* BSD, __OSX__, __APPLE__ */ #endif /* BSD, __OSX__, __APPLE__ */
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
ssdpAddr4->sin_family = (unsigned short)AF_INET; ssdpAddr4->sin_family = (sa_family_t)AF_INET;
ssdpAddr4->sin_addr.s_addr = htonl(INADDR_ANY); ssdpAddr4->sin_addr.s_addr = htonl(INADDR_ANY);
ssdpAddr4->sin_port = htons(SSDP_PORT); ssdpAddr4->sin_port = htons(SSDP_PORT);
ret = bind(*ssdpSock, (struct sockaddr *)ssdpAddr4, sizeof(*ssdpAddr4)); ret = bind(*ssdpSock, (struct sockaddr *)ssdpAddr4, sizeof(*ssdpAddr4));
@ -984,7 +987,7 @@ static int create_ssdp_sock_v6(
return UPNP_E_SOCKET_ERROR; return UPNP_E_SOCKET_ERROR;
} }
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
ssdpAddr6->sin6_family = AF_INET6; ssdpAddr6->sin6_family = (sa_family_t)AF_INET6;
ssdpAddr6->sin6_addr = in6addr_any; ssdpAddr6->sin6_addr = in6addr_any;
ssdpAddr6->sin6_scope_id = gIF_INDEX; ssdpAddr6->sin6_scope_id = gIF_INDEX;
ssdpAddr6->sin6_port = htons(SSDP_PORT); ssdpAddr6->sin6_port = htons(SSDP_PORT);
@ -1098,7 +1101,7 @@ static int create_ssdp_sock_v6_ula_gua(
return UPNP_E_SOCKET_ERROR; return UPNP_E_SOCKET_ERROR;
} }
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
ssdpAddr6->sin6_family = AF_INET6; ssdpAddr6->sin6_family = (sa_family_t)AF_INET6;
ssdpAddr6->sin6_addr = in6addr_any; ssdpAddr6->sin6_addr = in6addr_any;
ssdpAddr6->sin6_scope_id = gIF_INDEX; ssdpAddr6->sin6_scope_id = gIF_INDEX;
ssdpAddr6->sin6_port = htons(SSDP_PORT); ssdpAddr6->sin6_port = htons(SSDP_PORT);
@ -1187,7 +1190,7 @@ int get_ssdp_sockets(MiniServerSockArray * out)
out->ssdpReqSock4 = INVALID_SOCKET; out->ssdpReqSock4 = INVALID_SOCKET;
out->ssdpReqSock6 = INVALID_SOCKET; out->ssdpReqSock6 = INVALID_SOCKET;
/* Create the IPv4 socket for SSDP REQUESTS */ /* Create the IPv4 socket for SSDP REQUESTS */
if (strlen(gIF_IPV4) > 0) { if (strlen(gIF_IPV4) > (size_t)0) {
retVal = create_ssdp_sock_reqv4(&out->ssdpReqSock4); retVal = create_ssdp_sock_reqv4(&out->ssdpReqSock4);
if (retVal != UPNP_E_SUCCESS) if (retVal != UPNP_E_SUCCESS)
return retVal; return retVal;
@ -1197,7 +1200,7 @@ int get_ssdp_sockets(MiniServerSockArray * out)
out->ssdpReqSock4 = INVALID_SOCKET; out->ssdpReqSock4 = INVALID_SOCKET;
/* Create the IPv6 socket for SSDP REQUESTS */ /* Create the IPv6 socket for SSDP REQUESTS */
#ifdef UPNP_ENABLE_IPV6 #ifdef UPNP_ENABLE_IPV6
if (strlen(gIF_IPV6) > 0) { if (strlen(gIF_IPV6) > (size_t)0) {
retVal = create_ssdp_sock_reqv6(&out->ssdpReqSock6); retVal = create_ssdp_sock_reqv6(&out->ssdpReqSock6);
if (retVal != UPNP_E_SUCCESS) { if (retVal != UPNP_E_SUCCESS) {
shutdown(out->ssdpReqSock4, SD_BOTH); shutdown(out->ssdpReqSock4, SD_BOTH);