Add more explicit casts and remove dead code

Comment unused SERVER from DeviceShutdown.
Comment unused max from parse_hostport.
Comment unused nodeptr from ixmlNode_cloneDoc.
Comment unused newNode from Parser_hasDefaultNamespace.
Comment unused Parser_parseReference function
Check return code of shutdown and display an error if needed.
This commit is contained in:
Fabrice Fontaine 2012-03-15 14:49:26 +01:00
parent c9f3e26f24
commit cb07623dde
13 changed files with 159 additions and 118 deletions

View File

@ -2,6 +2,17 @@
Version 1.6.16
*******************************************************************************
2012-03-16 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Add more explicit casts and remove dead code
Comment unused SERVER from DeviceShutdown.
Comment unused max from parse_hostport.
Comment unused nodeptr from ixmlNode_cloneDoc.
Comment unused newNode from Parser_hasDefaultNamespace.
Comment unused Parser_parseReference function
Check return code of shutdown and display an error if needed.
2012-03-15 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Fix previous commit

View File

@ -1096,7 +1096,7 @@ static char *safe_strdup(
assert(s != NULL);
if (s == NULL) {
return strdup("");
return strdup((const char*)"");
}
return strdup(s);
}
@ -1215,7 +1215,7 @@ static int Parser_processCDSect(
IXML_Node *node)
{
char *pEnd;
size_t tokenLength = 0;
size_t tokenLength = (size_t)0;
char *pCDataStart;
if( *pSrc == NULL ) {
@ -1451,6 +1451,7 @@ ExitFunction:
*
* \return IXML_SUCCESS.
*/
#if 0
static int Parser_parseReference(
/*! [in] Currently unused. */
char *pStr)
@ -1459,6 +1460,7 @@ static int Parser_parseReference(
return IXML_SUCCESS;
pStr = pStr;
}
#endif
/*!
@ -1746,9 +1748,9 @@ static int Parser_processAttribute(
line = __LINE__;
goto ExitFunction;
}
if (*pCur == '&') {
/*if (*pCur == '&') {
Parser_parseReference(++pCur);
}
}*/
pCur++;
}
/* clear token buffer */
@ -1861,7 +1863,7 @@ static int Parser_getNextNode(
line = __LINE__;
ret = IXML_SUCCESS;
goto ExitFunction;
} else if ((xmlParser->tokenBuf).length == 0) {
} else if ((xmlParser->tokenBuf).length == (size_t)0) {
line = __LINE__;
ret = IXML_SYNTAX_ERR;
goto ExitFunction;
@ -1901,8 +1903,16 @@ static int Parser_getNextNode(
line = __LINE__;
ret = IXML_SUCCESS;
goto ExitFunction;
} else if (xmlParser->state == eATTRIBUTE && xmlParser->pCurElement != NULL) {
if (Parser_processAttribute(xmlParser, node) != IXML_SUCCESS) {
} else if (xmlParser->pCurElement != NULL) {
switch (xmlParser->state) {
case eATTRIBUTE:
if (Parser_processAttribute(xmlParser, node) != IXML_SUCCESS) {
line = __LINE__;
ret = IXML_SYNTAX_ERR;
goto ExitFunction;
}
break;
default:
line = __LINE__;
ret = IXML_SYNTAX_ERR;
goto ExitFunction;
@ -2139,7 +2149,7 @@ static BOOL Parser_hasDefaultNamespace(
/*! [in] The XML parser. */
Parser *xmlParser,
/*! [in] The Node to process. */
IXML_Node *newNode,
/*IXML_Node *newNode,*/
/*! [in,out] The name space URI. */
char **nsURI )
{
@ -2155,7 +2165,7 @@ static BOOL Parser_hasDefaultNamespace(
}
return FALSE;
newNode = newNode;
//newNode = newNode;
}
@ -2208,7 +2218,7 @@ static int Parser_processElementName(
} else {
/* does element has default namespace */
/* the node may have default namespace definition */
if (Parser_hasDefaultNamespace(xmlParser, newNode, &nsURI)) {
if (Parser_hasDefaultNamespace(xmlParser, /*newNode,*/ &nsURI)) {
Parser_setElementNamespace(newElement, nsURI);
} else {
switch (xmlParser->state) {
@ -2528,7 +2538,7 @@ static int Parser_readFileOrBuffer(
BOOL file)
{
long fileSize = 0;
size_t bytesRead = 0;
size_t bytesRead = (size_t)0;
FILE *xmlFilePtr = NULL;
if( file ) {
@ -2543,7 +2553,7 @@ static int Parser_readFileOrBuffer(
return IXML_SYNTAX_ERR;
}
xmlParser->dataBuffer = (char *)malloc((size_t)fileSize + 1);
xmlParser->dataBuffer = (char *)malloc((size_t)fileSize + (size_t)1);
if( xmlParser->dataBuffer == NULL ) {
fclose( xmlFilePtr );
return IXML_INSUFFICIENT_MEMORY;

View File

@ -128,7 +128,7 @@ IXML_Node *ixmlNamedNodeMap_item(
unsigned long ixmlNamedNodeMap_getLength(IXML_NamedNodeMap *nnMap)
{
IXML_Node *tempNode;
unsigned long length = 0;
unsigned long length = 0lu;
if (nnMap != NULL) {
tempNode = nnMap->nodeItem;

View File

@ -776,13 +776,13 @@ static IXML_Element *ixmlNode_cloneElement(
*/
static IXML_Document *ixmlNode_cloneDoc(
/*! [in] The \b Node to clone. */
IXML_Document *nodeptr)
/*IXML_Document *nodeptr*/)
{
IXML_Document *newDoc;
IXML_Node *docNode;
int rc;
assert(nodeptr != NULL);
//assert(nodeptr != NULL);
newDoc = (IXML_Document *)malloc(sizeof (IXML_Document));
if (newDoc == NULL) {
@ -801,7 +801,7 @@ static IXML_Document *ixmlNode_cloneDoc(
newDoc->n.nodeType = eDOCUMENT_NODE;
return newDoc;
nodeptr = nodeptr;
//nodeptr = nodeptr;
}
/*!
@ -968,7 +968,7 @@ static IXML_Node *ixmlNode_cloneNodeTreeRecursive(
break;
case eDOCUMENT_NODE:
newDoc = ixmlNode_cloneDoc((IXML_Document *)nodeptr);
newDoc = ixmlNode_cloneDoc(/*(IXML_Document *)nodeptr*/);
if (newDoc == NULL)
return NULL;
newNode = (IXML_Node *)newDoc;

View File

@ -83,18 +83,18 @@ static void StatsInit(
/*! Must be valid non null stats structure. */
ThreadPoolStats *stats)
{
stats->totalIdleTime = 0;
stats->totalIdleTime = 0.0;
stats->totalJobsHQ = 0;
stats->totalJobsLQ = 0;
stats->totalJobsMQ = 0;
stats->totalTimeHQ = 0;
stats->totalTimeMQ = 0;
stats->totalTimeLQ = 0;
stats->totalWorkTime = 0;
stats->totalIdleTime = 0;
stats->avgWaitHQ = 0;
stats->avgWaitMQ = 0;
stats->avgWaitLQ = 0;
stats->totalTimeHQ = 0.0;
stats->totalTimeMQ = 0.0;
stats->totalTimeLQ = 0.0;
stats->totalWorkTime = 0.0;
stats->totalIdleTime = 0.0;
stats->avgWaitHQ = 0.0;
stats->avgWaitMQ = 0.0;
stats->avgWaitLQ = 0.0;
stats->workerThreads = 0;
stats->idleThreads = 0;
stats->persistentThreads = 0;
@ -1205,7 +1205,7 @@ int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
if (stats->totalJobsHQ > 0)
stats->avgWaitHQ = stats->totalTimeHQ / (double)stats->totalJobsHQ;
else
stats->avgWaitHQ = 0;
stats->avgWaitHQ = 0.0;
if (stats->totalJobsMQ > 0)
stats->avgWaitMQ = stats->totalTimeMQ / (double)stats->totalJobsMQ;
else

View File

@ -249,7 +249,7 @@ static parse_status_t scanner_get_token(
/* possibly more valid chars */
return PARSE_INCOMPLETE;
/* calc token length */
token->length = (size_t)(cursor - token->buf);
token->length = (size_t)cursor - (size_t)token->buf;
} else if (c == ' ' || c == '\t') {
token->buf = cursor++;
token_type = TT_WHITESPACE;
@ -258,7 +258,7 @@ static parse_status_t scanner_get_token(
if (!scanner->entire_msg_loaded && cursor == null_terminator)
/* possibly more chars */
return PARSE_INCOMPLETE;
token->length = (size_t)(cursor - token->buf);
token->length = (size_t)cursor - (size_t)token->buf;
} else if (c == TOKCHAR_CR) {
/* scan CRLF */
token->buf = cursor++;
@ -304,7 +304,7 @@ static parse_status_t scanner_get_token(
return PARSE_FAILURE;
}
if (got_end_quote)
token->length = (size_t)(cursor - token->buf);
token->length = (size_t)cursor - (size_t)token->buf;
else { /* incomplete */
assert(cursor == null_terminator);
@ -1414,7 +1414,7 @@ parse_status_t parser_parse_responseline(INOUT http_parser_t *parser)
while (*p == ' ' || *p == '\t')
p++;
/* now, p is at start of status msg */
n = line.length - (size_t)(p - line.buf);
n = line.length - ((size_t)p - (size_t)line.buf);
if (membuffer_assign(&hmsg->status_msg, p, n) != 0) {
/* out of mem */
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
@ -1735,7 +1735,7 @@ parser_parse_chunky_entity( INOUT http_parser_t * parser )
( scanner->cursor - save_pos ) );
scanner->cursor = save_pos; /* adjust scanner too */
if( parser->chunk_size == 0 ) {
if( parser->chunk_size == (size_t)0 ) {
/* done reading entity; determine length of entity */
parser->msg.entity.length = parser->scanner.cursor -
parser->entity_start_position + parser->msg.amount_discarded;

View File

@ -220,6 +220,7 @@ SOCKET http_Connect(
SOCKET connfd;
socklen_t sockaddr_len;
int ret_connect;
char errorBuffer[ERROR_BUFFER_LEN];
http_FixUrl(destination_url, url);
@ -237,7 +238,11 @@ SOCKET http_Connect(
UpnpPrintf(UPNP_CRITICAL, HTTP, __FILE__, __LINE__,
"connect error: %d\n", WSAGetLastError());
#endif
shutdown(connfd, SD_BOTH);
if (shutdown(connfd, SD_BOTH) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(connfd);
return (SOCKET)(UPNP_E_SOCKET_CONNECT);
}
@ -1659,7 +1664,7 @@ int http_MakeMessage(membuffer *buf, int http_major_version,
/* mem buffer */
s = (char *)va_arg(argp, char *);
UpnpPrintf(UPNP_ALL, HTTP, __FILE__, __LINE__,
"Adding a char Buffer starting with: %c\n", s[0]);
"Adding a char Buffer starting with: %c\n", (int)s[0]);
assert(s);
length = (size_t) va_arg(argp, size_t);
if (membuffer_append(buf, s, length))

View File

@ -48,6 +48,9 @@
#include "upnp.h"
#include "UpnpStdInt.h" /* for ssize_t */
#include "upnpdebug.h"
#include "upnputil.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h> /* for F_GETFL, F_SETFL, O_NONBLOCK */
@ -87,9 +90,14 @@ int sock_init_with_ip(SOCKINFO *info, SOCKET sockfd,
int sock_destroy(SOCKINFO *info, int ShutdownMethod)
{
int ret = UPNP_E_SUCCESS;
char errorBuffer[ERROR_BUFFER_LEN];
if (info->socket != INVALID_SOCKET) {
shutdown(info->socket, ShutdownMethod);
if (shutdown(info->socket, ShutdownMethod) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
if (sock_close(info->socket) == -1) {
ret = UPNP_E_SOCKET_ERROR;
}
@ -128,7 +136,7 @@ static int sock_read_write(
time_t start_time = time(NULL);
SOCKET sockfd = info->socket;
long bytes_sent = 0;
size_t byte_left = 0;
size_t byte_left = (size_t)0;
ssize_t num_written;
if (*timeoutSecs < 0)
@ -172,7 +180,7 @@ static int sock_read_write(
} else {
byte_left = bufsize;
bytes_sent = 0;
while (byte_left != 0) {
while (byte_left != (size_t)0) {
/* write data. */
num_written = send(sockfd,
buffer + bytes_sent, byte_left,

View File

@ -315,7 +315,7 @@ int token_cmp(token *in1, token *in2)
int parse_hostport(
const char *in,
size_t max,
/*size_t max,*/
hostport_type *out)
{
char workbuf[256];
@ -446,7 +446,7 @@ int parse_hostport(
out->text.buff = in;
return (int)hostport_size;
max = max;
//max=max;
}
/*!
@ -706,7 +706,7 @@ int parse_uri(const char *in, size_t max, uri_type *out)
in[begin_hostport + (size_t)1] == '/') {
begin_hostport += (size_t)2;
begin_path = parse_hostport(&in[begin_hostport],
max - begin_hostport,
/*max - begin_hostport,*/
&out->hostport);
if (begin_path >= 0) {
begin_path += (int)begin_hostport;

View File

@ -502,7 +502,7 @@ int DeviceShutdown(
/* [in] Device UDN. */
char *Udn,
/* [in] . */
char *_Server,
/*char *_Server,*/
/* [in] Location URL. */
char *Location,
/* [in] Device duration in sec. */

View File

@ -287,7 +287,7 @@ int parse_hostport(
/*! [in] String of characters representing host and port. */
const char *in,
/*! [in] Sets a maximum limit. */
size_t max,
/*size_t max,*/
/*! [out] Output parameter where the host and port are represented as
* an internet address. */
hostport_type *out);

View File

@ -119,8 +119,11 @@ void ssdp_handle_device_request(http_message_t *hmsg, struct sockaddr_storage *d
HandleLock();
/* device info. */
if (GetDeviceHandleInfo(dest_addr->ss_family,
&handle, &dev_info) != HND_DEVICE) {
switch (GetDeviceHandleInfo((int)dest_addr->ss_family,
&handle, &dev_info)) {
case HND_DEVICE:
break;
default:
HandleUnlock();
/* no info found. */
return;
@ -241,7 +244,12 @@ static int NewRequestHandler(
}
end_NewRequestHandler:
shutdown(ReplySock, SD_BOTH);
ret = shutdown(ReplySock, SD_BOTH);
if (ret == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(ReplySock);
return ret;
@ -823,7 +831,7 @@ error_handler:
return RetVal;
}
int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *_Server,
int DeviceShutdown(char *DevType, int RootDev, char *Udn, /*char *_Server,*/
char *Location, int Duration, int AddressFamily,
int PowerState, int SleepPeriod, int RegistrationState)
{
@ -903,7 +911,7 @@ error_handler:
free(msgs[2]);
return ret_code;
_Server = _Server;
//_Server = _Server;
}
#endif /* EXCLUDE_SSDP */
#endif /* INCLUDE_DEVICE_APIS */

View File

@ -108,7 +108,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
IXML_Node *tmpNode2 = NULL;
IXML_Node *textNode = NULL;
const DOMString tmpStr;
char SERVER[200];
//char SERVER[200];
const DOMString dbgStr;
int NumCopy = 0;
@ -127,7 +127,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
}
defaultExp = SInfo->MaxAge;
/* get server info */
get_sdk_info(SERVER);
//get_sdk_info(SERVER);
/* parse the device list and send advertisements/replies */
while (NumCopy == 0 || (AdFlag && NumCopy < NUM_SSDP_COPY)) {
if (NumCopy != 0)
@ -218,7 +218,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
} else {
/* AdFlag == -1 */
DeviceShutdown(devType, i == 0lu, UDNstr,
SERVER, SInfo->DescURL,
/*SERVER,*/ SInfo->DescURL,
Exp, SInfo->DeviceAf,
SInfo->PowerState,
SInfo->SleepPeriod,
@ -812,10 +812,8 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEADDR: %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
#if defined(BSD) || defined(__OSX__) || defined(__APPLE__)
onOff = 1;
@ -826,10 +824,8 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEPORT: %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
#endif /* BSD, __OSX__, __APPLE__ */
memset(&__ss, 0, sizeof(__ss));
@ -842,10 +838,8 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in bind(), addr=0x%08X, port=%d: %s\n",
INADDR_ANY, SSDP_PORT, errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_BIND;
ret = UPNP_E_SOCKET_BIND;
goto error_handler;
}
memset((void *)&ssdpMcastAddr, 0, sizeof(struct ip_mreq));
ssdpMcastAddr.imr_interface.s_addr = inet_addr(gIF_IPV4);
@ -857,10 +851,8 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IP_ADD_MEMBERSHIP (join multicast group): %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
/* Set multicast interface. */
memset((void *)&addr, 0, sizeof(struct in_addr));
@ -885,13 +877,22 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_BROADCAST (set broadcast): %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
ret = UPNP_E_NETWORK_ERROR;
goto error_handler;
}
ret = UPNP_E_SUCCESS;
return UPNP_E_NETWORK_ERROR;
error_handler:
if (ret != UPNP_E_SUCCESS) {
if (shutdown(*ssdpSock, SD_BOTH) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(*ssdpSock);
}
return UPNP_E_SUCCESS;
return ret;
}
#ifdef INCLUDE_CLIENT_APIS
@ -953,10 +954,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEADDR: %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
#if defined(BSD) || defined(__OSX__) || defined(__APPLE__)
onOff = 1;
@ -967,10 +966,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEPORT: %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
#endif /* BSD, __OSX__, __APPLE__ */
onOff = 1;
@ -981,10 +978,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IPV6_V6ONLY: %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
memset(&__ss, 0, sizeof(__ss));
ssdpAddr6->sin6_family = (sa_family_t)AF_INET6;
@ -997,10 +992,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in bind(), addr=0x%032lX, port=%d: %s\n",
0lu, SSDP_PORT, errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_BIND;
ret = UPNP_E_SOCKET_BIND;
goto error_handler;
}
memset((void *)&ssdpMcastAddr, 0, sizeof(ssdpMcastAddr));
ssdpMcastAddr.ipv6mr_interface = gIF_INDEX;
@ -1013,10 +1006,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IPV6_JOIN_GROUP (join multicast group): %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
onOff = 1;
ret = setsockopt(*ssdpSock, SOL_SOCKET, SO_BROADCAST,
@ -1026,13 +1017,22 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_BROADCAST (set broadcast): %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
ret = UPNP_E_NETWORK_ERROR;
goto error_handler;
}
ret = UPNP_E_SUCCESS;
return UPNP_E_NETWORK_ERROR;
error_handler:
if (ret != UPNP_E_SUCCESS) {
if (shutdown(*ssdpSock, SD_BOTH) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(*ssdpSock);
}
return UPNP_E_SUCCESS;
return ret;
}
#endif /* IPv6 */
@ -1067,10 +1067,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEADDR: %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
#if defined(BSD) || defined(__OSX__) || defined(__APPLE__)
onOff = 1;
@ -1081,10 +1079,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEPORT: %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
#endif /* BSD, __OSX__, __APPLE__ */
onOff = 1;
@ -1095,10 +1091,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IPV6_V6ONLY: %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
memset(&__ss, 0, sizeof(__ss));
ssdpAddr6->sin6_family = (sa_family_t)AF_INET6;
@ -1111,10 +1105,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in bind(), addr=0x%032lX, port=%d: %s\n",
0lu, SSDP_PORT, errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_BIND;
ret = UPNP_E_SOCKET_BIND;
goto error_handler;
}
memset((void *)&ssdpMcastAddr, 0, sizeof(ssdpMcastAddr));
ssdpMcastAddr.ipv6mr_interface = gIF_INDEX;
@ -1128,10 +1120,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IPV6_JOIN_GROUP (join multicast group): %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
return UPNP_E_SOCKET_ERROR;
ret = UPNP_E_SOCKET_ERROR;
goto error_handler;
}
onOff = 1;
ret = setsockopt(*ssdpSock, SOL_SOCKET, SO_BROADCAST,
@ -1141,13 +1131,22 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_BROADCAST (set broadcast): %s\n",
errorBuffer);
shutdown(*ssdpSock, SD_BOTH);
UpnpCloseSocket(*ssdpSock);
ret = UPNP_E_NETWORK_ERROR;
goto error_handler;
}
ret = UPNP_E_SUCCESS;
return UPNP_E_NETWORK_ERROR;
error_handler:
if (ret != UPNP_E_SUCCESS) {
if (shutdown(*ssdpSock, SD_BOTH) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(*ssdpSock);
}
return UPNP_E_SUCCESS;
return ret;
}
#endif /* IPv6 */