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);
34 parseipandmask(lifc->ip, lifc->mask, f[i], f[i+1]);
35 parseip(lifc->net, f[i+2]);
36 ifc->pktin = strtoul(f[i+3], nil, 10);
37 ifc->pktout = strtoul(f[i+4], nil, 10);
38 ifc->errin = strtoul(f[i+5], nil, 10);
39 ifc->errout = strtoul(f[i+6], nil, 10);
45 findfield(char *name, char **f, int n)
49 for(i = 0; i < n-1; i++)
50 if(strcmp(f[i], name) == 0)
56 _readipifc(char *file, Ipifc **l, int index)
66 fd = open(file, OREAD);
70 while((i = read(fd, buf+n, sizeof(buf)-1-n)) > 0 && n < sizeof(buf) - 1)
75 if(strncmp(buf, "device", 6) != 0)
76 return _readoldipifc(buf, l, index);
77 /* ignore ifcs with no associated device */
78 if(strncmp(buf+6, " ", 2) == 0)
80 /* allocate new interface */
81 *l = ifc = mallocz(sizeof(Ipifc), 1);
88 lines = getfields(buf, line, nelem(line), 1, "\n");
90 /* pick off device specific info(first line) */
91 n = tokenize(line[0], f, nelem(f));
94 strncpy(ifc->dev, findfield("device", f, n), sizeof(ifc->dev));
95 ifc->dev[sizeof(ifc->dev)-1] = 0;
102 ifc->mtu = strtoul(findfield("maxtu", f, n), nil, 10);
103 ifc->sendra6 = atoi(findfield("sendra", f, n));
104 ifc->recvra6 = atoi(findfield("recvra", f, n));
105 ifc->rp.mflag = atoi(findfield("mflag", f, n));
106 ifc->rp.oflag = atoi(findfield("oflag", f, n));
107 ifc->rp.maxraint = atoi(findfield("maxraint", f, n));
108 ifc->rp.minraint = atoi(findfield("minraint", f, n));
109 ifc->rp.linkmtu = atoi(findfield("linkmtu", f, n));
110 ifc->rp.reachtime = atoi(findfield("reachtime", f, n));
111 ifc->rp.rxmitra = atoi(findfield("rxmitra", f, n));
112 ifc->rp.ttl = atoi(findfield("ttl", f, n));
113 ifc->rp.routerlt = atoi(findfield("routerlt", f, n));
114 ifc->pktin = strtoul(findfield("pktin", f, n), nil, 10);
115 ifc->pktout = strtoul(findfield("pktout", f, n), nil, 10);
116 ifc->errin = strtoul(findfield("errin", f, n), nil, 10);
117 ifc->errout = strtoul(findfield("errout", f, n), nil, 10);
119 /* now read the addresses */
121 for(i = 1; i < lines; i++){
122 n = tokenize(line[i], f, nelem(f));
126 /* allocate new local address */
127 *ll = lifc = mallocz(sizeof(Iplifc), 1);
130 parseipandmask(lifc->ip, lifc->mask, f[0], f[1]);
131 parseip(lifc->net, f[2]);
133 lifc->validlt = strtoul(f[3], nil, 10);
134 lifc->preflt = strtoul(f[4], nil, 10);
144 Iplifc *lnext, *lifc;
148 for(; ifc; ifc = next){
150 for(lifc = ifc->lifc; lifc; lifc = lnext){
159 readipifc(char *net, Ipifc *ifc, int index)
174 snprint(directory, sizeof(directory), "%s/ipifc", net);
177 snprint(buf, sizeof(buf), "%s/%d/status", directory, index);
178 _readipifc(buf, l, index);
180 fd = open(directory, OREAD);
183 n = dirreadall(fd, &dir);
186 for(i = 0; i < n; i++){
187 if(strcmp(dir[i].name, "clone") == 0)
189 if(strcmp(dir[i].name, "stats") == 0)
191 snprint(buf, sizeof(buf), "%s/%s/status", directory, dir[i].name);
192 l = _readipifc(buf, l, atoi(dir[i].name));