summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2010-05-03 16:07:57 -0700
committerSam Roberts <vieuxtech@gmail.com>2010-05-03 16:07:57 -0700
commit56e3b06a535cfea19ee433510601e40a8facde60 (patch)
treea5e591595f76f7594c16c7a4107f1798dc789c3c
parent933c8a02fcfbfbf64dfa20e4cb10e378408bc6b1 (diff)
downloadlibnet-56e3b06a535cfea19ee433510601e40a8facde60.tar.gz
Cleaned up implementations of libnet_get_hwaddr(), some leaked memory,
one returned a pointer to data on the stack, and the others return a pointer to static data. I'm settling on the non-reentrant static data form.
-rw-r--r--libnet/src/libnet_link_bpf.c14
-rw-r--r--libnet/src/libnet_link_dlpi.c3
2 files changed, 6 insertions, 11 deletions
diff --git a/libnet/src/libnet_link_bpf.c b/libnet/src/libnet_link_bpf.c
index 93231ec..1e6eded 100644
--- a/libnet/src/libnet_link_bpf.c
+++ b/libnet/src/libnet_link_bpf.c
@@ -261,7 +261,8 @@ libnet_get_hwaddr(libnet_t *l)
int8_t *buf, *next, *end;
struct if_msghdr *ifm;
struct sockaddr_dl *sdl;
- struct libnet_ether_addr *ea = NULL;
+ /* This implementation is not-reentrant. */
+ static struct libnet_ether_addr ea;
mib[0] = CTL_NET;
mib[1] = AF_ROUTE;
@@ -319,20 +320,13 @@ libnet_get_hwaddr(libnet_t *l)
continue;
if (strncmp(&sdl->sdl_data[0], l->device, sdl->sdl_nlen) == 0)
{
- if (!(ea = malloc(sizeof(struct libnet_ether_addr))))
- {
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): malloc(): %s", __func__, strerror(errno));
- free(buf);
- return (NULL);
- }
- memcpy(ea->ether_addr_octet, LLADDR(sdl), ETHER_ADDR_LEN);
+ memcpy(ea.ether_addr_octet, LLADDR(sdl), ETHER_ADDR_LEN);
break;
}
}
}
free(buf);
- return (ea);
+ return (&ea);
}
diff --git a/libnet/src/libnet_link_dlpi.c b/libnet/src/libnet_link_dlpi.c
index e35f19f..bb65901 100644
--- a/libnet/src/libnet_link_dlpi.c
+++ b/libnet/src/libnet_link_dlpi.c
@@ -735,7 +735,8 @@ libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
struct libnet_ether_addr *
libnet_get_hwaddr(libnet_t *l)
{
- int8_t buf[2048];
+ /* This implementation is not-reentrant. */
+ static int8_t buf[2048];
union DL_primitives *dlp;
struct libnet_ether_addr *eap;