From d56a68d7716a11aebbc52b1604e7c39a5111c7cd Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Sat, 10 Mar 2012 21:27:55 +0100 Subject: [PATCH] Remove more implicit casts in upnp part Remove more "implicit integer or enum conversions" as well as memset before snprintf. (forward port of commit 2eb3e069badd5c8676738c3ead37f9551fd8448e) --- ChangeLog | 7 ++++ upnp/src/api/upnpapi.c | 4 +- upnp/src/genlib/net/http/httpreadwrite.c | 46 +++++++++++---------- upnp/src/genlib/net/http/statcodes.c | 2 +- upnp/src/genlib/net/sock.c | 13 +++--- upnp/src/genlib/net/uri/uri.c | 39 +++++++++--------- upnp/src/inc/config.h | 3 +- upnp/src/inc/sock.h | 5 ++- upnp/src/inc/ssdplib.h | 8 ++-- upnp/src/inc/upnpapi.h | 2 +- upnp/src/inc/uri.h | 2 +- upnp/src/ssdp/ssdp_device.c | 51 ++++++++++-------------- 12 files changed, 96 insertions(+), 86 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b03729..e898930 100644 --- a/ChangeLog +++ b/ChangeLog @@ -318,6 +318,13 @@ Version 1.8.0 Version 1.6.16 ******************************************************************************* +2012-03-11 Fabrice Fontaine + + Remove more implicit casts in upnp part + + Remove more "implicit integer or enum conversions" as well as memset + before snprintf. + 2012-03-11 Yoichi NAKAYAMA Avoid out of range access in CheckOtherHTTPHeaders. diff --git a/upnp/src/api/upnpapi.c b/upnp/src/api/upnpapi.c index e16e94e..fe9e194 100644 --- a/upnp/src/api/upnpapi.c +++ b/upnp/src/api/upnpapi.c @@ -1313,9 +1313,9 @@ int UpnpUnRegisterRootDeviceLowPower(UpnpDevice_Handle Hnd, int PowerState, if (HInfo->aliasInstalled) web_server_set_alias(NULL, NULL, 0, 0); #endif /* INTERNAL_WEB_SERVER */ - if (HInfo->DeviceAf == AF_INET) + if (HInfo->DeviceAf == (unsigned short)AF_INET) UpnpSdkDeviceRegisteredV4 = 0; - else if (HInfo->DeviceAf == AF_INET6) + else if (HInfo->DeviceAf == (unsigned short)AF_INET6) UpnpSdkDeviceregisteredV6 = 0; FreeHandle(Hnd); HandleUnlock(); diff --git a/upnp/src/genlib/net/http/httpreadwrite.c b/upnp/src/genlib/net/http/httpreadwrite.c index 2b7853d..6be3f73 100644 --- a/upnp/src/genlib/net/http/httpreadwrite.c +++ b/upnp/src/genlib/net/http/httpreadwrite.c @@ -76,8 +76,8 @@ const int CHUNK_HEADER_SIZE = 10; const int CHUNK_TAIL_SIZE = 10; */ -#define CHUNK_HEADER_SIZE 10 -#define CHUNK_TAIL_SIZE 10 +#define CHUNK_HEADER_SIZE (size_t)10 +#define CHUNK_TAIL_SIZE (size_t)10 #ifndef UPNP_ENABLE_BLOCKING_TCP_CONNECTIONS @@ -337,7 +337,7 @@ int http_RecvMessage( int ok_on_close = FALSE; char buf[2 * 1024]; - if (request_method == HTTPMETHOD_UNKNOWN) { + if (request_method == (http_method_t)HTTPMETHOD_UNKNOWN) { parser_request_init(parser); } else { parser_response_init(parser, request_method); @@ -348,12 +348,13 @@ int http_RecvMessage( if (num_read > 0) { /* got data */ status = parser_append(parser, buf, (size_t)num_read); - if (status == PARSE_SUCCESS) { + switch (status) { + case PARSE_SUCCESS: UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, "<<< (RECVD) <<<\n%s\n-----------------\n", parser->msg.msg.buf ); print_http_headers( &parser->msg ); - if (g_maxContentLength > 0 && parser->content_length > (unsigned int)g_maxContentLength) { + if (g_maxContentLength > (size_t)0 && parser->content_length > (unsigned int)g_maxContentLength) { *http_error_code = HTTP_REQ_ENTITY_TOO_LARGE; line = __LINE__; ret = UPNP_E_OUTOF_BOUNDS; @@ -362,19 +363,21 @@ int http_RecvMessage( line = __LINE__; ret = 0; goto ExitFunction; - } else if (status == PARSE_FAILURE) { + case PARSE_FAILURE: *http_error_code = parser->http_error_code; line = __LINE__; ret = UPNP_E_BAD_HTTPMSG; goto ExitFunction; - } else if (status == PARSE_INCOMPLETE_ENTITY) { + case PARSE_INCOMPLETE_ENTITY: /* read until close */ ok_on_close = TRUE; - } else if (status == PARSE_CONTINUE_1) { + case PARSE_CONTINUE_1: /* Web post request. */ line = __LINE__; ret = PARSE_SUCCESS; goto ExitFunction; + default: + break; } } else if (num_read == 0) { if (ok_on_close) { @@ -427,7 +430,7 @@ int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt, ...) size_t buf_length; size_t num_read; size_t num_written; - size_t amount_to_be_read = 0; + size_t amount_to_be_read = (size_t)0; /* 10 byte allocated for chunk header. */ size_t Data_Buf_Size = WEB_SERVER_BUF_SIZE; @@ -482,7 +485,7 @@ int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt, ...) nr = virtualDirCallback.read(Fp, file_buf, n); num_read = (size_t)nr; } else { - num_read = fread(file_buf, 1, n, Fp); + num_read = fread(file_buf, (size_t)1, n, Fp); } amount_to_be_read -= num_read; if (Instr->ReadSendSize < 0) { @@ -490,9 +493,9 @@ int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt, ...) amount_to_be_read = Data_Buf_Size; } } else { - num_read = fread(file_buf, 1, Data_Buf_Size, Fp); + num_read = fread(file_buf, (size_t)1, Data_Buf_Size, Fp); } - if (num_read == 0) { + if (num_read == (size_t)0) { /* EOF so no more to send. */ if (Instr && Instr->IsChunkActive) { const char *str = "0\r\n\r\n"; @@ -529,10 +532,10 @@ int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt, ...) /*printf("Sending %s\n",file_buf-strlen(Chunk_Header)); */ nw = sock_write(info, file_buf - strlen(Chunk_Header), - num_read + strlen(Chunk_Header) + 2, + num_read + strlen(Chunk_Header) + (size_t)2, TimeOut); num_written = (size_t)nw; - if (nw <= 0 || num_written != num_read + strlen(Chunk_Header) + 2) + if (nw <= 0 || num_written != num_read + strlen(Chunk_Header) + (size_t)2) /* Send error nothing we can do. */ goto Cleanup_File; } else { @@ -559,7 +562,7 @@ Cleanup_File: /* memory buffer */ buf = va_arg(argp, char *); buf_length = va_arg(argp, size_t); - if (buf_length > 0) { + if (buf_length > (size_t)0) { nw = sock_write(info, buf, buf_length, TimeOut); num_written = (size_t)nw; UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__, @@ -619,7 +622,7 @@ int http_RequestAndResponse( SOCKINFO info; tcp_connection = socket( - destination->hostport.IPaddress.ss_family, SOCK_STREAM, 0); + (int)destination->hostport.IPaddress.ss_family, SOCK_STREAM, 0); if (tcp_connection == INVALID_SOCKET) { parser_response_init(response, req_method); return UPNP_E_SOCKET_ERROR; @@ -1225,8 +1228,11 @@ int http_GetHttpResponse(void *Handle, UpnpString *headers, goto errorHandler; } status = parser_get_entity_read_method(&handle->response); - if (status != (parse_status_t)PARSE_CONTINUE_1 && - status != (parse_status_t)PARSE_SUCCESS) { + switch (status) { + case PARSE_CONTINUE_1: + case PARSE_SUCCESS: + break; + default: ret_code = UPNP_E_BAD_RESPONSE; goto errorHandler; } @@ -1242,7 +1248,7 @@ int http_GetHttpResponse(void *Handle, UpnpString *headers, *contentType = ctype.buf; } if (contentLength) { - if (handle->response.position == POS_COMPLETE) + if (handle->response.position == (parser_pos_t)POS_COMPLETE) *contentLength = 0; else if (handle->response.ent_position == ENTREAD_USING_CHUNKED) *contentLength = UPNP_USING_CHUNKED; @@ -1404,7 +1410,7 @@ int http_SendStatusResponse(IN SOCKINFO *info, IN int http_status_code, http_CalcResponseVersion(request_major_version, request_minor_version, &response_major, &response_minor); membuffer_init(&membuf); - membuf.size_inc = 70; + membuf.size_inc = (size_t)70; /* response start line */ ret = http_MakeMessage(&membuf, response_major, response_minor, "RSCB", http_status_code, http_status_code); diff --git a/upnp/src/genlib/net/http/statcodes.c b/upnp/src/genlib/net/http/statcodes.c index 31b9ff3..2599d4a 100644 --- a/upnp/src/genlib/net/http/statcodes.c +++ b/upnp/src/genlib/net/http/statcodes.c @@ -129,7 +129,7 @@ init_table( IN const char *encoded_str, for( i = 0; i < tbl_size; i++ ) { table[i] = s; - s += strlen( s ) + 1; /* next entry */ + s += strlen( s ) + (size_t)1; /* next entry */ } } diff --git a/upnp/src/genlib/net/sock.c b/upnp/src/genlib/net/sock.c index 2064417..a69ce9b 100644 --- a/upnp/src/genlib/net/sock.c +++ b/upnp/src/genlib/net/sock.c @@ -2,6 +2,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (c) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -147,7 +148,7 @@ static int sock_read_write( /*! [out] Buffer to get data to or send data from. */ char *buffer, /*! [in] Size of the buffer. */ - int bufsize, + size_t bufsize, /*! [in] timeout value. */ int *timeoutSecs, /*! [in] Boolean value specifying read or write option. */ @@ -164,6 +165,8 @@ static int sock_read_write( long byte_left = 0; long num_written; + if (*timeoutSecs < 0) + return UPNP_E_TIMEDOUT; FD_ZERO(&readSet); FD_ZERO(&writeSet); if (bRead) @@ -173,7 +176,7 @@ static int sock_read_write( timeout.tv_sec = *timeoutSecs; timeout.tv_usec = 0; while (TRUE) { - if (*timeoutSecs < 0) + if (*timeoutSecs == 0) retCode = select(sockfd + 1, &readSet, &writeSet, NULL, NULL); else @@ -206,7 +209,7 @@ static int sock_read_write( else { #endif /* read data. */ - numBytes = (long)recv(sockfd, buffer, (size_t)bufsize, MSG_NOSIGNAL); + numBytes = (long)recv(sockfd, buffer, bufsize, MSG_NOSIGNAL); #ifdef UPNP_ENABLE_OPEN_SSL } #endif @@ -253,12 +256,12 @@ static int sock_read_write( return (int)numBytes; } -int sock_read(SOCKINFO *info, char *buffer, int bufsize, int *timeoutSecs) +int sock_read(SOCKINFO *info, char *buffer, size_t bufsize, int *timeoutSecs) { return sock_read_write(info, buffer, bufsize, timeoutSecs, TRUE); } -int sock_write(SOCKINFO *info, const char *buffer, int bufsize, int *timeoutSecs) +int sock_write(SOCKINFO *info, const char *buffer, size_t bufsize, int *timeoutSecs) { /* Consciently removing constness. */ return sock_read_write(info, (char *)buffer, bufsize, timeoutSecs, FALSE); diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index 89c7a7d..8d98fea 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -69,7 +69,7 @@ static int is_reserved( /*! [in] Char to be matched for RESERVED characters. */ char in) { - if (strchr(RESERVED, in)) { + if (strchr(RESERVED, (int)in)) { return 1; } else { return 0; @@ -87,7 +87,7 @@ int is_mark( /*! [in] Char to be matched for MARKED characters. */ char in) { - if (strchr(MARK, in)) { + if (strchr(MARK, (int)in)) { return 1; } else { return 0; @@ -213,12 +213,12 @@ static void copy_token( int copy_URL_list(URL_list *in, URL_list *out) { - size_t len = strlen(in->URLs) + 1; - size_t i = 0; + size_t len = strlen(in->URLs) + (size_t)1; + size_t i = (size_t)0; out->URLs = NULL; out->parsedURLs = NULL; - out->size = 0; + out->size = (size_t)0; out->URLs = malloc(len); out->parsedURLs = malloc(sizeof(uri_type) * in->size); @@ -226,7 +226,7 @@ int copy_URL_list(URL_list *in, URL_list *out) if ( !out->URLs || !out->parsedURLs) return UPNP_E_OUTOF_MEMORY; memcpy(out->URLs, in->URLs, len); - for( i = 0; i < in->size; i++ ) { + for( i = (size_t)0; i < in->size; i++ ) { /*copy the parsed uri */ out->parsedURLs[i].type = in->parsedURLs[i].type; copy_token( &in->parsedURLs[i].scheme, in->URLs, @@ -257,7 +257,7 @@ void free_URL_list(URL_list *list) if (list->parsedURLs) { free(list->parsedURLs); } - list->size = 0; + list->size = (size_t)0; } @@ -316,7 +316,7 @@ int token_cmp(token *in1, token *in2) int parse_hostport( const char *in, size_t max, - int defaultPort, + unsigned short int defaultPort, hostport_type *out) { char workbuf[256]; @@ -327,7 +327,7 @@ int parse_hostport( char *srvport = NULL; char *last_dot = NULL; unsigned short int port; - int af = AF_UNSPEC; + unsigned short af = AF_UNSPEC; size_t hostport_size; int has_port = 0; int ret; @@ -408,27 +408,26 @@ int parse_hostport( if (port == 0) /* Bad port number. */ return UPNP_E_INVALID_URL; - } else { + } else /* Port was not specified, use default port. */ port = defaultPort; - } /* The length of the host and port string can be calculated by */ /* subtracting pointers. */ hostport_size = (size_t)c - (size_t)workbuf; /* Fill in the 'out' information. */ - if (af == AF_INET) { - sai4->sin_family = (unsigned short)AF_INET; + if (af == (unsigned short)AF_INET) { + sai4->sin_family = af; sai4->sin_port = htons(port); ret = inet_pton(AF_INET, srvname, &sai4->sin_addr); - } else if (af == AF_INET6) { - sai6->sin6_family = (unsigned short)AF_INET6; + } else if (af == (unsigned short)AF_INET6) { + sai6->sin6_family = af; sai6->sin6_port = htons(port); sai6->sin6_scope_id = gIF_INDEX; ret = inet_pton(AF_INET6, srvname, &sai6->sin6_addr); } else { /* IP address was set by the hostname (getaddrinfo). */ /* Override port: */ - if (out->IPaddress.ss_family == AF_INET) + if (out->IPaddress.ss_family == (unsigned short)AF_INET) sai4->sin_port = htons(port); else sai6->sin6_port = htons(port); @@ -686,7 +685,7 @@ int parse_uri(const char *in, size_t max, uri_type *out) int begin_path = 0; size_t begin_hostport = (size_t)0; size_t begin_fragment = (size_t)0; - int defaultPort = 80; + unsigned short int defaultPort = 80; begin_hostport = parse_scheme(in, max, &out->scheme); if (begin_hostport) { @@ -705,9 +704,9 @@ int parse_uri(const char *in, size_t max, uri_type *out) defaultPort = 443; } begin_path = parse_hostport(&in[begin_hostport], - max - begin_hostport, - defaultPort, - &out->hostport); + max - begin_hostport, + defaultPort, + &out->hostport); if (begin_path >= 0) { begin_path += (int)begin_hostport; } else diff --git a/upnp/src/inc/config.h b/upnp/src/inc/config.h index 06d9f68..b59b944 100644 --- a/upnp/src/inc/config.h +++ b/upnp/src/inc/config.h @@ -2,6 +2,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (c) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -189,7 +190,7 @@ * * @{ */ -#define WEB_SERVER_BUF_SIZE (1024*1024) +#define WEB_SERVER_BUF_SIZE (size_t)(1024*1024) /* @} */ /*! diff --git a/upnp/src/inc/sock.h b/upnp/src/inc/sock.h index c8fed42..47987bc 100644 --- a/upnp/src/inc/sock.h +++ b/upnp/src/inc/sock.h @@ -5,6 +5,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (c) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -164,7 +165,7 @@ int sock_read( /*! [out] Buffer to get data to. */ char* buffer, /*! [in] Size of the buffer. */ - int bufsize, + size_t bufsize, /*! [in,out] timeout value. */ int *timeoutSecs); @@ -182,7 +183,7 @@ int sock_write( /*! [in] Buffer to send data from. */ const char *buffer, /*! [in] Size of the buffer. */ - int bufsize, + size_t bufsize, /*! [in,out] timeout value. */ int *timeoutSecs); diff --git a/upnp/src/inc/ssdplib.h b/upnp/src/inc/ssdplib.h index 40e5b28..b4a8276 100644 --- a/upnp/src/inc/ssdplib.h +++ b/upnp/src/inc/ssdplib.h @@ -354,7 +354,7 @@ int DeviceAdvertisement( /* [in] Service duration in sec. */ int Duration, /* [in] Device address family. */ - int AddressFamily, + unsigned short AddressFamily, /* [in] PowerState as defined by UPnP Low Power. */ int PowerState, /* [in] SleepPeriod as defined by UPnP Low Power. */ @@ -432,7 +432,7 @@ int ServiceAdvertisement( /* [in] Life time of this device. */ int Duration, /* [in] Device address family. */ - int AddressFamily, + unsigned short AddressFamily, /* [in] PowerState as defined by UPnP Low Power. */ int PowerState, /* [in] SleepPeriod as defined by UPnP Low Power. */ @@ -480,7 +480,7 @@ int ServiceShutdown( /* [in] Service duration in sec. */ int Duration, /* [in] Device address family. */ - int AddressFamily, + unsigned short AddressFamily, /* [in] PowerState as defined by UPnP Low Power. */ int PowerState, /* [in] SleepPeriod as defined by UPnP Low Power. */ @@ -508,7 +508,7 @@ int DeviceShutdown( /* [in] Device duration in sec. */ int Duration, /* [in] Device address family. */ - int AddressFamily, + unsigned short AddressFamily, /* [in] PowerState as defined by UPnP Low Power. */ int PowerState, /* [in] SleepPeriod as defined by UPnP Low Power. */ diff --git a/upnp/src/inc/upnpapi.h b/upnp/src/inc/upnpapi.h index 110fda6..f68fa0f 100644 --- a/upnp/src/inc/upnpapi.h +++ b/upnp/src/inc/upnpapi.h @@ -107,7 +107,7 @@ struct Handle_Info /*! . */ int MaxSubscriptionTimeOut; /*! Address family: AF_INET or AF_INET6. */ - int DeviceAf; + unsigned short DeviceAf; #endif /* Client only */ diff --git a/upnp/src/inc/uri.h b/upnp/src/inc/uri.h index 14a3b4e..5018e5e 100644 --- a/upnp/src/inc/uri.h +++ b/upnp/src/inc/uri.h @@ -289,7 +289,7 @@ int parse_hostport( /*! [in] Sets a maximum limit. */ size_t max, /*! [in] The default port if the port is not specified. */ - int defaultPort, + unsigned short int defaultPort, /*! [out] Output parameter where the host and port are represented as * an internet address. */ hostport_type *out); diff --git a/upnp/src/ssdp/ssdp_device.c b/upnp/src/ssdp/ssdp_device.c index d4fb51c..5b16e78 100644 --- a/upnp/src/ssdp/ssdp_device.c +++ b/upnp/src/ssdp/ssdp_device.c @@ -380,7 +380,7 @@ static void CreateServicePacket( nts = "ssdp:byebye"; /* NOTE: The CACHE-CONTROL and LOCATION headers are not present in * a shutdown msg, but are present here for MS WinMe interop. */ - if (AddressFamily == AF_INET) + if (AddressFamily == (unsigned short)AF_INET) host = SSDP_IP; else { if (isUrlV6UlaGua(location)) @@ -430,7 +430,7 @@ static void CreateServicePacket( } int DeviceAdvertisement(char *DevType, int RootDev, char *Udn, char *Location, - int Duration, int AddressFamily, int PowerState, + int Duration, unsigned short AddressFamily, int PowerState, int SleepPeriod, int RegistrationState) { struct sockaddr_storage __ss; @@ -445,12 +445,11 @@ int DeviceAdvertisement(char *DevType, int RootDev, char *Udn, char *Location, UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, "In function DeviceAdvertisement\n"); memset(&__ss, 0, sizeof(__ss)); - memset(Mil_Usn, 0, sizeof(Mil_Usn)); - if (AddressFamily == AF_INET) { + if (AddressFamily == (unsigned short)AF_INET) { DestAddr4->sin_family = (unsigned short)AF_INET; inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); DestAddr4->sin_port = htons(SSDP_PORT); - } else if (AddressFamily == AF_INET6) { + } else if (AddressFamily == (unsigned short)AF_INET6) { DestAddr6->sin6_family = (unsigned short)AF_INET6; inet_pton(AF_INET6, (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : @@ -524,7 +523,6 @@ int SendReply(struct sockaddr *DestAddr, char *DevType, int RootDev, msgs[0] = NULL; msgs[1] = NULL; - memset(Mil_Usn, 0, sizeof(Mil_Usn)); if (RootDev) { /* one msg for root device */ num_msgs = 1; @@ -587,11 +585,10 @@ int DeviceReply(struct sockaddr *DestAddr, char *DevType, int RootDev, szReq[0] = NULL; szReq[1] = NULL; szReq[2] = NULL; - memset(Mil_Nt, 0, sizeof(Mil_Nt)); - memset(Mil_Usn, 0, sizeof(Mil_Usn)); /* create 2 or 3 msgs */ if (RootDev) { /* 3 replies for root device */ + memset(Mil_Nt, 0, sizeof(Mil_Nt)); strncpy(Mil_Nt, "upnp:rootdevice", sizeof(Mil_Nt) - 1); rc = snprintf(Mil_Usn, sizeof(Mil_Usn), "%s::upnp:rootdevice", Udn); if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn)) @@ -641,8 +638,8 @@ error_handler: } int ServiceAdvertisement(char *Udn, char *ServType, char *Location, - int Duration, int AddressFamily, int PowerState, - int SleepPeriod, int RegistrationState) + int Duration, unsigned short AddressFamily, + int PowerState, int SleepPeriod, int RegistrationState) { char Mil_Usn[LINE_SIZE]; char *szReq[1]; @@ -653,14 +650,13 @@ int ServiceAdvertisement(char *Udn, char *ServType, char *Location, int rc = 0; memset(&__ss, 0, sizeof(__ss)); - memset(Mil_Usn, 0, sizeof(Mil_Usn)); szReq[0] = NULL; - if (AddressFamily == AF_INET) { - DestAddr4->sin_family = (unsigned short)AF_INET; + if (AddressFamily == (unsigned short)AF_INET) { + DestAddr4->sin_family = AddressFamily; inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); DestAddr4->sin_port = htons(SSDP_PORT); - } else if (AddressFamily == AF_INET6) { - DestAddr6->sin6_family = (unsigned short)AF_INET6; + } else if (AddressFamily == (unsigned short)AF_INET6) { + DestAddr6->sin6_family = AddressFamily; inet_pton(AF_INET6, (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); @@ -698,7 +694,6 @@ int ServiceReply(struct sockaddr *DestAddr, char *ServType, char *Udn, int RetVal = UPNP_E_OUTOF_MEMORY; int rc = 0; - memset(Mil_Usn, 0, sizeof(Mil_Usn)); szReq[0] = NULL; rc = snprintf(Mil_Usn, sizeof(Mil_Usn), "%s::%s", Udn, ServType); if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn)) @@ -717,8 +712,8 @@ error_handler: } int ServiceShutdown(char *Udn, char *ServType, char *Location, int Duration, - int AddressFamily, int PowerState, int SleepPeriod, - int RegistrationState) + unsigned short AddressFamily, int PowerState, + int SleepPeriod, int RegistrationState) { char Mil_Usn[LINE_SIZE]; char *szReq[1]; @@ -729,14 +724,13 @@ int ServiceShutdown(char *Udn, char *ServType, char *Location, int Duration, int rc = 0; memset(&__ss, 0, sizeof(__ss)); - memset(Mil_Usn, 0, sizeof(Mil_Usn)); szReq[0] = NULL; - if (AddressFamily == AF_INET) { - DestAddr4->sin_family = AF_INET; + if (AddressFamily == (unsigned short)AF_INET) { + DestAddr4->sin_family = AddressFamily; inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); DestAddr4->sin_port = htons(SSDP_PORT); - } else if (AddressFamily == AF_INET6) { - DestAddr6->sin6_family = AF_INET6; + } else if (AddressFamily == (unsigned short)AF_INET6) { + DestAddr6->sin6_family = AddressFamily; inet_pton(AF_INET6, (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); @@ -766,7 +760,7 @@ error_handler: } int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *_Server, - char *Location, int Duration, int AddressFamily, + char *Location, int Duration, unsigned short AddressFamily, int PowerState, int SleepPeriod, int RegistrationState) { struct sockaddr_storage __ss; @@ -781,13 +775,12 @@ int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *_Server, msgs[1] = NULL; msgs[2] = NULL; memset(&__ss, 0, sizeof(__ss)); - memset(Mil_Usn, 0, sizeof(Mil_Usn)); - if (AddressFamily == AF_INET) { - DestAddr4->sin_family = (unsigned short)AF_INET; + if (AddressFamily == (unsigned short)AF_INET) { + DestAddr4->sin_family = AddressFamily; inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); DestAddr4->sin_port = htons(SSDP_PORT); - } else if (AddressFamily == AF_INET6) { - DestAddr6->sin6_family = (unsigned short)AF_INET6; + } else if (AddressFamily == (unsigned short)AF_INET6) { + DestAddr6->sin6_family = AddressFamily; inet_pton(AF_INET6, (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);