summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2013-06-30 11:24:17 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-06-30 11:24:17 +0000
commit364a65badb4f36a4cb3a76d2946f13899b4665c6 (patch)
tree065dfba5d90a2a60e13f431040379274447f88fc
parent87b7ee9e740940881b0a431f5149512091ff1bcd (diff)
Fix socketio
* Makefile (CFLAGS): Add -Wall * socketio.c (xgethostbyname): Use bigger start size, 8 currently gets INVAL from glibc. (node_socket_open): Initialize `sock' to MACH_PORT_NULL; (node_socket_open): Add default case. (socket_open): Do not free `buf' on error.
-rw-r--r--Makefile2
-rw-r--r--socketio.c11
2 files changed, 8 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index f029d5ea3..b8531837b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,3 @@
-CFLAGS=-D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O2
+CFLAGS=-D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O2 -Wall
LDLIBS=-lnetfs -lfshelp -liohelp -lports -lshouldbeinlibc
all: socketio
diff --git a/socketio.c b/socketio.c
index 9d578f344..0bcf29b21 100644
--- a/socketio.c
+++ b/socketio.c
@@ -191,7 +191,7 @@ xgethostbyname (char *hostname, struct hostent *hostaddr, char **buf)
char *tmp_hostbuf;
int herr, err;
- hostbuf_len = 8;
+ hostbuf_len = 64;
tmp_hostbuf = malloc (hostbuf_len);
if (! tmp_hostbuf)
return ENOMEM;
@@ -373,7 +373,7 @@ node_socket_open (struct iouser *user, struct node *np, char *netport_s,
{
uint16_t netport = strtol (netport_s, NULL, 10);
char *hostname = np->nn->hostname;
- socket_t sock;
+ socket_t sock = MACH_PORT_NULL;
error_t err;
int style;
@@ -385,6 +385,8 @@ node_socket_open (struct iouser *user, struct node *np, char *netport_s,
case PROTOCOL_ID_UDP:
style = SOCK_DGRAM;
break;
+ default:
+ return EINVAL;
}
err = socket_open (style, hostname, netport, &sock);
@@ -435,9 +437,10 @@ socket_open (int style, char *hostname, uint16_t netport,
char *buf;
err = xgethostbyname (hostname, &hostaddr, &buf);
- if (! err)
+ if (! err) {
sockaddr_init (addr, AF_INET, &hostaddr, netport);
- free (buf);
+ free (buf);
+ }
if (! err)
err = socket_create (socket_server, style, 0, &sock);
if (! err)