Example #1
0
int
_attrfmt(Fmt *fmt)
{
    char *b, buf[1024], *ebuf;
    Attr *a;

    ebuf = buf+sizeof buf;
    b = buf;
    strcpy(buf, " ");
    for(a=va_arg(fmt->args, Attr*); a; a=a->next) {
        if(a->name == nil)
            continue;
        switch(a->type) {
        case AttrQuery:
            b = seprint(b, ebuf, " %q?", a->name);
            break;
        case AttrNameval:
            b = seprint(b, ebuf, " %q=%q", a->name, a->val);
            break;
        case AttrDefault:
            b = seprint(b, ebuf, " %q:=%q", a->name, a->val);
            break;
        }
    }
    return fmtstrcpy(fmt, buf+1);
}
Example #2
0
File: tagfs.c Project: ericvh/tagfs
static void
ctlread(Req* r)
{
	char	buf[4096];
	char*	s;
	int	i;

	s = seprint(buf, buf+sizeof(buf), "trie %s\n", tfname);
	s = seprint(s, buf+sizeof(buf), "prefixes %ld\n", ntries);
	s = seprint(s, buf+sizeof(buf), "tags %ld\n", nvaltries);
	s = seprint(s, buf+sizeof(buf), "max entry %ld\n", maxvals);
	if(trie->nents > 0){
		s = seprint(s, buf+sizeof(buf), "%d root runes [", trie->nents);
		for(i = 0; i < trie->nents; i++)
			s = seprint(s, buf+sizeof(buf), "%C", trie->ents[i].r);
		s = seprint(s, buf+sizeof(buf), "]\n");
	}
	if(roott.nents > 0){
		s = seprint(s, buf+sizeof(buf), "%d used runes [", roott.nents);
		for(i = 0; i < roott.nents; i++)
			s = seprint(s, buf+sizeof(buf), "%C", roott.ents[i].r);
		seprint(s, buf+sizeof(buf), "]\n");
	}
	readstr(r, buf);
	respond(r, nil);
}
Example #3
0
File: ether.c Project: npe9/harvey
void
dumpframe(char *tag, void *p, int n)
{
	Etherpkt *ep;
	char buf[128];
	char *s, *se;
	int i;

	ep = p;
	if(n < Eaddrlen * 2 + 2){
		fprint(2, "short packet (%d bytes)\n", n);
		return;
	}
	se = buf+sizeof(buf);
	s = seprint(buf, se, "%s [%d]: ", tag, n);
	s = seprintaddr(s, se, ep->s);
	s = seprint(s, se, " -> ");
	s = seprintaddr(s, se, ep->d);
	s = seprint(s, se, " type 0x%02ux%02ux ", ep->type[0], ep->type[1]);
	n -= Eaddrlen * 2 + 2;
	for(i = 0; i < n && i < 16; i++)
		s = seprint(s, se, "%02x", ep->data[i]);
	if(n >= 16)
		fprint(2, "%s...\n", buf);
	else
		fprint(2, "%s\n", buf);
}
Example #4
0
File: main.c Project: aahud/harvey
/*
 *  format and print a packet
 */
void
printpkt(char *p, char *e, uint8_t *ps, uint8_t *pe)
{
	Msg m;
	uint32_t dt;

	dt = (pkttime-starttime)/1000000LL;
	m.p = seprint(p, e, "%6.6lu ms ", dt);
	m.ps = ps;
	m.pe = pe;
	m.e = e;
	m.pr = root;
	while(m.p < m.e){
		if(!sflag)
			m.p = seprint(m.p, m.e, "\n\t");
		m.p = seprint(m.p, m.e, "%s(", m.pr->name);
		if((*m.pr->seprint)(&m) < 0){
			m.p = seprint(m.p, m.e, "TOO SHORT");
			m.ps = m.pe;
		}
		m.p = seprint(m.p, m.e, ")");
		if(m.pr == nil || m.ps >= m.pe)
			break;
	}
	*m.p++ = '\n';

	if(write(1, p, m.p - p) < 0)
		sysfatal("stdout: %r");
}
Example #5
0
static void
writeinfo(Dev *d)
{
	char buf[128];
	char *s;
	char *se;
	Usbdev *ud;
	Conf *c;
	Iface *ifc;
	int i, j;

	ud = d->usb;
	s = buf;
	se = buf+sizeof(buf);
	s = seprint(s, se, "info %s csp %#08ux", classname(ud->class), ud->csp);
	for(i = 0; i < ud->nconf; i++){
		c = ud->conf[i];
		if(c == nil)
			break;
		for(j = 0; j < nelem(c->iface); j++){
			ifc = c->iface[j];
			if(ifc == nil)
				break;
			if(ifc->csp != ud->csp)
				s = seprint(s, se, " csp %#08ulx", ifc->csp);
		}
	}
	s = seprint(s, se, " vid %06#x did %06#x", ud->vid, ud->did);
	seprint(s, se, " %q %q", ud->vendor, ud->product);
	devctl(d, "%s", buf);
}
Example #6
0
char *
confine(char *q, char *s)
{
	int i, n, m;
	char *p, *e, *r, *buf, *toks[Maxtoks];

	n = nhgetl(q);
	q += 4;
	buf = malloc(n+1);
	if (buf == nil)
		return nil;
	memmove(buf, q, n);
	buf[n]  = 0;
	m = tokenize(buf, toks, nelem(toks));
	e = s + n + 1;
	for (i = 0, r = s; i < m; ++i) {
		p = strrchr(toks[i], '/');
		if (p == nil)
			r = seprint(r, e, "%s ", toks[i]);
		else if (p[0] != '\0' && p[1] != '\0')
			r = seprint(r, e, "%s ", p+1);
		else
			r = seprint(r, e, ". ");
	}
	free(buf);
	q += n;
	return q;
}
Example #7
0
File: ppp.c Project: 99years/plan9
static int
p_seprintcomp(Msg *m)
{
	char compflag[5];
	ushort x;
	int i;
	int len;

	len = m->pe-m->ps;
	if(len < 2)
		return -1;

	x = NetS(m->ps);
	m->ps += 2;
	i = 0;
	if(x & (1<<15))
		compflag[i++] = 'r';
	if(x & (1<<14))
		compflag[i++] = 'f';
	if(x & (1<<13))
		compflag[i++] = 'c';
	if(x & (1<<12))
		compflag[i++] = 'e';
	compflag[i] = 0;
	m->p = seprint(m->p, m->e, "flag=%s count=%.3ux", compflag, x&0xfff);
	m->p = seprint(m->p, m->e, " data=%.*H", len>64?64:len, m->ps);
	m->pr = nil;
	return 0;
}
Example #8
0
File: ppp.c Project: 99years/plan9
static char*
seprintccpopt(char *p, char *e, void *a, int len)
{
	Lcpopt *o;
	uchar *cp, *ecp;

	cp = a;
	ecp = cp+len;

	for(; cp < ecp; cp += o->len){
		o = (Lcpopt*)cp;
		if(cp + o->len > ecp){
			p = seprint(p, e, " bad opt len %ux", o->type);
			return p;
		}
		
		switch(o->type){
		default:
			p = seprint(p, e, " type=%d ", o->type);
			break;
		case 0:
			p = seprint(p, e, " OUI=(%d %.2ux%.2ux%.2ux) ", o->type, 
				o->data[0], o->data[1], o->data[2]);
			break;
		case 17:
			p = seprint(p, e, " Stac-LZS");
			break;
		case 18:
			p = seprint(p, e, " Microsoft-PPC=%ux", NetL(o->data));
			break;
		}
	}
	return p;
}
Example #9
0
File: bootp.c Project: aahud/harvey
static int
p_seprint(Msg *m)
{
	Hdr *h;
	uint32_t x;

	h = (Hdr*)m->ps;

	if(m->pe < (uint8_t*)h->sname)
		return -1;

	/* point past data */
	m->ps = h->optdata;

	/* next protocol */
	m->pr = nil;
	if(m->pe >= (uint8_t*)h->optdata){
		x = NetL(h->optmagic);
		demux(p_mux, x, x, m, &dump);
	}

	m->p = seprint(m->p, m->e, "t=%s ht=%d hl=%d hp=%d xid=%x sec=%d fl=%4.4x ca=%V ya=%V sa=%V ga=%V cha=%E magic=%lx",
		op(h->op), h->htype, h->hlen, h->hops,
		NetL(h->xid), NetS(h->secs), NetS(h->flags),
		h->ciaddr, h->yiaddr, h->siaddr, h->giaddr, h->chaddr,
		(uint32_t)NetL(h->optmagic));
	if(m->pe > (uint8_t*)h->sname && *h->sname)
		m->p = seprint(m->p, m->e, " snam=%s", h->sname);
	if(m->pe > (uint8_t*)h->file && *h->file)
		m->p = seprint(m->p, m->e, " file=%s", h->file);
	return 0;
}
Example #10
0
File: dump.c Project: bhanug/harvey
static char*
seprintconf(char *s, char *e, Usbdev *d, int ci)
{
	int i;
	Conf *c;
	char *hd;

	c = d->conf[ci];
	s = seprint(s, e, "\tconf: cval %d attrib %x %d mA\n",
		c->cval, c->attrib, c->milliamps);
	for(i = 0; i < Niface; i++)
		if(c->iface[i] == nil)
			break;
		else
			s = seprintiface(s, e, c->iface[i]);
	for(i = 0; i < Nddesc; i++)
		if(d->ddesc[i] == nil)
			break;
		else if(d->ddesc[i]->conf == c){
			hd = hexstr((uint8_t*)&d->ddesc[i]->data,
				d->ddesc[i]->data.bLength);
			s = seprint(s, e, "\t\tdev desc %x[%d]: %s\n",
				d->ddesc[i]->data.bDescriptorType,
				d->ddesc[i]->data.bLength, hd);
			free(hd);
		}
	return s;
}
Example #11
0
File: dump.c Project: bhanug/harvey
int
Ufmt(Fmt *f)
{
	int i;
	Dev *d;
	Usbdev *ud;
	char buf[1024];
	char *s, *e;

	s = buf;
	e = buf+sizeof(buf);
	d = va_arg(f->args, Dev*);
	if(d == nil)
		return fmtprint(f, "<nildev>\n");
	s = seprint(s, e, "%s", d->dir);
	ud = d->usb;
	if(ud == nil)
		return fmtprint(f, "%s %ld refs\n", buf, d->Ref.ref);
	s = seprint(s, e, " csp %s.%uld.%uld",
		classname(Class(ud->csp)), Subclass(ud->csp), Proto(ud->csp));
	s = seprint(s, e, " vid %#ux did %#ux", ud->vid, ud->did);
	s = seprint(s, e, " refs %ld\n", d->Ref.ref);
	s = seprint(s, e, "\t%s %s %s\n", ud->vendor, ud->product, ud->serial);
	for(i = 0; i < Nconf; i++){
		if(ud->conf[i] == nil)
			break;
		else
			s = seprintconf(s, e, ud, i);
	}
	return fmtprint(f, "%s", buf);
}
Example #12
0
static long	 
flashread(Chan *c, void *buf, long n, vlong offset)
{
	Flash *f;
	char *s, *o;
	Flashpart *fp;
	Flashregion *r;
	int i;
	ulong start, end;

	if(c->qid.type & QTDIR)
		return devdirread(c, buf, n, nil, 0, flashgen);

	f = flash.card[c->dev];
	fp = &f->part[PART(c->qid.path)];
	if(fp->name == nil)
		error(Egreg);
	switch(TYPE(c->qid.path)){
	case Qdata:
		offset += fp->start;
		if(offset >= fp->end)
			return 0;
		if(offset+n > fp->end)
			n = fp->end - offset;
		n = readflash(f, buf, offset, n);
		if(n < 0)
			error(Eio);
		return n;
	case Qctl:
		s = malloc(READSTR);
		if(waserror()){
			free(s);
			nexterror();
		}
		o = seprint(s, s+READSTR, "%#2.2ux %#4.4ux %d %q\n",
			f->id, f->devid, f->width, f->sort!=nil? f->sort: "nor");
		for(i=0; i<f->nr; i++){
			r = &f->regions[i];
			if(r->start < fp->end && fp->start < r->end){
				start = r->start;
				if(fp->start > start)
					start = fp->start;
				end = r->end;
				if(fp->end < end)
					end = fp->end;
				o = seprint(o, s+READSTR, "%#8.8lux %#8.8lux %#8.8lux", start, end, r->erasesize);
				if(r->pagesize)
					o = seprint(o, s+READSTR, " %#8.8lux", r->pagesize);
				o = seprint(o, s+READSTR, "\n");
			}
		}
		n = readstr(offset, buf, n, s);
		poperror();
		free(s);
		return n;
	}
	error(Egreg);
	return 0;		/* not reached */
}
Example #13
0
/*
 *  look up the ip attributes 'list' for an entry that has the
 *  given 'attr=val' and a 'ip=' tuples.
 *
 *  return nil if not found.
 */
Ndbtuple*
csipinfo(char *netroot, char *attr, char *val, char **list, int n)
{
	Ndbtuple *t, *first, *last;
	int i;
	char line[1024];
	int fd;
	char *p, *e;

	if(netroot)
		snprint(line, sizeof(line), "%s/cs", netroot);
	else
		strcpy(line, "/net/cs");
	fd = open(line, ORDWR);
	if(fd < 0)
		return 0;
	seek(fd, 0, 0);
	e = line + sizeof(line);
	p = seprint(line, e, "!ipinfo %s=%s", attr, val);
	for(i = 0; i < n; i++){
		if(*list == nil)
			break;
		p = seprint(p, e, " %s", *list++);
	}
	
	if(write(fd, line, strlen(line)) < 0){
		close(fd);
		return 0;
	}
	seek(fd, 0, 0);

	first = last = 0;
	for(;;){
		n = read(fd, line, sizeof(line)-2);
		if(n <= 0)
			break;
		line[n] = '\n';
		line[n+1] = 0;

		t = _ndbparseline(line);
		if(t == 0)
			continue;
		if(first)
			last->entry = t;
		else
			first = t;
		last = t;

		while(last->entry)
			last = last->entry;
	}
	close(fd);

	setmalloctag(first, getcallerpc(&netroot));
	return first;
}
Example #14
0
char *
getplaystat(char *p, char *e)
{
	p = seprint(p, e, "empty buffers %d of %d\n", empty->n, empty->s);
	p = seprint(p, e, "full buffers %d of %d\n", full->n, full->s);
	p = seprint(p, e, "playout buffers %d of %d\n", playout->n, playout->s);
	p = seprint(p, e, "spare buffers %d of %d\n", spare->n, spare->s);
	p = seprint(p, e, "bytes %lud / buffers %lud played\n", totbytes, totbuffers);
	return p;
}
Example #15
0
static char *
pflag(char *s, char *e, uchar f)
{
	uchar i;

	for(i = 0; i < 8; i++)
		if(f & (1 << i))
			s = seprint(s, e, "%s ", flagname[i]);
	return seprint(s, e, "\n");
}
Example #16
0
File: dhcp.c Project: bhanug/harvey
static char*
ptype(char *p, char *e, uint8_t val)
{
	char *x;

	x = dhcptype[val];
	if(x != nil)
		return seprint(p, e, "t=%s", x);
	else
		return seprint(p, e, "t=%d", val);
}
Example #17
0
static char *
printech2(EiceChain2 *ec2, char *s, int ssz)
{
	char *e, *te;

	te = s + ssz -1;
	
	e = seprint(s, te, "data: %#8.8ux\n", ec2->data);
	e = seprint(e, te, "addr: %#2.2ux\n", ec2->addr);
	e = seprint(e, te, "rw: %1.1d\n", ec2->rw);
	return e;
}
Example #18
0
File: dhcp.c Project: bhanug/harvey
static char*
pserver(char *p, char *e, char *tag, uint8_t *o, int n)
{
	p = seprint(p, e, "%s=(", tag);
	while(n >= 4){
		p = seprint(p, e, " %V", o);
		n -= 4;
		o += 4;
	}
	p = seprint(p, e, ")");
	return p;
}
Example #19
0
File: dns.c Project: npe9/harvey
static int
p_seprint(Msg *m)
{
	char *e;

	if((e = convM2DNS(m->ps, m->pe-m->ps, &dm, nil)) != nil){
		m->p = seprint(m->p, m->e, "error: %s", e);
		return 0;
	}
	m->p = seprint(m->p, m->e, "id=%d flags=%#ux", dm.id, dm.flags);
	donext(m);
	return 0;
}
Example #20
0
static char *
printech1(EiceChain1 *ec1, char *s, int ssz)
{
	char *e, *te;

	te = s + ssz -1;
	
	e = seprint(s, te, "rwdata: %#8.8ux\n", ec1->rwdata);
	e = seprint(e, te, "wptandbkpt: %1.1d\n", ec1->wptandbkpt);
	e = seprint(e, te, "sysspeed: %1.1d\n", ec1->sysspeed);
	e = seprint(e, te, "instr: %#8.8ux\n", ec1->instr);
	return e;
}
Example #21
0
void
logPacket(Packet *p)
{
	Attribute *a;
	char buf[255];
	char pbuf[4*1024];
	uchar *au = p->authenticator;
	int i;
	char *np, *e;

	e = pbuf + sizeof(pbuf);

	np = seprint(pbuf, e, "Packet ID=%d auth=%x %x %x... ", p->ID, au[0], au[1], au[2]);
	switch(p->code){
	case R_AccessRequest:
		np = seprint(np, e, "request\n");
		break;
	case R_AccessAccept:
		np = seprint(np, e, "accept\n");
		break;
	case R_AccessReject:
		np = seprint(np, e, "reject\n");
		break;
	case R_AccessChallenge:
		np = seprint(np, e, "challenge\n");
		break;
	default:
		np = seprint(np, e, "code=%d\n", p->code);
		break;
	}
	replymess = "0000000";
	for(a = &p->first; a; a = a->next){
		if(a->len > 253 )
			a->len = 253;
		memmove(buf, a->val, a->len);
		np = seprint(np, e, " [%d]", a->type);
		for(i = 0; i<a->len; i++)
			if(isprint(a->val[i]))
				np = seprint(np, e, "%c", a->val[i]);
			else
				np = seprint(np, e, "\\%o", a->val[i]);
		np = seprint(np, e, "\n");
		buf[a->len] = 0;
		if(a->type == R_ReplyMessage)
			replymess = strdup(buf);
		else if(a->type == R_State)
			stateattr = a;
	}

	syslog(0, AUTHLOG, "%s", pbuf);
}
Example #22
0
File: ecp.c Project: bhanug/harvey
/*
 * warning - print best error message possible and clear errno
 */
void
warning(char *s1, char *s2)
{
	char err[100], msg[256];
	char *np, *ep = msg + sizeof msg - 1;

	errstr(err, sizeof err);		/* save error string */
	np = seprint(msg, ep, "%s: ", argv0);
	np = seprint(np, ep, s1, s2);
	errstr(err, sizeof err);		/* restore error string */
	seprint(np, ep, ": %r\n");

	fprint(2, "%s", msg);
}
Example #23
0
void
error(char* fmt, ...)
{
	va_list arg;
	char *e, s[256];

	va_start(arg, fmt);
	e = seprint(s, s+sizeof(s), "%s: ", argv0);
	e = vseprint(e, s+sizeof(s), fmt, arg);
	e = seprint(e, s+sizeof(s), "\n");
	va_end(arg);

	write(2, s, e-s);
}
Example #24
0
static int
v6hdr_seprint(Msg *m)
{
	int len = IP6HDR;
	uchar *pkt = m->ps;
	Hdr *h = (Hdr *) pkt;
	int pktlen = IP6HDR + NetS(h->length);
	uchar nexthdr = h->proto;
	int plen;
	
	pkt += len;
	plen = len;

	while ( (nexthdr == HBH_HDR) || (nexthdr == ROUT_HDR) ||
		(nexthdr == FRAG_HDR) || (nexthdr == DEST_HDR) ) {

		switch (nexthdr) {
		case FRAG_HDR:
			m->p = seprint(m->p, m->e, "\n	  xthdr=frag id=%d offset=%d pr=%d more=%d res1=%d res2=%d",
					NetL(pkt+4),
					NetS(pkt+2) & ~7,
					(int) (*pkt),
					(int) (*(pkt+3) & 0x1),
					(int) *(pkt+1),
					(int) (*(pkt+3) & 0x6)
				);
			len = FRAG_HSZ;
			break;

		case HBH_HDR:
		case ROUT_HDR:
		case DEST_HDR:
			len = ( ((int) *(pkt+1)) + 1) * 8;
			break;
		}

		if (plen + len > pktlen) {
			m->p = seprint(m->p, m->e, "bad pkt");
			m->pr = &dump;
			return -1;
		}
		plen += len;
		pkt += len;
		nexthdr = *pkt;
	}

	m->ps = pkt;
	return 1;

}
Example #25
0
static int
aoerctl(SDunit *u, char *p, int l)
{
	Ctlr *c;
	char *e, *op;

	if((c = u->dev->ctlr) == nil)
		return 0;
	e = p+l;
	op = p;

	p = seprint(p, e, "model\t%s\n", c->model);
	p = seprint(p, e, "serial\t%s\n", c->serial);
	p = seprint(p, e, "firm	%s\n", c->firmware);
	if(c->smartrs == 0xff)
		p = seprint(p, e, "smart\tenable error\n");
	else if(c->smartrs == 0)
		p = seprint(p, e, "smart\tdisabled\n");
	else
		p = seprint(p, e, "smart\t%s\n", smarttab[c->smart]);
	p = seprint(p, e, "flag	");
	p = pflag(p, e, c->feat);
	p = seprint(p, e, "geometry %llud %d\n", c->sectors, Aoesectsz);
	return p-op;
}
Example #26
0
File: ether.c Project: npe9/harvey
static char*
seprintifstats(char *s, char *se, Ether *e)
{
	int i;
	Conn *c;

	qlock(e);
	s = seprint(s, se, "ctlr id: %#x\n", e->cid);
	s = seprint(s, se, "phy: %#x\n", e->phy);
	s = seprint(s, se, "exiting: %s\n", e->exiting ? "y" : "n");
	s = seprint(s, se, "conns: %d\n", e->nconns);
	s = seprint(s, se, "allocated bufs: %d\n", e->nabufs);
	s = seprint(s, se, "used bufs: %d\n", e->nbufs);
	for(i = 0; i < nelem(e->conns); i++){
		c = e->conns[i];
		if(c == nil)
			continue;
		if(c->ref == 0)
			s = seprint(s, se, "c[%d]: free\n", i);
		else{
			s = seprint(s, se, "c[%d]: refs %ld t %#x h %d p %d\n",
				c->nb, c->ref, c->type, c->headersonly, c->prom);
		}
	}
	qunlock(e);
	return s;
}
Example #27
0
static int
looprctl(SDunit *unit, char *p, int l)
{
	Ctlr *ctlr;
	char *e, *op;
	
	ctlr = unit->dev->ctlr;
	e = p+l;
	op = p;
	
	p = seprint(p, e, "loop %s %s\n", ctlr->mode == ORDWR ? "rw" : "ro", chanpath(ctlr->c));
	p = seprint(p, e, "geometry %llud 512\n", unit->sectors*512);
	return p - op;
}
Example #28
0
static int
looprctl(SDunit *u, char *p, int l)
{
	Ctlr *c;
	char *e, *op;

	if((c = u->dev->ctlr) == nil)
		return 0;
	e = p+l;
	op = p;

	p = seprint(p, e, "path\t%s\n", c->path);
	p = seprint(p, e, "geometry %llud %d\n", c->sectors, c->sectsize);
	return p - op;
}
Example #29
0
char *
armsprctxt(ArmCtxt *ctxt, char *s, int ssz)
{
	char *e, *te;
	int i;

	te = s + ssz -1;

	e = seprint(s, te, "Arm is in debug: %d\nregs\n", ctxt->debug);
	for(i = 0; i < 16; i++)
		e = seprint(e, te, "r%d: %#8.8ux\n", i, ctxt->r[i]);
	e = seprint(e, te, "cpsr: %#8.8ux\n", ctxt->cpsr);
	e = seprint(e, te, "spsr: %#8.8ux\n", ctxt->spsr);
	return e;
}
Example #30
0
static void
SRdumpReq(ScsiReq *rp)
{
	char buf[128];
	char *s;
	char *se;

	se = buf+sizeof(buf);
	s = seprint(buf, se, "lun %d ", rp->lun);
	s = seprintcmd(s, se, (char*)rp->cmd.p, rp->cmd.count, 1);
	s = seprint(s, se, " [%ld]", rp->data.count);
	if(rp->cmd.write)
		seprintdata(s, se, rp->data.p, rp->data.count);
	fprint(2, "scsi⇒ %s\n", buf);
}