From d83b0472cb523da8be245cd1f7f12f29c8023faa Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sun, 24 Jan 2010 19:13:57 +0100 Subject: proper sockaddr_un len calculation --- main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index b283f5a3..b979b011 100644 --- a/main.c +++ b/main.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #ifdef __linux__ #include @@ -249,7 +250,8 @@ server_start (void) { // snprintf (srv_local.sun_path, sizeof (srv_local.sun_path), "%s/socket", dbconfdir); // unlink(srv_local.sun_path); memcpy (srv_local.sun_path, server_id, sizeof (server_id)); - int len = sizeof (srv_local); + //int len = sizeof (srv_local); + int len = offsetof(struct sockaddr_un, sun_path) + sizeof (server_id); if (bind(srv_socket, (struct sockaddr *)&srv_local, len) < 0) { perror ("bind"); return -1; @@ -502,7 +504,8 @@ main (int argc, char *argv[]) { memcpy (remote.sun_path, server_id, sizeof (server_id)); // snprintf (remote.sun_path, 108, "%s/socket", dbconfdir); // len = strlen(remote.sun_path) + sizeof(remote.sun_family); - len = sizeof (remote); + //len = sizeof (remote); + len = offsetof(struct sockaddr_un, sun_path) + sizeof (server_id); if (connect(s, (struct sockaddr *)&remote, len) == 0) { if (argc <= 1) { cmdline[0] = 0; -- cgit v1.2.3