diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-01-24 19:13:57 +0100 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-01-24 19:21:19 +0100 |
commit | 305bd8b2e51b844cdc68932670580b2c75716b52 (patch) | |
tree | b6983ccaade18b21903255341f9e8cdf08d65221 | |
parent | 3c1bc4c9e8764d2301765943fcb4f0d17364c00a (diff) |
proper sockaddr_un len calculation
-rw-r--r-- | main.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -19,6 +19,7 @@ #include <stdint.h> #include <string.h> #include <stdlib.h> +#include <stddef.h> #include <time.h> #ifdef __linux__ #include <sys/prctl.h> @@ -251,7 +252,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; @@ -504,7 +506,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; |