aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorgrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2011-05-25 21:41:52 +0000
committergrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2011-05-25 21:41:52 +0000
commit263afe071a2ce9158b778eab08c1049ea4896139 (patch)
tree7a274ea3d3591fe59d724ca691fdc976d0175066 /src/util
parent465907aaa9146a952fe7c56ad6fa0d85c3dde050 (diff)
set sxn_len on FreeBSD where required
git-svn-id: https://gnunet.org/svn/gnunet@15313 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/util')
-rw-r--r--src/util/connection.c9
-rw-r--r--src/util/gnunet-service-resolver.c9
-rw-r--r--src/util/os_network.c10
-rw-r--r--src/util/service.c15
-rw-r--r--src/util/test_resolver_api.c6
-rw-r--r--src/util/test_server_with_client_unix.c3
6 files changed, 41 insertions, 11 deletions
diff --git a/src/util/connection.c b/src/util/connection.c
index ff41a33a8d..09a28923e7 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -376,6 +376,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
memset (v4, 0, sizeof (struct sockaddr_in));
v4->sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ v4->sin_len = (u_char) sizeof (struct sockaddr_in);
+#endif
memcpy (&v4->sin_addr,
&((char *) &v6->sin6_addr)[sizeof (struct in6_addr) -
sizeof (struct in_addr)],
@@ -936,10 +939,12 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
unixpath,
slen);
un->sun_path[slen] = '\0';
- slen += sizeof (sa_family_t);
+ slen = SUN_LEN (un);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ un->sun_len = (u_char) slen;
+#endif
#if LINUX
un->sun_path[0] = '\0';
- slen = sizeof (struct sockaddr_un);
#endif
ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
ret->cfg = cfg;
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index f72b70da75..ee2cfb3b83 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -327,6 +327,9 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
GNUNET_assert (hp->h_length == sizeof (struct in_addr));
memset (&a4, 0, sizeof (a4));
a4.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ a4.sin_len = (u_char) sizeof (struct sockaddr_in);
+#endif
memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length);
GNUNET_SERVER_transmit_context_append_data (tc,
&a4,
@@ -338,6 +341,9 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
GNUNET_assert (hp->h_length == sizeof (struct in6_addr));
memset (&a6, 0, sizeof (a6));
a6.sin6_family = AF_INET6;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
+#endif
memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length);
GNUNET_SERVER_transmit_context_append_data (tc,
&a6,
@@ -372,6 +378,9 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
GNUNET_assert (hp->h_length == sizeof (struct in_addr));
memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ addr.sin_len = (u_char) sizeof (struct sockaddr_in);
+#endif
memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
GNUNET_SERVER_transmit_context_append_data (tc,
&addr,
diff --git a/src/util/os_network.c b/src/util/os_network.c
index 498f6ac9ca..ccf326c05e 100644
--- a/src/util/os_network.c
+++ b/src/util/os_network.c
@@ -148,6 +148,9 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
free (pszIfName);
sa.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ sa.sin_len = (u_char) sizeof (struct sockaddr_in);
+#endif
sa.sin_addr.S_un.S_addr = dwIP;
if (GNUNET_OK !=
@@ -256,6 +259,9 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
{
memset (&a4, 0, sizeof (a4));
a4.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ a4.sin_len = (u_char) sizeof (struct sockaddr_in);
+#endif
a4.sin_addr = v4;
if (GNUNET_OK !=
proc (proc_cls,
@@ -270,8 +276,10 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
{
memset (&a6, 0, sizeof (a6));
a6.sin6_family = AF_INET6;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
+#endif
a6.sin6_addr = v6;
- fprintf (stderr, "procing %s\n", addrstr);
if (GNUNET_OK !=
proc (proc_cls,
ifc,
diff --git a/src/util/service.c b/src/util/service.c
index 834b27dd68..876b35265a 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -766,15 +766,13 @@ add_unixpath (struct sockaddr **saddrs,
unixpath,
slen);
un->sun_path[slen] = '\0';
+ slen = SUN_LEN (un);
#if LINUX
un->sun_path[0] = '\0';
- slen = sizeof (struct sockaddr_un);
-#elif FREEBSD
- slen += sizeof (sa_family_t) + 1 ;
-#else
- slen += sizeof (sa_family_t) ;
#endif
-
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ un->sun_len = (u_char) slen;
+#endif
*saddrs = (struct sockaddr*) un;
*saddrlens = slen;
#else
@@ -909,6 +907,7 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
{
/* probe UNIX support */
struct sockaddr_un s_un;
+
if (strlen(unixpath) >= sizeof(s_un.sun_path))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -923,8 +922,8 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
if (NULL == desc)
{
- if ((errno == ENOBUFS) ||
- (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES))
+ if ( (errno == ENOBUFS) ||
+ (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
GNUNET_free_non_null (hostname);
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index b897a6c13c..cd3e42d230 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -229,6 +229,9 @@ run(void *cls, char * const *args,
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ sa.sin_len = (u_char) sizeof (sa);
+#endif
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
GNUNET_RESOLVER_ip_get(cfg, "localhost", AF_INET, timeout, &check_127,
cls);
@@ -343,6 +346,9 @@ run(void *cls, char * const *args,
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ sa.sin_len = (u_char) sizeof (sa);
+#endif
#ifndef MINGW
inet_aton(ROOTSERVER_IP, &sa.sin_addr);
#else
diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c
index 8c0e4b84c8..98a530a193 100644
--- a/src/util/test_server_with_client_unix.c
+++ b/src/util/test_server_with_client_unix.c
@@ -142,6 +142,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
un.sun_family = AF_UNIX;
memcpy (un.sun_path, unixpath, slen);
un.sun_path[slen] = '\0';
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ un.sun_len = (u_char) SUN_LEN (&un);
+#endif
#if LINUX
un.sun_path[0] = '\0';
#endif