header definition is hidden in kernel tree under net/core/dev.c in dev_seq_show.
"Inter-| Receive " " | Transmit\n" " face |bytes packets errs drop fifo frame " "compressed multicast|bytes packets errs " "drop fifo colls carrier compressed\n"
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com --- src/ifaces.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/ifaces.c b/src/ifaces.c index a3a7b08..c14af0a 100644 --- a/src/ifaces.c +++ b/src/ifaces.c @@ -17,21 +17,22 @@ ifaces.c - routine that determines whether a given interface is supported * at the top of the file. */
-FILE *open_procnetdev(void) -{ - FILE *fd; - char buf[161];
- fd = fopen("/proc/net/dev", "r"); +/* taken from net/core/dev.c: dev_seq_show */ +#define NET_DEV_START_TOKEN \ + "Inter-| Receive " \ + " | Transmit\n" \ + " face |bytes packets errs drop fifo frame " \ + "compressed multicast|bytes packets errs " \ + "drop fifo colls carrier compressed\n"
- /* - * Read and discard the table header lines in the file - */ +FILE *open_procnetdev(void) +{ + FILE *fd = fopen("/proc/net/dev", "r"); + if (!fd) + return NULL;
- if (fd != NULL) { - fgets(buf, 160, fd); - fgets(buf, 160, fd); - } + fseek(fd, strlen(NET_DEV_START_TOKEN), SEEK_SET);
return fd; }
On Wed, Sep 12, 2012 at 12:41:39PM +0200, Nikola Pajkovsky wrote:
header definition is hidden in kernel tree under net/core/dev.c in dev_seq_show.
"Inter-| Receive " " | Transmit\n" " face |bytes packets errs drop fifo frame " "compressed multicast|bytes packets errs " "drop fifo colls carrier compressed\n"
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com
I don't agree. It's more error prone than finding two end-of-lines. In the case someone adds a new column to the /proc/net/dev file in some 5.9.x kernel and modifies the header then we need to accomodate with this and check two types of header.
Leave this as is, please (it's not on any fast path).
Vita
P.S. If you want to change this, then use netlink socket and get the interfaces from it.
src/ifaces.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/ifaces.c b/src/ifaces.c index a3a7b08..c14af0a 100644 --- a/src/ifaces.c +++ b/src/ifaces.c @@ -17,21 +17,22 @@ ifaces.c - routine that determines whether a given interface is supported
- at the top of the file.
*/
-FILE *open_procnetdev(void) -{
FILE *fd;
char buf[161];
fd = fopen("/proc/net/dev", "r");
+/* taken from net/core/dev.c: dev_seq_show */ +#define NET_DEV_START_TOKEN \
- "Inter-| Receive " \
- " | Transmit\n" \
- " face |bytes packets errs drop fifo frame " \
- "compressed multicast|bytes packets errs " \
- "drop fifo colls carrier compressed\n"
- /*
* Read and discard the table header lines in the file
*/
+FILE *open_procnetdev(void) +{
- FILE *fd = fopen("/proc/net/dev", "r");
- if (!fd)
return NULL;
- if (fd != NULL) {
fgets(buf, 160, fd);
fgets(buf, 160, fd);
- }
fseek(fd, strlen(NET_DEV_START_TOKEN), SEEK_SET);
return fd;
}
1.7.12
Vitezslav Samel vitezslav@samel.cz writes:
On Wed, Sep 12, 2012 at 12:41:39PM +0200, Nikola Pajkovsky wrote:
header definition is hidden in kernel tree under net/core/dev.c in dev_seq_show.
"Inter-| Receive " " | Transmit\n" " face |bytes packets errs drop fifo frame " "compressed multicast|bytes packets errs " "drop fifo colls carrier compressed\n"
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com
I don't agree. It's more error prone than finding two end-of-lines. In the case someone adds a new column to the /proc/net/dev file in some 5.9.x kernel and modifies the header then we need to accomodate with this and check two types of header.
Leave this as is, please (it's not on any fast path).
Vita
P.S. If you want to change this, then use netlink socket and get the interfaces from it.
it wasn't changed since Linux-2.6.12-rc2 (which is kernel import to git) ;)
On Wed, Sep 12, 2012 at 04:27:01PM +0200, Nikola Pajkovsky wrote:
Vitezslav Samel vitezslav@samel.cz writes:
On Wed, Sep 12, 2012 at 12:41:39PM +0200, Nikola Pajkovsky wrote:
header definition is hidden in kernel tree under net/core/dev.c in dev_seq_show.
"Inter-| Receive " " | Transmit\n" " face |bytes packets errs drop fifo frame " "compressed multicast|bytes packets errs " "drop fifo colls carrier compressed\n"
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com
I don't agree. It's more error prone than finding two end-of-lines. In the case someone adds a new column to the /proc/net/dev file in some 5.9.x kernel and modifies the header then we need to accomodate with this and check two types of header.
Leave this as is, please (it's not on any fast path).
Vita
P.S. If you want to change this, then use netlink socket and get the interfaces from it.
it wasn't changed since Linux-2.6.12-rc2 (which is kernel import to git) ;)
Still don't agree. Don't change code which perfectly works.
Vita
iptraf-ng@lists.fedorahosted.org