Tomato 1.23
[tomato.git] / release / src / router / upnp / igd / linux / linux_net.c
blobac1f4cb3950adaae2ac36746d2dd90fe4a45b4c8
1 /*
2 * Copyright 2005, Broadcom Corporation
3 * All Rights Reserved.
4 *
5 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
7 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10 * $Id: linux_net.c,v 1.1.1.7 2005/03/07 07:31:12 kanki Exp $
13 #include <sys/ioctl.h>
14 #include <net/if.h>
15 //#include <linux/sockios.h>
16 #include <linux/socket.h>
18 #include "upnp_osl.h"
19 #include "upnp.h"
20 #include "../igd/igd.h"
22 char *get_name(char *name, char *p)
24 while (isspace(*p))
25 p++;
26 while (*p) {
27 if (isspace(*p))
28 break;
29 if (*p == ':') { /* could be an alias */
30 char *dot = p, *dotname = name;
31 *name++ = *p++;
32 while (isdigit(*p))
33 *name++ = *p++;
34 if (*p != ':') { /* it wasn't, backup */
35 p = dot;
36 name = dotname;
38 if (*p == '\0')
39 return NULL;
40 p++;
41 break;
43 *name++ = *p++;
45 *name++ = '\0';
46 return p;
49 int get_dev_fields(char *bp, int versioninfo, if_stats_t *pstats )
51 switch (versioninfo) {
52 case 3:
53 sscanf(bp,
54 "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
55 &pstats->rx_bytes,
56 &pstats->rx_packets,
57 &pstats->rx_errors,
58 &pstats->rx_dropped,
59 &pstats->rx_fifo_errors,
60 &pstats->rx_frame_errors,
61 &pstats->rx_compressed,
62 &pstats->rx_multicast,
64 &pstats->tx_bytes,
65 &pstats->tx_packets,
66 &pstats->tx_errors,
67 &pstats->tx_dropped,
68 &pstats->tx_fifo_errors,
69 &pstats->collisions,
70 &pstats->tx_carrier_errors,
71 &pstats->tx_compressed);
72 break;
73 case 2:
74 sscanf(bp, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
75 &pstats->rx_bytes,
76 &pstats->rx_packets,
77 &pstats->rx_errors,
78 &pstats->rx_dropped,
79 &pstats->rx_fifo_errors,
80 &pstats->rx_frame_errors,
82 &pstats->tx_bytes,
83 &pstats->tx_packets,
84 &pstats->tx_errors,
85 &pstats->tx_dropped,
86 &pstats->tx_fifo_errors,
87 &pstats->collisions,
88 &pstats->tx_carrier_errors);
89 pstats->rx_multicast = 0;
90 break;
91 case 1:
92 sscanf(bp, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
93 &pstats->rx_packets,
94 &pstats->rx_errors,
95 &pstats->rx_dropped,
96 &pstats->rx_fifo_errors,
97 &pstats->rx_frame_errors,
99 &pstats->tx_packets,
100 &pstats->tx_errors,
101 &pstats->tx_dropped,
102 &pstats->tx_fifo_errors,
103 &pstats->collisions,
104 &pstats->tx_carrier_errors);
105 pstats->rx_bytes = 0;
106 pstats->tx_bytes = 0;
107 pstats->rx_multicast = 0;
108 break;
110 return 0;
113 int procnetdev_version(char *buf)
115 if (strstr(buf, "compressed"))
116 return 3;
117 if (strstr(buf, "bytes"))
118 return 2;
119 return 1;