From 7392697aec737c7835e2a87b54902a795eedc14a Mon Sep 17 00:00:00 2001 From: Iain Denniston Date: Fri, 18 Mar 2011 12:09:33 +0000 Subject: [PATCH] Several fixes to correctly use SOCKET (and related) types instead of non-portable variations. (cherry picked from commit fed316ff3e5aeca34f825a60796a1eac05b8e43a) --- ChangeLog | 4 ++++ upnp/src/api/upnpapi.c | 4 ++-- upnp/src/genlib/net/http/httpreadwrite.c | 14 +++++++------- upnp/src/genlib/net/sock.c | 4 ++-- upnp/src/inc/sock.h | 2 +- upnp/src/ssdp/ssdp_ctrlpt.c | 2 +- upnp/src/ssdp/ssdp_device.c | 2 +- upnp/src/ssdp/ssdp_server.c | 10 +++++----- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index a76d9b2..71cf6fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -255,6 +255,10 @@ Version 1.8.0 Version 1.6.14 ******************************************************************************* +2011-03-08 Iain Denniston + + Several fixes to correctly use SOCKET (and related) types instead of + non-portable variations. ******************************************************************************* Version 1.6.13 diff --git a/upnp/src/api/upnpapi.c b/upnp/src/api/upnpapi.c index 85e844a..9fa067f 100644 --- a/upnp/src/api/upnpapi.c +++ b/upnp/src/api/upnpapi.c @@ -3242,7 +3242,7 @@ int UpnpGetIfInfo(const char *IfName) ifname_found = 1; } /* Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. */ - if ((LocalSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { + if ((LocalSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) { UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Can't create addrlist socket\n"); return UPNP_E_INIT; @@ -3662,7 +3662,7 @@ int getlocalhostname(char *out, size_t out_len) /* Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. */ LocalSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (LocalSock < 0) { + if (LocalSock == INVALID_SOCKET) { UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Can't create addrlist socket\n"); return UPNP_E_INIT; diff --git a/upnp/src/genlib/net/http/httpreadwrite.c b/upnp/src/genlib/net/http/httpreadwrite.c index c4a2b34..8ffa8ce 100644 --- a/upnp/src/genlib/net/http/httpreadwrite.c +++ b/upnp/src/genlib/net/http/httpreadwrite.c @@ -222,8 +222,8 @@ SOCKET http_Connect( http_FixUrl(destination_url, url); connfd = socket(url->hostport.IPaddress.ss_family, SOCK_STREAM, 0); - if (connfd == -1) { - return UPNP_E_OUTOF_SOCKET; + if (connfd == INVALID_SOCKET) { + return (SOCKET)(UPNP_E_OUTOF_SOCKET); } sockaddr_len = (socklen_t)(url->hostport.IPaddress.ss_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)); @@ -236,7 +236,7 @@ SOCKET http_Connect( #endif shutdown(connfd, SD_BOTH); UpnpCloseSocket(connfd); - return UPNP_E_SOCKET_CONNECT; + return (SOCKET)(UPNP_E_SOCKET_CONNECT); } return connfd; @@ -548,7 +548,7 @@ int http_RequestAndResponse( tcp_connection = socket( destination->hostport.IPaddress.ss_family, SOCK_STREAM, 0); - if (tcp_connection == -1) { + if (tcp_connection == INVALID_SOCKET) { parser_response_init(response, req_method); return UPNP_E_SOCKET_ERROR; } @@ -969,7 +969,7 @@ int http_OpenHttpPost( handle->contentLength = contentLength; tcp_connection = socket(url.hostport.IPaddress.ss_family, SOCK_STREAM, 0); - if (tcp_connection == -1) { + if (tcp_connection == INVALID_SOCKET) { ret_code = UPNP_E_SOCKET_ERROR; goto errorHandler; } @@ -1446,7 +1446,7 @@ int http_OpenHttpGetProxy(const char *url_str, const char *proxy_str, parser_response_init(&handle->response, HTTPMETHOD_GET); tcp_connection = socket(peer->hostport.IPaddress.ss_family, SOCK_STREAM, 0); - if (tcp_connection == -1) { + if (tcp_connection == INVALID_SOCKET) { ret_code = UPNP_E_SOCKET_ERROR; goto errorHandler; } @@ -1965,7 +1965,7 @@ int http_OpenHttpGetEx( memset(handle, 0, sizeof(*handle)); parser_response_init(&handle->response, HTTPMETHOD_GET); tcp_connection = socket(url.hostport.IPaddress.ss_family, SOCK_STREAM, 0); - if (tcp_connection == -1) { + if (tcp_connection == INVALID_SOCKET) { errCode = UPNP_E_SOCKET_ERROR; free(handle); break; diff --git a/upnp/src/genlib/net/sock.c b/upnp/src/genlib/net/sock.c index e59d05a..1ec0a73 100644 --- a/upnp/src/genlib/net/sock.c +++ b/upnp/src/genlib/net/sock.c @@ -86,12 +86,12 @@ int sock_destroy(SOCKINFO *info, int ShutdownMethod) { int ret = UPNP_E_SUCCESS; - if (info->socket != -1) { + if (info->socket != INVALID_SOCKET) { shutdown(info->socket, ShutdownMethod); if (sock_close(info->socket) == -1) { ret = UPNP_E_SOCKET_ERROR; } - info->socket = -1; + info->socket = INVALID_SOCKET; } return ret; diff --git a/upnp/src/inc/sock.h b/upnp/src/inc/sock.h index 5a2195e..038563e 100644 --- a/upnp/src/inc/sock.h +++ b/upnp/src/inc/sock.h @@ -74,7 +74,7 @@ static UPNP_INLINE int sock_close( { int ret = -1; - if (sock != -1) + if (sock != INVALID_SOCKET) ret = UpnpCloseSocket(sock); return ret; diff --git a/upnp/src/ssdp/ssdp_ctrlpt.c b/upnp/src/ssdp/ssdp_ctrlpt.c index 7ddb6bc..b118140 100644 --- a/upnp/src/ssdp/ssdp_ctrlpt.c +++ b/upnp/src/ssdp/ssdp_ctrlpt.c @@ -452,7 +452,7 @@ int SearchByTarget(int Mx, char *St, void *Cookie) struct Handle_Info *ctrlpt_info = NULL; enum SsdpSearchType requestType; unsigned long addrv4 = inet_addr(gIF_IPV4); - int max_fd = 0; + SOCKET max_fd = 0; /*ThreadData *ThData; */ ThreadPoolJob job; diff --git a/upnp/src/ssdp/ssdp_device.c b/upnp/src/ssdp/ssdp_device.c index 4446add..260bd75 100644 --- a/upnp/src/ssdp/ssdp_device.c +++ b/upnp/src/ssdp/ssdp_device.c @@ -181,7 +181,7 @@ static int NewRequestHandler( int ret = UPNP_E_SUCCESS; ReplySock = socket(DestAddr->sa_family, SOCK_DGRAM, 0); - if (ReplySock == -1) { + if (ReplySock == INVALID_SOCKET) { strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, "SSDP_LIB: New Request Handler:" diff --git a/upnp/src/ssdp/ssdp_server.c b/upnp/src/ssdp/ssdp_server.c index 7abad6b..4e3ae72 100644 --- a/upnp/src/ssdp/ssdp_server.c +++ b/upnp/src/ssdp/ssdp_server.c @@ -736,7 +736,7 @@ static int create_ssdp_sock_v4( struct in_addr addr; *ssdpSock = socket(AF_INET, SOCK_DGRAM, 0); - if (*ssdpSock == -1) { + if (*ssdpSock == INVALID_SOCKET) { strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, "Error in socket(): %s\n", errorBuffer); @@ -847,7 +847,7 @@ static int create_ssdp_sock_reqv4( u_char ttl = 4; *ssdpReqSock = socket(AF_INET, SOCK_DGRAM, 0); - if (*ssdpReqSock == -1) { + if (*ssdpReqSock == INVALID_SOCKET) { strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, "Error in socket(): %s\n", errorBuffer); @@ -877,7 +877,7 @@ static int create_ssdp_sock_v6( int ret = 0; *ssdpSock = socket(AF_INET6, SOCK_DGRAM, 0); - if (*ssdpSock == -1) { + if (*ssdpSock == INVALID_SOCKET) { strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, "Error in socket(): %s\n", errorBuffer); @@ -978,7 +978,7 @@ static int create_ssdp_sock_v6_ula_gua( int ret = 0; *ssdpSock = socket(AF_INET6, SOCK_DGRAM, 0); - if (*ssdpSock == -1) { + if (*ssdpSock == INVALID_SOCKET) { strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, "Error in socket(): %s\n", errorBuffer); @@ -1076,7 +1076,7 @@ static int create_ssdp_sock_reqv6( char hops = 1; *ssdpReqSock = socket(AF_INET6, SOCK_DGRAM, 0); - if (*ssdpReqSock == -1) { + if (*ssdpReqSock == INVALID_SOCKET) { strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, "Error in socket(): %s\n", errorBuffer);