Fix for regression in SSDP code to send/receive messages over UDP
Sending messages over UDP is broken in some Apple OSes such as OS X and iOS. This might be broken in other OSes to but didn't verify. The fix is to modify the socket lenght argument of sendto to use the correct sockaddr lenght dependng on whether the socket is IPV4 or IPV6. Also added some error checks and debugging related to the issue
This commit is contained in:
parent
4657e57766
commit
2b3ab1799b
12
ChangeLog
12
ChangeLog
@ -2,6 +2,18 @@
|
||||
Version 1.6.7
|
||||
*******************************************************************************
|
||||
|
||||
2010-09-09 Chandra Penke <chandrapenke(at)mcntech.com>
|
||||
Fix for regression in SSDP code to send/receive messages over UDP
|
||||
|
||||
Sending messages over UDP is broken in some Apple OSes
|
||||
such as OS X and iOS. This might be broken in other OSes to but didn't
|
||||
verify.
|
||||
|
||||
The fix is to modify the socket lenght argument of sendto to use the correct
|
||||
sockaddr lenght dependng on whether the socket is IPV4 or IPV6.
|
||||
|
||||
Also added some error checks and debugging related to the issue
|
||||
|
||||
2010-09-07 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||
Using UpnpReadHttpGet to download large files causes the application to
|
||||
crash. This happens when the file being downloaded exceeds the device
|
||||
|
@ -510,7 +510,6 @@ int SearchByTarget(
|
||||
IN void *Cookie)
|
||||
{
|
||||
char errorBuffer[ERROR_BUFFER_LEN];
|
||||
int socklen = sizeof( struct sockaddr_storage );
|
||||
int *id = NULL;
|
||||
int ret = 0;
|
||||
char ReqBufv4[BUFSIZE];
|
||||
@ -622,16 +621,21 @@ int SearchByTarget(
|
||||
while (NumCopy < NUM_SSDP_COPY) {
|
||||
sendto(gSsdpReqSocket6,
|
||||
ReqBufv6UlaGua, strlen(ReqBufv6UlaGua), 0,
|
||||
(struct sockaddr *)&__ss_v6, socklen);
|
||||
(struct sockaddr *)&__ss_v6,
|
||||
sizeof(struct sockaddr_in));
|
||||
NumCopy++;
|
||||
imillisleep(SSDP_PAUSE);
|
||||
}
|
||||
NumCopy = 0;
|
||||
inet_pton(AF_INET6, SSDP_IPV6_LINKLOCAL, &destAddr6->sin6_addr);
|
||||
while (NumCopy < NUM_SSDP_COPY) {
|
||||
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
|
||||
">>> SSDP SEND M-SEARCH >>>\n%s\n",
|
||||
*ReqBufv6 );
|
||||
sendto(gSsdpReqSocket6,
|
||||
ReqBufv6, strlen(ReqBufv6), 0,
|
||||
(struct sockaddr *)&__ss_v6, socklen);
|
||||
ReqBufv6, strlen(ReqBufv6), 0,
|
||||
(struct sockaddr *)&__ss_v6,
|
||||
sizeof(struct sockaddr_in6));
|
||||
NumCopy++;
|
||||
imillisleep(SSDP_PAUSE);
|
||||
}
|
||||
@ -639,11 +643,14 @@ int SearchByTarget(
|
||||
if (gSsdpReqSocket4 != INVALID_SOCKET &&
|
||||
FD_ISSET(gSsdpReqSocket4, &wrSet)) {
|
||||
int NumCopy = 0;
|
||||
|
||||
while (NumCopy < NUM_SSDP_COPY) {
|
||||
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
|
||||
">>> SSDP SEND M-SEARCH >>>\n%s\n",
|
||||
ReqBufv4);
|
||||
sendto(gSsdpReqSocket4,
|
||||
ReqBufv4, strlen(ReqBufv4), 0,
|
||||
(struct sockaddr *)&__ss_v4, socklen);
|
||||
(struct sockaddr *)&__ss_v4,
|
||||
sizeof(struct sockaddr_in));
|
||||
NumCopy++;
|
||||
imillisleep(SSDP_PAUSE);
|
||||
}
|
||||
|
@ -229,6 +229,7 @@ NewRequestHandler( IN struct sockaddr *DestAddr,
|
||||
int ttl = 4; // a/c to UPNP Spec
|
||||
int hops = 1;
|
||||
char buf_ntop[64];
|
||||
int ret = UPNP_E_SUCCESS;
|
||||
|
||||
ReplySock = socket( DestAddr->sa_family, SOCK_DGRAM, 0 );
|
||||
if ( ReplySock == -1 ) {
|
||||
@ -247,6 +248,7 @@ NewRequestHandler( IN struct sockaddr *DestAddr,
|
||||
(char *)&replyAddr, sizeof (replyAddr) );
|
||||
setsockopt( ReplySock, IPPROTO_IP, IP_MULTICAST_TTL,
|
||||
(char *)&ttl, sizeof (int) );
|
||||
socklen = sizeof(struct sockaddr_in);
|
||||
} else if( DestAddr->sa_family == AF_INET6 ) {
|
||||
inet_ntop(AF_INET6, &((struct sockaddr_in6*)DestAddr)->sin6_addr,
|
||||
buf_ntop, sizeof(buf_ntop));
|
||||
@ -257,6 +259,8 @@ NewRequestHandler( IN struct sockaddr *DestAddr,
|
||||
} else {
|
||||
UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
|
||||
"Invalid destination address specified." );
|
||||
ret = UPNP_E_NETWORK_ERROR;
|
||||
goto end_NewRequestHandler;
|
||||
}
|
||||
|
||||
for( Index = 0; Index < NumPacket; Index++ ) {
|
||||
@ -280,15 +284,27 @@ NewRequestHandler( IN struct sockaddr *DestAddr,
|
||||
rc = sendto( ReplySock, *( RqPacket + Index ),
|
||||
strlen( *( RqPacket + Index ) ),
|
||||
0, DestAddr, socklen );
|
||||
|
||||
if (rc == -1) {
|
||||
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
|
||||
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
|
||||
"SSDP_LIB: New Request Handler:"
|
||||
"Error in socket(): %s\n", errorBuffer );
|
||||
ret = UPNP_E_SOCKET_WRITE;
|
||||
goto end_NewRequestHandler;
|
||||
}
|
||||
|
||||
imillisleep( SSDP_PAUSE );
|
||||
|
||||
++NumCopy;
|
||||
}
|
||||
}
|
||||
|
||||
end_NewRequestHandler:
|
||||
shutdown( ReplySock, SD_BOTH );
|
||||
UpnpCloseSocket( ReplySock );
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user