Hi -
On 2016-04-13 at 23:02 ron minnich <[email protected]> wrote:
> Comments welcome or, if none, that's fine too.
A couple minor things:
> From 261397311206e8c23a4a7b03b3849f40341a0147 Mon Sep 17 00:00:00 2001
> diff --git a/tests/getifaddrs.c b/tests/getifaddrs.c
> +int mygetifaddrs(struct ifaddrs **ifap)
> +{
> + DIR *net;
> + struct dirent *d;
> + int addr;
> + static char etheraddr[MAX_PATH_LEN];
That static char[] should be just a char[], o/w we'll have problems with
concurrent calls to this functio.
> + struct ifaddrs *ifa;
> + uint8_t *v;
> +
> + *ifap = NULL;
> +
> + net = opendir("/net");
> + if (net == NULL) {
> + fprintf(stderr, "/net: %r");
> + return -1;
> + }
> +
> + for (d = readdir(net); d; d = readdir(net)) {
readdir() isn't threadsafe.
> + if (strncmp(d->d_name, "ether", 5))
> + continue;
> + sprintf(etheraddr, "/net/%s/addr", d->d_name);
> + addr = open(etheraddr, O_RDONLY);
> + if (addr < 0)
> + continue;
> + if (read(addr, etheraddr, 24) < 0) {
> + fprintf(stderr, "Read addr from %s: %r", d->d_name);
probably need to close the addr FD here. actually, you don't close it
down below either, so you can just do something like:
ret = read(addr, etheraddr, 24)
close(addr)
if (ret < 0)
error out;
> + continue;
> + }
> + /* getifaddrds is a stupid design as it only admits of
> + * one address per interface. Don't even bother
> + * filling in ifa_{addr,netmask}. They're allowed to
> + * be NULL. Broadaddr need be set IFF a bit is set
> + * in the flags field. We don't set either one.
> + */
Will we have issues without having ifa_addr filled in? The test below
checks for it. Though I ran the same test code on my linux box and got
AF_PACKET for all of my interfaces. Not sure if that's right or not.
> +int myfreeifaddrs(struct ifaddrs *ifa)
> +{
> + free(ifa);
Also need to free the entire linked list of ifas, and not just the first ifa.
Barret
--
You received this message because you are subscribed to the Google Groups
"Akaros" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.