Vitezslav Samel (4): packet.h: change spaces in indentation to tabs packet.h: remove unused open_socket() declaration packet_get(): receive packets using recvmsg() instead of recvfrom() iptraf.c: fix displaying long interface names
src/packet.c | 19 ++++++++++++++----- src/packet.h | 15 +++++++-------- src/tcptable.c | 47 ++++++++++++++++++----------------------------- src/tcptable.h | 1 + 4 files changed, 40 insertions(+), 42 deletions(-)
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/packet.h | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/packet.h b/src/packet.h index 00bc3c9..9683a0d 100644 --- a/src/packet.h +++ b/src/packet.h @@ -40,13 +40,13 @@ struct pkt_hdr {
static inline void PACKET_INIT_STRUCT(struct pkt_hdr *p) { - p->pkt_bufsize = MAX_PACKET_SIZE; - p->pkt_payload = NULL; - p->ethhdr = NULL; - p->fddihdr = NULL; - p->iphdr = NULL; - p->ip6_hdr = NULL; - p->pkt_len = 0; /* signalize we have no packet prepared */ + p->pkt_bufsize = MAX_PACKET_SIZE; + p->pkt_payload = NULL; + p->ethhdr = NULL; + p->fddihdr = NULL; + p->iphdr = NULL; + p->ip6_hdr = NULL; + p->pkt_len = 0; /* signalize we have no packet prepared */ }
#define PACKET_INIT(packet) \
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/packet.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/src/packet.h b/src/packet.h index 9683a0d..895d63b 100644 --- a/src/packet.h +++ b/src/packet.h @@ -76,7 +76,6 @@ static inline __u8 pkt_ip_protocol(const struct pkt_hdr *p) return 0; }
-void open_socket(int *fd); int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win); int packet_process(struct pkt_hdr *pkt, unsigned int *total_br, in_port_t *sport, in_port_t *dport,
Since recvfrom() is emulated by recvmsg() (in kernel space), make use of recvmsg().
This also prepares the ground for VLAN handling: since about 6 years the VLAN header is stripped off the packet (except for some rare and/or software interfaces) and is passed to us using auxilliary data structure. This 'struct tpacket_auxdata' is passed to us using control messages (see cmsg(3)) and these control messages can be received only by recvmsg(2).
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/packet.c | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/packet.c b/src/packet.c index 251466b..bc8ed21 100644 --- a/src/packet.c +++ b/src/packet.c @@ -147,12 +147,21 @@ int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win) PACKET_INIT_STRUCT(pkt); if ((ss > 0) && (pfds[0].revents & POLLIN) != 0) { struct sockaddr_ll from; - socklen_t fromlen = sizeof(struct sockaddr_ll); - ssize_t len; + struct iovec iov; + struct msghdr msg;
- len = recvfrom(fd, pkt->pkt_buf, pkt->pkt_bufsize, - MSG_TRUNC | MSG_DONTWAIT, - (struct sockaddr *) &from, &fromlen); + 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_iovlen = 1; + msg.msg_control = NULL; + msg.msg_controllen = 0; + msg.msg_flags = 0; + + ssize_t len = recvmsg(fd, &msg, MSG_TRUNC | MSG_DONTWAIT); if (len > 0) { pkt->pkt_len = len; pkt->pkt_caplen = len;
Vitezslav Samel vitezslav@samel.cz writes:
Since recvfrom() is emulated by recvmsg() (in kernel space), make use of recvmsg().
This also prepares the ground for VLAN handling: since about 6 years the VLAN header is stripped off the packet (except for some rare and/or software interfaces) and is passed to us using auxilliary data structure. This 'struct tpacket_auxdata' is passed to us using control messages (see cmsg(3)) and these control messages can be received only by recvmsg(2).
Signed-off-by: Vitezslav Samel vitezslav@samel.cz
src/packet.c | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-)
patch is not bad, but you will have to convince me, that recvfrom is emulated by recvmsg ;)
On Wed, Nov 28, 2012 at 11:12:50AM +0100, Nikola Pajkovsky wrote:
Vitezslav Samel vitezslav@samel.cz writes:
Since recvfrom() is emulated by recvmsg() (in kernel space), make use of recvmsg().
This also prepares the ground for VLAN handling: since about 6 years the VLAN header is stripped off the packet (except for some rare and/or software interfaces) and is passed to us using auxilliary data structure. This 'struct tpacket_auxdata' is passed to us using control messages (see cmsg(3)) and these control messages can be received only by recvmsg(2).
Signed-off-by: Vitezslav Samel vitezslav@samel.cz
src/packet.c | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-)
patch is not bad, but you will have to convince me, that recvfrom is emulated by recvmsg ;)
linux-3.6/net/socket.c: lines 1753 - 1792
Hope this will convince you.
Vita
Vitezslav Samel vitezslav@samel.cz writes:
On Wed, Nov 28, 2012 at 11:12:50AM +0100, Nikola Pajkovsky wrote:
Vitezslav Samel vitezslav@samel.cz writes:
Since recvfrom() is emulated by recvmsg() (in kernel space), make use of recvmsg().
This also prepares the ground for VLAN handling: since about 6 years the VLAN header is stripped off the packet (except for some rare and/or software interfaces) and is passed to us using auxilliary data structure. This 'struct tpacket_auxdata' is passed to us using control messages (see cmsg(3)) and these control messages can be received only by recvmsg(2).
Signed-off-by: Vitezslav Samel vitezslav@samel.cz
src/packet.c | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-)
patch is not bad, but you will have to convince me, that recvfrom is emulated by recvmsg ;)
linux-3.6/net/socket.c: lines 1753 - 1792
Hope this will convince you.
nice one,
I overlooked for the first time this part
err = (nosec ? sock_recvmsg_nosec : sock_recvmsg)(sock, msg_sys, total_len, flags);
There was garbage printed in "IP traffic monitor" when interface name was longer than 5 chars. Fix it by making more room for the name (shortening the flags field) and caping name length to room left on display (at least 7 and maximum IFNAMSIZ characters).
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/tcptable.c | 47 ++++++++++++++++++----------------------------- src/tcptable.h | 1 + 2 files changed, 19 insertions(+), 29 deletions(-)
diff --git a/src/tcptable.c b/src/tcptable.c index 3f492dd..956866c 100644 --- a/src/tcptable.c +++ b/src/tcptable.c @@ -118,11 +118,16 @@ void init_tcp_table(struct tcptable *table) setlabels(table->borderwin, 0); /* initially use mode 0 */
wmove(table->borderwin, 0, 65 * COLS / 80); - wprintw(table->borderwin, " Flags "); - wmove(table->borderwin, 0, 72 * COLS / 80); + wprintw(table->borderwin, " Flag "); + wmove(table->borderwin, 0, 70 * COLS / 80); wprintw(table->borderwin, " Iface "); update_panels(); doupdate(); + table->ifnamew = COLS - (70 * COLS / 80) - 3; + if (table->ifnamew < 7) + table->ifnamew = 7; + if (table->ifnamew > IFNAMSIZ) + table->ifnamew = IFNAMSIZ;
table->head = table->tail = NULL; table->firstvisible = table->lastvisible = NULL; @@ -862,39 +867,23 @@ void printentry(struct tcptable *table, struct tcptableent *tableentry, wattrset(table->tcpscreen, normalattr);
if (tableentry->finsent == 1) - strcpy(stat, "DONE "); + strcpy(stat, "DONE"); else if (tableentry->finsent == 2) - strcpy(stat, "CLOSED"); + strcpy(stat, "CLOS"); else if (tableentry->stat & FLAG_RST) - strcpy(stat, "RESET "); + strcpy(stat, "RSET"); else { - if (tableentry->stat & FLAG_SYN) - strcat(stat, "S"); - else - strcat(stat, "-"); - - if (tableentry->stat & FLAG_PSH) - strcat(stat, "P"); - else - strcat(stat, "-"); - - if (tableentry->stat & FLAG_ACK) - strcat(stat, "A"); - else - strcat(stat, "-"); - - if (tableentry->stat & FLAG_URG) - strcat(stat, "U"); - else - strcat(stat, "-"); - - strcat(stat, " "); + strcat(stat, (tableentry->stat & FLAG_SYN) ? "S" : "-"); + strcat(stat, (tableentry->stat & FLAG_PSH) ? "P" : "-"); + strcat(stat, (tableentry->stat & FLAG_ACK) ? "A" : "-"); + strcat(stat, (tableentry->stat & FLAG_URG) ? "U" : "-"); }
wmove(table->tcpscreen, target_row, 65 * COLS / 80); - wprintw(table->tcpscreen, "%s", stat); - wmove(table->tcpscreen, target_row, 72 * COLS / 80); - wprintw(table->tcpscreen, "%s", tableentry->ifname); + wprintw(table->tcpscreen, "%4.4s", stat); + wmove(table->tcpscreen, target_row, 70 * COLS / 80); + wprintw(table->tcpscreen, "%-*.*s", table->ifnamew, table->ifnamew, + tableentry->ifname); }
/* diff --git a/src/tcptable.h b/src/tcptable.h index d0f5253..21fafc6 100644 --- a/src/tcptable.h +++ b/src/tcptable.h @@ -86,6 +86,7 @@ struct tcptable { unsigned int count; unsigned int bmaxy; /* number of lines of the border window */ unsigned int imaxy; /* number of lines inside the border */ + int ifnamew; /* interface name width to display */ WINDOW *tcpscreen; PANEL *tcppanel; WINDOW *borderwin;
Vitezslav Samel vitezslav@samel.cz writes:
There was garbage printed in "IP traffic monitor" when interface name was longer than 5 chars. Fix it by making more room for the name (shortening the flags field) and caping name length to room left on display (at least 7 and maximum IFNAMSIZ characters).
Signed-off-by: Vitezslav Samel vitezslav@samel.cz
src/tcptable.c | 47 ++++++++++++++++++----------------------------- src/tcptable.h | 1 + 2 files changed, 19 insertions(+), 29 deletions(-)
diff --git a/src/tcptable.c b/src/tcptable.c index 3f492dd..956866c 100644 --- a/src/tcptable.c +++ b/src/tcptable.c @@ -118,11 +118,16 @@ void init_tcp_table(struct tcptable *table) setlabels(table->borderwin, 0); /* initially use mode 0 */
wmove(table->borderwin, 0, 65 * COLS / 80);
- wprintw(table->borderwin, " Flags ");
- wmove(table->borderwin, 0, 72 * COLS / 80);
wprintw(table->borderwin, " Flag ");
wmove(table->borderwin, 0, 70 * COLS / 80); wprintw(table->borderwin, " Iface "); update_panels(); doupdate();
table->ifnamew = COLS - (70 * COLS / 80) - 3;
if (table->ifnamew < 7)
table->ifnamew = 7;if (table->ifnamew > IFNAMSIZ)
table->ifnamew = IFNAMSIZ;table->head = table->tail = NULL; table->firstvisible = table->lastvisible = NULL;
@@ -862,39 +867,23 @@ void printentry(struct tcptable *table, struct tcptableent *tableentry, wattrset(table->tcpscreen, normalattr);
if (tableentry->finsent == 1)
strcpy(stat, "DONE ");
else if (tableentry->finsent == 2)strcpy(stat, "DONE");
strcpy(stat, "CLOSED");
else if (tableentry->stat & FLAG_RST)strcpy(stat, "CLOS");
strcpy(stat, "RESET ");
strcpy(stat, "RSET");
just nitpicking, RST is for me more informative
On Wed, Nov 28, 2012 at 11:17:38AM +0100, Nikola Pajkovsky wrote:
Vitezslav Samel vitezslav@samel.cz writes:
There was garbage printed in "IP traffic monitor" when interface name was longer than 5 chars. Fix it by making more room for the name (shortening the flags field) and caping name length to room left on display (at least 7 and maximum IFNAMSIZ characters).
Signed-off-by: Vitezslav Samel vitezslav@samel.cz
src/tcptable.c | 47 ++++++++++++++++++----------------------------- src/tcptable.h | 1 + 2 files changed, 19 insertions(+), 29 deletions(-)
diff --git a/src/tcptable.c b/src/tcptable.c index 3f492dd..956866c 100644 --- a/src/tcptable.c +++ b/src/tcptable.c @@ -118,11 +118,16 @@ void init_tcp_table(struct tcptable *table) setlabels(table->borderwin, 0); /* initially use mode 0 */
wmove(table->borderwin, 0, 65 * COLS / 80);
- wprintw(table->borderwin, " Flags ");
- wmove(table->borderwin, 0, 72 * COLS / 80);
wprintw(table->borderwin, " Flag ");
wmove(table->borderwin, 0, 70 * COLS / 80); wprintw(table->borderwin, " Iface "); update_panels(); doupdate();
table->ifnamew = COLS - (70 * COLS / 80) - 3;
if (table->ifnamew < 7)
table->ifnamew = 7;if (table->ifnamew > IFNAMSIZ)
table->ifnamew = IFNAMSIZ;table->head = table->tail = NULL; table->firstvisible = table->lastvisible = NULL;
@@ -862,39 +867,23 @@ void printentry(struct tcptable *table, struct tcptableent *tableentry, wattrset(table->tcpscreen, normalattr);
if (tableentry->finsent == 1)
strcpy(stat, "DONE ");
else if (tableentry->finsent == 2)strcpy(stat, "DONE");
strcpy(stat, "CLOSED");
else if (tableentry->stat & FLAG_RST)strcpy(stat, "CLOS");
strcpy(stat, "RESET ");
strcpy(stat, "RSET");just nitpicking, RST is for me more informative
I just wanted to make it 4-chars wide and don't have preference to either version.
Vita
Vitezslav Samel vitezslav@samel.cz writes:
Vitezslav Samel (4): packet.h: change spaces in indentation to tabs packet.h: remove unused open_socket() declaration packet_get(): receive packets using recvmsg() instead of recvfrom() iptraf.c: fix displaying long interface names
src/packet.c | 19 ++++++++++++++----- src/packet.h | 15 +++++++-------- src/tcptable.c | 47 ++++++++++++++++++----------------------------- src/tcptable.h | 1 + 4 files changed, 40 insertions(+), 42 deletions(-)
applied, thanks
iptraf-ng@lists.fedorahosted.org