View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001989 | GNUnet | util library | public | 2011-12-07 12:22 | 2012-02-28 11:05 |
| Reporter | Matthias Wachs | Assigned To | Matthias Wachs | ||
| Priority | normal | Severity | feature | Reproducibility | have not tried |
| Status | closed | Resolution | open | ||
| Product Version | 0.9.0 | ||||
| Target Version | 0.9.2 | Fixed in Version | 0.9.2 | ||
| Summary | 0001989: implement broadcast and netmask retrieval | ||||
| Description | implement broadcast and netmask retrieval in os_interface for the text-parsing fallback method | ||||
| Tags | No tags attached. | ||||
| Attached Files | parse_broadcast_address_and_netmask_output_from_ifconfig.diff (4,041 bytes)
Index: src/util/os_network.c
===================================================================
--- src/util/os_network.c (revision 19488)
+++ src/util/os_network.c (working copy)
@@ -101,17 +101,26 @@
freeifaddrs (ifa_first);
}
#else
+ int i;
char line[1024];
+ char *replace;
const char *start;
char ifc[12];
char addrstr[128];
char bcstr[128];
+ char netmaskstr[128];
FILE *f;
int have_ifc;
struct sockaddr_in a4;
struct sockaddr_in6 a6;
struct in_addr v4;
struct in6_addr v6;
+ struct sockaddr_in bcaddr;
+ struct sockaddr_in netmask;
+ struct sockaddr_in6 netmask6;
+ struct sockaddr *pass_bcaddr;
+ struct sockaddr *pass_netmask;
+ int prefixlen;
if (system ("ifconfig -a > /dev/null 2> /dev/null"))
if (system ("/sbin/ifconfig -a > /dev/null 2> /dev/null") == 0)
@@ -146,12 +155,21 @@
}
if (!have_ifc)
continue; /* strange input, hope for the best */
+
+ /* make parsing of ipv6 addresses easier */
+ for (replace = line; *replace != '\0'; replace++)
+ {
+ if (*replace == '/')
+ *replace = ' ';
+ }
+ prefixlen = -1;
+
start = line;
while (('\0' != *start) && (isspace (*start)))
start++;
if ( /* Linux */
- (2 == SSCANF (start, "inet addr:%127s Bcast:%127s", addrstr, bcstr)) ||
- (1 == SSCANF (start, "inet6 addr:%127s", addrstr)) ||
+ (3 == SSCANF (start, "inet addr:%127s Bcast:%127s Mask:%127s", addrstr, bcstr, netmaskstr)) ||
+ (2 == SSCANF (start, "inet6 addr:%127s %d", addrstr, &prefixlen)) ||
/* Solaris, OS X */
(1 == SSCANF (start, "inet %127s", addrstr)) ||
(1 == SSCANF (start, "inet6 %127s", addrstr)))
@@ -165,11 +183,34 @@
a4.sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
a4.sin_addr = v4;
+
+ pass_bcaddr = NULL;
+ pass_netmask = NULL;
+ if (1 == inet_pton (AF_INET, bcstr, &v4))
+ {
+ memset (&bcaddr, 0, sizeof (bcaddr));
+ bcaddr.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ bcaddr.sin_len = (u_char) sizeof (struct sockaddr_in);
+#endif
+ bcaddr.sin_addr = v4;
+ pass_bcaddr = (struct sockaddr *) &bcaddr;
+ }
+ if (1 == inet_pton (AF_INET, netmaskstr, &v4))
+ {
+ memset (&netmask, 0, sizeof (netmask));
+ netmask.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ netmask.sin_len = (u_char) sizeof (struct sockaddr_in);
+#endif
+ netmask.sin_addr = v4;
+ pass_bcaddr = (struct sockaddr *) &netmask;
+ }
+
if (GNUNET_OK !=
proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
(const struct sockaddr *) &a4,
- /* TODO broadcast and netmask */
- NULL, NULL, sizeof (a4)))
+ pass_bcaddr, pass_netmask, sizeof (a4)))
break;
continue;
}
@@ -182,11 +223,30 @@
a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
#endif
a6.sin6_addr = v6;
+
+ pass_netmask = NULL;
+ if (prefixlen != -1)
+ {
+ memset (v6.s6_addr, 0, sizeof (v6.s6_addr));
+ for (i = 0; i < prefixlen; i++)
+ {
+ v6.s6_addr[i >> 3] |= 1 << (i & 7);
+ }
+ memset (&netmask6, 0, sizeof (netmask6));
+ netmask6.sin6_family = AF_INET6;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ netmask6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
+#endif
+ netmask6.sin6_addr = v6;
+
+ pass_netmask = (struct sockaddr *) &netmask;
+ }
+
if (GNUNET_OK !=
proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
(const struct sockaddr *) &a6,
/* TODO broadcast and netmask */
- NULL, NULL, sizeof (a6)))
+ NULL, pass_netmask, sizeof (a6)))
break;
continue;
}
| ||||
| child of | 0001990 | closed | Matthias Wachs | Implement WAN/LAN detection in plugins |
|
|
W32: done Syscall: done fallback textparsing: done |
|
|
E-mail from himthingwatsit@gmail.com about the attached patch: Hi people. I'm completely new to GNUnet but I thought I'd have a try at one of the introductory tasks for GNUnet hackers listed on your website. Attached is a proposed patch for this [https://gnunet.org/bugs/view.php?id=1989] bug. I don't know whether this actually works because I'm not entirely sure that I tested it correctly. However, after making these changed and forcing it to use the ifconfig failover code by changing the #elif on line 73, I was able to build, install and do a few basic things like look at my peerinfo and search for files. |
|
|
Patch applied in 19568 Fixed bugs in patch: - IPv4 loopback address was not included: added line 179 - stack allocated strings were not zeroed out, so last value was used if value was not included in current line - IPv4 netmask was passed as broadcast address (patch line 81) - IPv4 netmask was passed as IPv6 netmask, caused invalid address conversion (patch line 113) |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2011-12-07 12:22 | Matthias Wachs | New Issue | |
| 2011-12-08 16:55 | Christian Grothoff | Relationship added | child of 0001990 |
| 2011-12-14 14:44 | Matthias Wachs | Note Added: 0005099 | |
| 2011-12-14 14:44 | Matthias Wachs | Status | new => confirmed |
| 2011-12-19 14:22 | Christian Grothoff | Product Version | => 0.9.0 |
| 2011-12-19 14:22 | Christian Grothoff | Target Version | => 0.9.1 |
| 2011-12-26 17:57 | Christian Grothoff | Target Version | 0.9.1 => 0.9.2 |
| 2012-01-22 21:20 | Christian Grothoff | Target Version | 0.9.2 => 0.9.3 |
| 2012-01-29 18:11 | Christian Grothoff | File Added: parse_broadcast_address_and_netmask_output_from_ifconfig.diff | |
| 2012-01-29 18:12 | Christian Grothoff | Note Added: 0005400 | |
| 2012-01-29 18:12 | Christian Grothoff | Target Version | 0.9.3 => 0.9.2 |
| 2012-01-31 14:15 | Matthias Wachs | Note Added: 0005413 | |
| 2012-01-31 14:15 | Matthias Wachs | Note Edited: 0005099 | |
| 2012-01-31 14:15 | Matthias Wachs | Status | confirmed => resolved |
| 2012-01-31 16:34 | Christian Grothoff | Fixed in Version | => 0.9.2 |
| 2012-02-12 21:25 | Christian Grothoff | Assigned To | => Matthias Wachs |
| 2012-02-28 11:05 | Christian Grothoff | Status | resolved => closed |