There's no need to initialize struct iovec before every recvmsg();
move it to struct pkt_hdr and initialize only once in packet_init().
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/packet.c | 9 ++++-----
src/packet.h | 3 +++
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/packet.c b/src/packet.c
index ad6fb61..e6fcae5 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -148,15 +148,11 @@ int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win)
if ((ss > 0) && (pfds[0].revents & POLLIN) != 0) {
struct sockaddr_ll from;
- struct iovec iov;
struct msghdr msg;
- iov.iov_len = pkt->pkt_bufsize;
- iov.iov_base = pkt->pkt_buf;
-
msg.msg_name = &from;
msg.msg_namelen = sizeof(from);
- msg.msg_iov = &iov;
+ msg.msg_iov = &pkt->iov;
msg.msg_iovlen = 1;
msg.msg_control = NULL;
msg.msg_controllen = 0;
@@ -339,6 +335,9 @@ int packet_init(struct pkt_hdr *pkt)
pkt->ip6_hdr = NULL;
pkt->pkt_len = 0; /* signalize we have no packet prepared */
+ pkt->iov.iov_len = pkt->pkt_bufsize;
+ pkt->iov.iov_base = pkt->pkt_buf;
+
return 0; /* all O.K. */
}
diff --git a/src/packet.h b/src/packet.h
index 1cdbe76..d47d658 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -31,6 +31,9 @@ struct pkt_hdr {
unsigned char pkt_pkttype; /* Packet type: PACKET_OUTGOING, PACKET_BROADCAST, ... */
unsigned char pkt_halen; /* Length of address */
unsigned char pkt_addr[8]; /* Physical layer address */
+
+ struct iovec iov;
+
struct ethhdr *ethhdr;
struct fddihdr *fddihdr;
struct iphdr *iphdr;
--
1.9.1