summaryrefslogtreecommitdiff
path: root/src/common/socket.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-01-20 04:36:08 +0100
committerHaru <haru@dotalux.com>2015-01-20 04:41:33 +0100
commit4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4 (patch)
treedab9d12a6a4b95a37598e27e6e86d6047360d61b /src/common/socket.c
parent03709c136ad300be631adfd38dc36c2433bda718 (diff)
downloadhercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.tar.gz
hercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.tar.bz2
hercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.tar.xz
hercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.zip
Minor fixes and tweaks suggested by cppcheck
- Variable scopes reduced - Parenthesized ambiguous expressions - Removed or added NULL checks where (un)necessary - Corrected format strings - Fixed typos potentially leading to bugs Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/socket.c')
-rw-r--r--src/common/socket.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/src/common/socket.c b/src/common/socket.c
index 600666d21..9fe08e6f1 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -624,7 +624,6 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF
static void delete_session(int fd)
{
if( sockt->session_isValid(fd) ) {
- unsigned int i;
#ifdef SHOW_SERVER_STATS
socket_data_qi -= session[fd]->rdata_size - session[fd]->rdata_pos;
socket_data_qo -= session[fd]->wdata_size;
@@ -633,8 +632,8 @@ static void delete_session(int fd)
aFree(session[fd]->wdata);
if( session[fd]->session_data )
aFree(session[fd]->session_data);
- if( session[fd]->hdata )
- {
+ if (session[fd]->hdata) {
+ unsigned int i;
for(i = 0; i < session[fd]->hdatac; i++) {
if( session[fd]->hdata[i]->flag.free ) {
aFree(session[fd]->hdata[i]->data);
@@ -1249,38 +1248,31 @@ int socket_getips(uint32* ips, int max)
#ifdef WIN32
{
char fullhost[255];
- u_long** a;
- struct hostent* hent;
// XXX This should look up the local IP addresses in the registry
// instead of calling gethostbyname. However, the way IP addresses
// are stored in the registry is annoyingly complex, so I'll leave
// this as T.B.D. [Meruru]
- if( gethostname(fullhost, sizeof(fullhost)) == SOCKET_ERROR )
- {
+ if (gethostname(fullhost, sizeof(fullhost)) == SOCKET_ERROR) {
ShowError("socket_getips: No hostname defined!\n");
return 0;
- }
- else
- {
- hent = gethostbyname(fullhost);
+ } else {
+ u_long** a;
+ struct hostent *hent =gethostbyname(fullhost);
if( hent == NULL ){
ShowError("socket_getips: Cannot resolve our own hostname to an IP address\n");
return 0;
}
a = (u_long**)hent->h_addr_list;
- for( ; a[num] != NULL && num < max; ++num)
+ for (; num < max && a[num] != NULL; ++num)
ips[num] = (uint32)ntohl(*a[num]);
}
}
#else // not WIN32
{
- int pos;
int fd;
char buf[2*16*sizeof(struct ifreq)];
struct ifconf ic;
- struct ifreq* ir;
- struct sockaddr_in* a;
u_long ad;
fd = sSocket(AF_INET, SOCK_STREAM, 0);
@@ -1291,21 +1283,18 @@ int socket_getips(uint32* ips, int max)
// interfaces than will fit in the buffer
ic.ifc_len = sizeof(buf);
ic.ifc_buf = buf;
- if( sIoctl(fd, SIOCGIFCONF, &ic) == -1 )
- {
+ if (sIoctl(fd, SIOCGIFCONF, &ic) == -1) {
ShowError("socket_getips: SIOCGIFCONF failed!\n");
sClose(fd);
return 0;
- }
- else
- {
- for( pos=0; pos < ic.ifc_len && num < max; )
- {
- ir = (struct ifreq*)(buf+pos);
- a = (struct sockaddr_in*) &(ir->ifr_addr);
- if( a->sin_family == AF_INET ){
+ } else {
+ int pos;
+ for (pos = 0; pos < ic.ifc_len && num < max; ) {
+ struct ifreq *ir = (struct ifreq*)(buf+pos);
+ struct sockaddr_in *a = (struct sockaddr_in*) &(ir->ifr_addr);
+ if (a->sin_family == AF_INET) {
ad = ntohl(a->sin_addr.s_addr);
- if( ad != INADDR_LOOPBACK && ad != INADDR_ANY )
+ if (ad != INADDR_LOOPBACK && ad != INADDR_ANY)
ips[num++] = (uint32)ad;
}
#if (defined(BSD) && BSD >= 199103) || defined(_AIX) || defined(__APPLE__)