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);
80 /* allocate new interface */
81 *l = ifc = mallocz(sizeof(Ipifc), 1);
87 lines = getfields(buf, line, nelem(line), 1, "\n");
89 /* pick off device specific info(first line) */
90 n = tokenize(line[0], f, nelem(f));
91 strncpy(ifc->dev, findfield("device", f, n), sizeof(ifc->dev));
92 ifc->dev[sizeof(ifc->dev)-1] = 0;
97 ifc->mtu = strtoul(findfield("maxmtu", f, n), nil, 10);
98 ifc->sendra6 = atoi(findfield("sendra", f, n));
99 ifc->recvra6 = atoi(findfield("recvra", f, n));
100 ifc->rp.mflag = atoi(findfield("mflag", f, n));
101 ifc->rp.oflag = atoi(findfield("oflag", f, n));
102 ifc->rp.maxraint = atoi(findfield("maxraint", f, n));
103 ifc->rp.minraint = atoi(findfield("minraint", f, n));
104 ifc->rp.linkmtu = atoi(findfield("linkmtu", f, n));
105 ifc->rp.reachtime = atoi(findfield("reachtime", f, n));
106 ifc->rp.rxmitra = atoi(findfield("rxmitra", f, n));
107 ifc->rp.ttl = atoi(findfield("ttl", f, n));
108 ifc->rp.routerlt = atoi(findfield("routerlt", f, n));
109 ifc->pktin = strtoul(findfield("pktin", f, n), nil, 10);
110 ifc->pktout = strtoul(findfield("pktout", f, n), nil, 10);
111 ifc->errin = strtoul(findfield("errin", f, n), nil, 10);
112 ifc->errout = strtoul(findfield("errout", f, n), nil, 10);
114 /* now read the addresses */
116 for(i = 1; i < lines; i++){
117 n = tokenize(line[i], f, nelem(f));
121 /* allocate new local address */
122 *ll = lifc = mallocz(sizeof(Iplifc), 1);
125 parseip(lifc->ip, f[0]);
126 parseipmask(lifc->mask, f[1]);
127 parseip(lifc->net, f[2]);
129 lifc->validlt = strtoul(f[3], nil, 10);
130 lifc->preflt = strtoul(f[4], nil, 10);
140 Iplifc *lnext, *lifc;
144 for(; ifc; ifc = next){
146 for(lifc = ifc->lifc; lifc; lifc = lnext){
155 readipifc(char *net, Ipifc *ifc, int index)
170 snprint(directory, sizeof(directory), "%s/ipifc", net);
173 snprint(buf, sizeof(buf), "%s/%d/status", directory, index);
174 _readipifc(buf, l, index);
176 fd = open(directory, OREAD);
179 n = dirreadall(fd, &dir);
182 for(i = 0; i < n; i++){
183 if(strcmp(dir[i].name, "clone") == 0)
185 if(strcmp(dir[i].name, "stats") == 0)
187 snprint(buf, sizeof(buf), "%s/%s/status", directory, dir[i].name);
188 l = _readipifc(buf, l, atoi(dir[i].name));