7 _readoldipifc(char *buf, Ipifc **l, int index)
14 /* allocate new interface */
15 *l = ifc = mallocz(sizeof(Ipifc), 1);
21 n = tokenize(buf, f, nelem(f));
25 strncpy(ifc->dev, f[0], sizeof ifc->dev);
26 ifc->dev[sizeof(ifc->dev) - 1] = 0;
27 ifc->mtu = strtoul(f[1], nil, 10);
30 for(i = 2; n-i >= 7; i += 7){
31 /* allocate new local address */
32 *ll = lifc = mallocz(sizeof(Iplifc), 1);
35 parseip(lifc->ip, f[i]);
36 parseipmask(lifc->mask, f[i+1]);
37 parseip(lifc->net, f[i+2]);
38 ifc->pktin = strtoul(f[i+3], nil, 10);
39 ifc->pktout = strtoul(f[i+4], nil, 10);
40 ifc->errin = strtoul(f[i+5], nil, 10);
41 ifc->errout = strtoul(f[i+6], nil, 10);
47 findfield(char *name, char **f, int n)
51 for(i = 0; i < n-1; i++)
52 if(strcmp(f[i], name) == 0)
58 _readipifc(char *file, Ipifc **l, int index)
68 fd = open(file, OREAD);
72 while((i = read(fd, buf+n, sizeof(buf)-1-n)) > 0 && n < sizeof(buf) - 1)
77 if(strncmp(buf, "device", 6) != 0)
78 return _readoldipifc(buf, l, index);
79 /* ignore ifcs with no associated device */
80 if(strncmp(buf+6, " ", 2) == 0)
82 /* allocate new interface */
83 *l = ifc = mallocz(sizeof(Ipifc), 1);
90 lines = getfields(buf, line, nelem(line), 1, "\n");
92 /* pick off device specific info(first line) */
93 n = tokenize(line[0], f, nelem(f));
96 strncpy(ifc->dev, findfield("device", f, n), sizeof(ifc->dev));
97 ifc->dev[sizeof(ifc->dev)-1] = 0;
104 ifc->mtu = strtoul(findfield("maxtu", f, n), nil, 10);
105 ifc->sendra6 = atoi(findfield("sendra", f, n));
106 ifc->recvra6 = atoi(findfield("recvra", f, n));
107 ifc->rp.mflag = atoi(findfield("mflag", f, n));
108 ifc->rp.oflag = atoi(findfield("oflag", f, n));
109 ifc->rp.maxraint = atoi(findfield("maxraint", f, n));
110 ifc->rp.minraint = atoi(findfield("minraint", f, n));
111 ifc->rp.linkmtu = atoi(findfield("linkmtu", f, n));
112 ifc->rp.reachtime = atoi(findfield("reachtime", f, n));
113 ifc->rp.rxmitra = atoi(findfield("rxmitra", f, n));
114 ifc->rp.ttl = atoi(findfield("ttl", f, n));
115 ifc->rp.routerlt = atoi(findfield("routerlt", f, n));
116 ifc->pktin = strtoul(findfield("pktin", f, n), nil, 10);
117 ifc->pktout = strtoul(findfield("pktout", f, n), nil, 10);
118 ifc->errin = strtoul(findfield("errin", f, n), nil, 10);
119 ifc->errout = strtoul(findfield("errout", f, n), nil, 10);
121 /* now read the addresses */
123 for(i = 1; i < lines; i++){
124 n = tokenize(line[i], f, nelem(f));
128 /* allocate new local address */
129 *ll = lifc = mallocz(sizeof(Iplifc), 1);
132 parseip(lifc->ip, f[0]);
133 parseipmask(lifc->mask, f[1]);
134 parseip(lifc->net, f[2]);
136 lifc->validlt = strtoul(f[3], nil, 10);
137 lifc->preflt = strtoul(f[4], nil, 10);
147 Iplifc *lnext, *lifc;
151 for(; ifc; ifc = next){
153 for(lifc = ifc->lifc; lifc; lifc = lnext){
162 readipifc(char *net, Ipifc *ifc, int index)
177 snprint(directory, sizeof(directory), "%s/ipifc", net);
180 snprint(buf, sizeof(buf), "%s/%d/status", directory, index);
181 _readipifc(buf, l, index);
183 fd = open(directory, OREAD);
186 n = dirreadall(fd, &dir);
189 for(i = 0; i < n; i++){
190 if(strcmp(dir[i].name, "clone") == 0)
192 if(strcmp(dir[i].name, "stats") == 0)
194 snprint(buf, sizeof(buf), "%s/%s/status", directory, dir[i].name);
195 l = _readipifc(buf, l, atoi(dir[i].name));