From dfffd21c424ff27f268a732e22716a8a399bacb3 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 4 Apr 2003 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2003-04-04 --- boot/bootip.c | 1 + ip/ip.h | 2 +- ip/ipaux.c | 18 ++++++++++------- ip/iproute.c | 53 +++++++++++++++++++++++---------------------------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/boot/bootip.c b/boot/bootip.c index 285832e52ef0fae76b2e1cbcf5bebd796e5dbe5e..682622a172e6feebc8d2c499a02682766bbe2254 100644 --- a/boot/bootip.c +++ b/boot/bootip.c @@ -61,6 +61,7 @@ configip(void) case -1: fatal("configuring ip: %r"); case 0: + print("exec-ing ipconfig\n"); exec("/boot/ipconfig", arg); fatal("execing /ipconfig"); default: diff --git a/ip/ip.h b/ip/ip.h index acfe839185022678e51d5e3d06d8f56afa4e1f76..ab81398a3b2c8f9e5d9095de2adaa7e043a0f3f9 100644 --- a/ip/ip.h +++ b/ip/ip.h @@ -440,10 +440,10 @@ enum struct Routewalk { - int n; int o; int h; char* p; + char* e; void* state; void (*walk)(Route*, Routewalk*); }; diff --git a/ip/ipaux.c b/ip/ipaux.c index ae8baf293c40e3c8c90bb677195b7a1afe551af6..a53266b09ef087ffcca62eef71cb7d6c47e01dae 100644 --- a/ip/ipaux.c +++ b/ip/ipaux.c @@ -282,13 +282,16 @@ eipfmt(Fmt *f) switch(f->r) { case 'E': /* Ethernet address */ p = va_arg(f->args, uchar*); - return fmtprint(f, efmt, p[0], p[1], p[2], p[3], p[4], p[5]); + snprint(buf, sizeof buf, efmt, p[0], p[1], p[2], p[3], p[4], p[5]); + return fmtstrcpy(f, buf); case 'I': /* Ip address */ p = va_arg(f->args, uchar*); common: - if(memcmp(p, v4prefix, 12) == 0) - return fmtprint(f, ifmt, p[12], p[13], p[14], p[15]); + if(memcmp(p, v4prefix, 12) == 0){ + snprint(buf, sizeof buf, ifmt, p[12], p[13], p[14], p[15]); + return fmtstrcpy(f, buf); + } /* find longest elision */ eln = eli = -1; @@ -326,7 +329,8 @@ common: case 'V': /* v4 ip address */ p = va_arg(f->args, uchar*); - return fmtprint(f, ifmt, p[0], p[1], p[2], p[3]); + snprint(buf, sizeof buf, ifmt, p[0], p[1], p[2], p[3]); + return fmtstrcpy(f, buf); case 'M': /* ip mask */ p = va_arg(f->args, uchar*); @@ -346,10 +350,10 @@ common: n = 8*16; /* got one, use /xx format */ - return fmtprint(f, "/%d", n); - + snprint(buf, sizeof buf, "/%d", n); + return fmtstrcpy(f, buf); } - return fmtprint(f, "(eipfmt)"); + return fmtstrcpy(f, "(eipfmt)"); } #define CLASS(p) ((*(uchar*)(p))>>6) diff --git a/ip/iproute.c b/ip/iproute.c index 816e6685f2993fe1be722d94b2e277256bce8b1c..3229435ecd49073384ae57331eb69f207d32d314 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -617,12 +617,7 @@ routetype(int type, char *p) *p = 'p'; } -enum -{ - Rlinelen= 137, -}; - -char *rformat = "%-40.40I %-40.40M %-40.40I %4.4s %4.4s %3s\n"; +char *rformat = "%-15I %-4M %-15I %4.4s %4.4s %3s\n"; void convroute(Route *r, uchar *addr, uchar *mask, uchar *gate, char *t, int *nifc) @@ -658,21 +653,27 @@ convroute(Route *r, uchar *addr, uchar *mask, uchar *gate, char *t, int *nifc) static void sprintroute(Route *r, Routewalk *rw) { - int nifc; + int nifc, n; char t[5], *iname, ifbuf[5]; uchar addr[IPaddrlen], mask[IPaddrlen], gate[IPaddrlen]; + char *p; - if(rw->o >= 0) { - convroute(r, addr, mask, gate, t, &nifc); - iname = "-"; - if(nifc != -1) { - iname = ifbuf; - sprint(ifbuf, "%d", nifc); - } - sprint(rw->p, rformat, addr, mask, gate, t, r->tag, iname); - rw->p += Rlinelen; + convroute(r, addr, mask, gate, t, &nifc); + iname = "-"; + if(nifc != -1) { + iname = ifbuf; + sprint(ifbuf, "%d", nifc); } - rw->o++; + p = seprint(rw->p, rw->e, rformat, addr, mask, gate, t, r->tag, iname); + if(rw->o < 0){ + n = p - rw->p; + if(n > -rw->o){ + memmove(rw->p, rw->p-rw->o, n+rw->o); + rw->p = p + rw->o; + } + rw->o += n; + } else + rw->p = p; } /* @@ -683,7 +684,7 @@ rr(Route *r, Routewalk *rw) { int h; - if(rw->n <= rw->o) + if(rw->e <= rw->p) return 0; if(r == nil) return 1; @@ -709,12 +710,12 @@ void ipwalkroutes(Fs *f, Routewalk *rw) { rlock(&routelock); - if(rw->n > rw->o) { + if(rw->e > rw->p) { for(rw->h = 0; rw->h < nelem(f->v4root); rw->h++) if(rr(f->v4root[rw->h], rw) == 0) break; } - if(rw->n > rw->o) { + if(rw->e > rw->p) { for(rw->h = 0; rw->h < nelem(f->v6root); rw->h++) if(rr(f->v6root[rw->h], rw) == 0) break; @@ -727,20 +728,14 @@ routeread(Fs *f, char *p, ulong offset, int n) { Routewalk rw; - if(offset % Rlinelen) - return 0; - rw.p = p; - rw.n = n/Rlinelen; - rw.o = -(offset/Rlinelen); + rw.e = p+n; + rw.o = -offset; rw.walk = sprintroute; ipwalkroutes(f, &rw); - if(rw.o < 0) - rw.o = 0; - - return rw.o*Rlinelen; + return rw.p - p; } /*