Correctly return multiple IPv6 addresses.

This commit is contained in:
Martin Baulig
2000-01-28 22:25:59 +00:00
parent 00a9f98ee0
commit 8892637796

View File

@@ -184,7 +184,7 @@ _parse_ipv6_address (const char *addr_string, u_int8_t *dest)
if (strlen (addr_string) != 32) if (strlen (addr_string) != 32)
return -1; return -1;
for (i = 0; i < 8; i++) { for (i = 0; i < 16; i++) {
char c1, c2; char c1, c2;
int d1, d2; int d1, d2;
@@ -213,7 +213,7 @@ _parse_ipv6_address (const char *addr_string, u_int8_t *dest)
static int static int
_netinfo_ipv6 (glibtop *server, glibtop_netinfo *buf, _netinfo_ipv6 (glibtop *server, glibtop_netinfo *buf,
const char *interface, glibtop_ifaddr *address) const char *interface, GPtrArray *parray)
{ {
FILE *f; FILE *f;
char addr6[40], devname[20]; char addr6[40], devname[20];
@@ -231,29 +231,31 @@ _netinfo_ipv6 (glibtop *server, glibtop_netinfo *buf,
while (fscanf (f, "%64s %02x %02x %02x %02x %20s\n", while (fscanf (f, "%64s %02x %02x %02x %02x %20s\n",
addr6, &if_idx, &plen, &scope, &dad_status, addr6, &if_idx, &plen, &scope, &dad_status,
devname) != EOF) { devname) != EOF) {
glibtop_ifaddr address;
memset (&address, 0, sizeof (glibtop_ifaddr));
if (strcmp (devname, interface)) if (strcmp (devname, interface))
continue; continue;
if (!_parse_ipv6_address (addr6, address->address)) if (!_parse_ipv6_address (addr6, address.address))
address->flags |= (1L << GLIBTOP_IFADDR_ADDRESS); address.flags |= (1L << GLIBTOP_IFADDR_ADDRESS);
address->transport = GLIBTOP_TRANSPORT_IPV6; address.transport = GLIBTOP_TRANSPORT_IPV6;
address->addr_len = 8; address.addr_len = plen;
address->scope = scope; address.scope = scope;
address->flags |= (1L << GLIBTOP_IFADDR_TRANSPORT) | address.flags |= (1L << GLIBTOP_IFADDR_TRANSPORT) |
(1L << GLIBTOP_IFADDR_ADDR_LEN) | (1L << GLIBTOP_IFADDR_ADDR_LEN) |
(1L << GLIBTOP_IFADDR_SCOPE); (1L << GLIBTOP_IFADDR_SCOPE);
fclose (f); g_ptr_array_add (parray, g_memdup (&address, sizeof (address)));
return 0;
} }
} }
fclose (f); fclose (f);
return -1; return 0;
} }
#endif /* HAVE_AFINET6 */ #endif /* HAVE_AFINET6 */
@@ -315,20 +317,15 @@ glibtop_get_netinfo_s (glibtop *server, glibtop_array *array,
memset (&address, 0, sizeof (glibtop_ifaddr)); memset (&address, 0, sizeof (glibtop_ifaddr));
if (!_netinfo_ipv4 (server, buf, interface, &address)) _netinfo_ipv4 (server, buf, interface, &address);
if (address.flags & (1L << GLIBTOP_IFADDR_ADDRESS))
g_ptr_array_add (parray, g_memdup (&address, sizeof (address))); g_ptr_array_add (parray, g_memdup (&address, sizeof (address)));
} }
#endif /* HAVE_AFINET */ #endif /* HAVE_AFINET */
#ifdef HAVE_AFINET6 #ifdef HAVE_AFINET6
if (transport & GLIBTOP_TRANSPORT_IPV6) { if (transport & GLIBTOP_TRANSPORT_IPV6)
glibtop_ifaddr address; _netinfo_ipv6 (server, buf, interface, parray);
memset (&address, 0, sizeof (glibtop_ifaddr));
if (!_netinfo_ipv6 (server, buf, interface, &address))
g_ptr_array_add (parray, g_memdup (&address, sizeof (address)));
}
#endif /* HAVE_AFINET6 */ #endif /* HAVE_AFINET6 */
if (!parray->len) { if (!parray->len) {