Several fixes to correctly use SOCKET (and related) types instead of non-portable variations.

(cherry picked from commit fed316ff3e)
This commit is contained in:
Iain Denniston 2011-03-18 12:09:33 +00:00 committed by Marcelo Roberto Jimenez
parent f8831d0196
commit 7392697aec
8 changed files with 23 additions and 19 deletions

View File

@ -255,6 +255,10 @@ Version 1.8.0
Version 1.6.14
*******************************************************************************
2011-03-08 Iain Denniston <iain.denniston(at)gmail.com>
Several fixes to correctly use SOCKET (and related) types instead of
non-portable variations.
*******************************************************************************
Version 1.6.13

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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:"

View File

@ -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);