From cb9434a5a9efbd0744555fa3d1208562009586f7 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:13:52 +0200 Subject: [PATCH 01/14] [os_net] update makefile --- src/os_net/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/os_net/Makefile b/src/os_net/Makefile index 72b3a82bf..c9f29458b 100755 --- a/src/os_net/Makefile +++ b/src/os_net/Makefile @@ -6,13 +6,13 @@ NAME=os_net include ../Config.Make +HEAD = os_net.h SRCS = os_net.c OBJS = os_net.o -net: - $(CC) $(CFLAGS) -c $(SRCS) - ar cru os_net.a ${OBJS} - ranlib os_net.a +os_net.a: + ${CC} ${CFLAGS} -c ${SRCS} + ${BUILDLIB} os_net.a ${OBJS} clean: ${CLEAN} From d1e7d613cafbd36b18e946c512f8e9819204d029 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:15:15 +0200 Subject: [PATCH 02/14] [os_net] fix CID 28487 --- src/os_net/os_net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index 096e0d9b5..0277d2818 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -215,7 +215,7 @@ int OS_ConnectUnixDomain(char * path, int max_msg_size) n_us.sun_family = AF_UNIX; /* Setting up path */ - strncpy(n_us.sun_path,path,sizeof(n_us.sun_path)-1); + strncpy(n_us.sun_path,path,sizeof(n_us.sun_path)-1); if((ossock = socket(PF_UNIX, SOCK_DGRAM,0)) < 0) return(OS_SOCKTERR); @@ -241,7 +241,7 @@ int OS_ConnectUnixDomain(char * path, int max_msg_size) } - /* Returning the socket */ + /* Returning the socket */ return(ossock); } @@ -411,7 +411,7 @@ int OS_AcceptTCP(int socket, char *srcip, int addrsize) if((clientsocket = accept(socket, (struct sockaddr *) &_nc, &_ncl)) < 0) - return(-1); + return(-1); strncpy(srcip, inet_ntoa(_nc.sin_addr),addrsize -1); srcip[addrsize -1]='\0'; @@ -475,7 +475,10 @@ char *OS_RecvUDP(int socket, int sizet) return(NULL); if((recv(socket,ret,sizet-1,0))<0) + { + free(ret); return(NULL); + } return(ret); } From 50eb048e0ca208463b780e2e5bb61f6e3c609c47 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:20:26 +0200 Subject: [PATCH 03/14] [os_net] add function for closing sockets --- src/os_net/os_net.c | 9 +++++++++ src/os_net/os_net.h | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index 0277d2818..8fca7a090 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -571,4 +571,13 @@ char *OS_GetHost(char *host, int attempts) return(NULL); } +int OS_CloseSocket(int socket) +{ + #ifdef WIN32 + return (closesocket(socket)); + #else + return (close(socket)); + #endif /* WIN32 */ +} + /* EOF */ diff --git a/src/os_net/os_net.h b/src/os_net/os_net.h index 33d27fb77..f5a185545 100755 --- a/src/os_net/os_net.h +++ b/src/os_net/os_net.h @@ -80,6 +80,13 @@ int OS_SendUDPbySize(int socket, int size, char *msg); */ char *OS_GetHost(char *host, int attempts); +/** + * Close a network socket. + * @param socket the socket to close + * @return 0 on success, else -1 or SOCKET_ERROR + */ +int OS_CloseSocket(int socket); + #endif /* EOF */ From ef1f6eb6a72bc52fd220133faec26a6d380e659e Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:23:37 +0200 Subject: [PATCH 04/14] [os_net] fix CID 28486 --- src/os_net/os_net.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index 8fca7a090..a6f4d87dc 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -80,6 +80,7 @@ int OS_Bindport(unsigned int _port, unsigned int _proto, char *_ip, int ipv6) if(setsockopt(ossock, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof(flag)) < 0) { + OS_CloseSocket(ossock); return(OS_SOCKTERR); } } @@ -99,6 +100,7 @@ int OS_Bindport(unsigned int _port, unsigned int _proto, char *_ip, int ipv6) if(bind(ossock, (struct sockaddr *) &server6, sizeof(server6)) < 0) { + OS_CloseSocket(ossock); return(OS_SOCKTERR); } #endif @@ -118,6 +120,7 @@ int OS_Bindport(unsigned int _port, unsigned int _proto, char *_ip, int ipv6) if(bind(ossock, (struct sockaddr *) &server, sizeof(server)) < 0) { + OS_CloseSocket(ossock); return(OS_SOCKTERR); } } @@ -128,6 +131,7 @@ int OS_Bindport(unsigned int _port, unsigned int _proto, char *_ip, int ipv6) { if(listen(ossock, 32) < 0) { + OS_CloseSocket(ossock); return(OS_SOCKTERR); } } From 9f055fa6671e4eb27bf0a9a84a6e196cae7b0242 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:24:30 +0200 Subject: [PATCH 05/14] [os_net] fix CID 28485 --- src/os_net/os_net.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index a6f4d87dc..f1dfa80c7 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -438,7 +438,10 @@ char *OS_RecvTCP(int socket, int sizet) return(NULL); if((retsize = recv(socket, ret, sizet-1,0)) <= 0) + { + free(ret); return(NULL); + } return(ret); } From ee89804ec2f76fdcb1854f575ed06958161004c2 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:26:38 +0200 Subject: [PATCH 06/14] [os_net] fix CID 28484 --- src/os_net/os_net.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index f1dfa80c7..9bb0fc70e 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -304,7 +304,10 @@ int OS_Connect(unsigned int _port, unsigned int protocol, char *_ip, int ipv6) if((_ip == NULL)||(_ip[0] == '\0')) + { + OS_CloseSocket(ossock); return(OS_INVALID); + } if(ipv6 == 1) @@ -316,7 +319,10 @@ int OS_Connect(unsigned int _port, unsigned int protocol, char *_ip, int ipv6) inet_pton(AF_INET6, _ip, &server6.sin6_addr.s6_addr); if(connect(ossock,(struct sockaddr *)&server6, sizeof(server6)) < 0) + { + OS_CloseSocket(ossock); return(OS_SOCKTERR); + } #endif } else @@ -328,7 +334,10 @@ int OS_Connect(unsigned int _port, unsigned int protocol, char *_ip, int ipv6) if(connect(ossock,(struct sockaddr *)&server, sizeof(server)) < 0) + { + OS_CloseSocket(ossock); return(OS_SOCKTERR); + } } From c822ea9d535be9023a44bc458f7bf587907180b6 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:28:08 +0200 Subject: [PATCH 07/14] [os_net] fix CID 28483 --- src/os_net/os_net.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index 9bb0fc70e..2fa6a2184 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -229,12 +229,18 @@ int OS_ConnectUnixDomain(char * path, int max_msg_size) * We can use "send" after that */ if(connect(ossock,(struct sockaddr *)&n_us,SUN_LEN(&n_us)) < 0) + { + OS_CloseSocket(ossock); return(OS_SOCKTERR); + } /* Getting current maximum size */ if(getsockopt(ossock, SOL_SOCKET, SO_SNDBUF, &len, &optlen) == -1) + { + OS_CloseSocket(ossock); return(OS_SOCKTERR); + } /* Setting maximum message size */ From ccf17a575f8e5299912c6a86c6370965ca396b15 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:29:26 +0200 Subject: [PATCH 08/14] [os_net] fix CID 28482 --- src/os_net/os_net.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index 2fa6a2184..426f43d05 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -180,7 +180,7 @@ int OS_BindUnixDomain(char * path, int mode, int max_msg_size) if(bind(ossock, (struct sockaddr *)&n_us, SUN_LEN(&n_us)) < 0) { - close(ossock); + OS_CloseSocket(ossock); return(OS_SOCKTERR); } @@ -190,7 +190,10 @@ int OS_BindUnixDomain(char * path, int mode, int max_msg_size) /* Getting current maximum size */ if(getsockopt(ossock, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1) + { + OS_CloseSocket(ossock); return(OS_SOCKTERR); + } /* Setting socket opt */ From 6cf3f39a2c9f871e2c64327a770b40b0f598a433 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:32:25 +0200 Subject: [PATCH 09/14] [os_net] fix CID 28436 --- src/os_net/os_net.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index 426f43d05..c718216ab 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -470,17 +470,12 @@ char *OS_RecvTCP(int socket, int sizet) */ int OS_RecvTCPBuffer(int socket, char *buffer, int sizet) { - int retsize = 0; + int retsize; - while(!retsize) + if((retsize = recv(socket, buffer, sizet -1, 0)) > 0) { - retsize = recv(socket, buffer, sizet -1, 0); - if(retsize > 0) - { - buffer[retsize] = '\0'; - return(0); - } - return(-1); + buffer[retsize] = '\0'; + return(0); } return(-1); } From 36a149d174da90a2fd4e562d778f7e36f6cdfdd9 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:34:00 +0200 Subject: [PATCH 10/14] [os_net] fix CID 28417 --- src/os_net/os_net.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index c718216ab..e066a0a25 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -250,7 +250,11 @@ int OS_ConnectUnixDomain(char * path, int max_msg_size) if(len < max_msg_size) { len = max_msg_size; - setsockopt(ossock, SOL_SOCKET, SO_SNDBUF, &len, optlen); + if(setsockopt(ossock, SOL_SOCKET, SO_SNDBUF, &len, optlen) < 0) + { + OS_CloseSocket(ossock); + return(OS_SOCKTERR); + } } From 5b3d481059820754a14b83c61e6d1e1bd1bc1213 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:34:39 +0200 Subject: [PATCH 11/14] [os_net] fix CID 28416 --- src/os_net/os_net.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index e066a0a25..57a25f499 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -200,7 +200,11 @@ int OS_BindUnixDomain(char * path, int mode, int max_msg_size) if(len < max_msg_size) { len = max_msg_size; - setsockopt(ossock, SOL_SOCKET, SO_RCVBUF, &len, optlen); + if(setsockopt(ossock, SOL_SOCKET, SO_RCVBUF, &len, optlen) < 0) + { + OS_CloseSocket(ossock); + return(OS_SOCKTERR); + } } return(ossock); From 172ed249685ac3a43a91ccc155628c21f8a3acbe Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:35:33 +0200 Subject: [PATCH 12/14] [os_net] fix CID 28415 --- src/os_net/os_net.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index 57a25f499..42189cdb4 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -185,7 +185,11 @@ int OS_BindUnixDomain(char * path, int mode, int max_msg_size) } /* Changing permissions */ - chmod(path,mode); + if(chmod(path,mode) < 0) + { + OS_CloseSocket(ossock); + return(OS_SOCKTERR); + } /* Getting current maximum size */ From 08cb45f73dfecde0d84a4149ead61e5089a4755d Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:36:59 +0200 Subject: [PATCH 13/14] [os_net] remove unnecessary variable --- src/os_net/os_net.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index 42189cdb4..08e1352ee 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -461,13 +461,11 @@ char *OS_RecvTCP(int socket, int sizet) { char *ret; - int retsize=0; - ret = (char *) calloc((sizet), sizeof(char)); if(ret == NULL) return(NULL); - if((retsize = recv(socket, ret, sizet-1,0)) <= 0) + if(recv(socket, ret, sizet-1,0) <= 0) { free(ret); return(NULL); From ef752d3be30873d8acbfdfc5e1b9368375b87422 Mon Sep 17 00:00:00 2001 From: cgzones Date: Thu, 1 May 2014 11:44:09 +0200 Subject: [PATCH 14/14] [os_net] fix dependency list for make target --- src/os_net/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os_net/Makefile b/src/os_net/Makefile index c9f29458b..143bd6d77 100755 --- a/src/os_net/Makefile +++ b/src/os_net/Makefile @@ -10,7 +10,7 @@ HEAD = os_net.h SRCS = os_net.c OBJS = os_net.o -os_net.a: +os_net.a: ${HEAD} ${SRCS} ${CC} ${CFLAGS} -c ${SRCS} ${BUILDLIB} os_net.a ${OBJS}