gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r20732 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r20732 - gnunet/src/transport
Date: Fri, 23 Mar 2012 17:39:06 +0100

Author: wachs
Date: 2012-03-23 17:39:06 +0100 (Fri, 23 Mar 2012)
New Revision: 20732

Modified:
   gnunet/src/transport/plugin_transport_http.c
Log:
- code deduplication 


Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c        2012-03-23 16:39:05 UTC 
(rev 20731)
+++ gnunet/src/transport/plugin_transport_http.c        2012-03-23 16:39:06 UTC 
(rev 20732)
@@ -741,14 +741,12 @@
   }
 }
 
-static void
-nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
-                 socklen_t addrlen)
+static void *
+find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t 
addrlen)
 {
-  struct Plugin *plugin = cls;
+  int af;
   struct IPv4HttpAddressWrapper *w_t4 = NULL;
   struct IPv6HttpAddressWrapper *w_t6 = NULL;
-  int af;
 
   af = addr->sa_family;
   switch (af)
@@ -773,8 +771,52 @@
         break;
       w_t4 = w_t4->next;
     }
+    return w_t4;
+    break;
+  case AF_INET6:
+    w_t6 = plugin->ipv6_addr_head;
+    struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
+
+    while (w_t6)
+    {
+      int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
+                        sizeof (struct in6_addr));
+
+      if (res == 0)
+      {
+        if (a6->sin6_port != w_t6->addr6.u6_port)
+          res = -1;
+      }
+      if (0 == res)
+        break;
+      w_t6 = w_t6->next;
+    }
+    return w_t6;
+    break;
+  default:
+    return NULL;
+  }
+
+
+}
+
+static void
+nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
+                 socklen_t addrlen)
+{
+  struct Plugin *plugin = cls;
+  struct IPv4HttpAddressWrapper *w_t4 = NULL;
+  struct IPv6HttpAddressWrapper *w_t6 = NULL;
+  int af;
+
+  af = addr->sa_family;
+  switch (af)
+  {
+  case AF_INET:
+    w_t4 = find_address (plugin, addr, addrlen);
     if (w_t4 == NULL)
     {
+      struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
       w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
       memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
       w_t4->addr.u4_port = a4->sin_port;
@@ -794,27 +836,11 @@
 
     break;
   case AF_INET6:
-    w_t6 = plugin->ipv6_addr_head;
-    struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
-
-    while (w_t6)
-    {
-      int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
-                        sizeof (struct in6_addr));
-
-      if (res == 0)
-      {
-        if (a6->sin6_port != w_t6->addr6.u6_port)
-          res = -1;
-      }
-      if (0 == res)
-        break;
-      w_t6 = w_t6->next;
-    }
+    w_t6 = find_address (plugin, addr, addrlen);
     if (w_t6 == NULL)
     {
       w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
-
+      struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
       memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct 
in6_addr));
       w_t6->addr6.u6_port = a6->sin6_port;
 
@@ -850,26 +876,7 @@
   switch (af)
   {
   case AF_INET:
-    w_t4 = plugin->ipv4_addr_head;
-    struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
-
-    while (w_t4 != NULL)
-    {
-      int res = memcmp (&w_t4->addr.ipv4_addr,
-                        &a4->sin_addr,
-                        sizeof (struct in_addr));
-
-      if (res == 0)
-      {
-        if (a4->sin_port != w_t4->addr.u4_port)
-          res = -1;
-      }
-
-      if (0 == res)
-        break;
-      w_t4 = w_t4->next;
-    }
-    if (w_t4 == NULL)
+    w_t4 = find_address (plugin, addr, addrlen);
       return;
 
 #if DEBUG_HTTP
@@ -887,23 +894,7 @@
     GNUNET_free (w_t4);
     break;
   case AF_INET6:
-    w_t6 = plugin->ipv6_addr_head;
-    struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
-
-    while (w_t6)
-    {
-      int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
-                        sizeof (struct in6_addr));
-
-      if (res == 0)
-      {
-        if (a6->sin6_port != w_t6->addr6.u6_port)
-          res = -1;
-      }
-      if (0 == res)
-        break;
-      w_t6 = w_t6->next;
-    }
+    w_t6 = find_address (plugin, addr, addrlen);
     if (w_t6 == NULL)
       return;
 #if DEBUG_HTTP




reply via email to

[Prev in Thread] Current Thread [Next in Thread]