[PATCH] driver_bsd.c: Clean up EAPOL frame transmission code
Masashi Honma
honma
Tue Jan 12 20:42:36 PST 2010
Hello.
The bsd_send_eapol() prepares 3000 bytes buffer for every EAPOL
frame transmission. I think malloc() is better way for efficient
memory use.
diff --git a/src/drivers/driver_bsd.c b/src/drivers/driver_bsd.c
index bd3f56b..70c5e02 100644
--- a/src/drivers/driver_bsd.c
+++ b/src/drivers/driver_bsd.c
@@ -696,8 +696,7 @@ bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
int encrypt, const u8 *own_addr)
{
struct bsd_driver_data *drv = priv;
- unsigned char buf[3000];
- unsigned char *bp = buf;
+ unsigned char *bp;
struct l2_ethhdr *eth;
size_t len;
int status;
@@ -709,26 +708,23 @@ bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
* and size of frames this probably doesn't matter.
*/
len = data_len + sizeof(struct l2_ethhdr);
- if (len > sizeof(buf)) {
- bp = malloc(len);
- if (bp == NULL) {
- printf("EAPOL frame discarded, cannot malloc temp "
- "buffer of size %u!\n", (unsigned int) len);
- return -1;
- }
+ bp = os_zalloc(len);
+ if (bp == NULL) {
+ wpa_printf(MSG_ERROR, "malloc() failed for bsd_send_eapol"
+ "(len=%lu)", (unsigned long) len);
+ return -1;
}
eth = (struct l2_ethhdr *) bp;
- memcpy(eth->h_dest, addr, ETH_ALEN);
- memcpy(eth->h_source, own_addr, ETH_ALEN);
+ os_memcpy(eth->h_dest, addr, ETH_ALEN);
+ os_memcpy(eth->h_source, own_addr, ETH_ALEN);
eth->h_proto = htons(ETH_P_EAPOL);
- memcpy(eth+1, data, data_len);
+ os_memcpy(eth+1, data, data_len);
wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
- if (bp != buf)
- free(bp);
+ os_free(bp);
return status;
}
Regards,
Masashi Honma.
More information about the Hostap
mailing list