plan 9 kernel history: overview | file list | diff list

1991/1108/port/net.c (diff list | history)

1991/1107/sys/src/9/port/net.c:5,101991/1108/sys/src/9/port/net.c:5,12 (short | long | prev | next)
1991/1107    
#include	"fns.h" 
#include	"errno.h" 
 
1991/1108    
#include	"fcall.h" 
 
1991/1107    
enum 
{ 
	Qlisten=	1, 
1991/1107/sys/src/9/port/net.c:11,161991/1108/sys/src/9/port/net.c:13,19
1991/1107    
	Qclone=		2, 
	Q2nd=		3, 
	Q3rd=		4, 
1991/1108    
	Qinf=		5, 
1991/1107    
}; 
 
/* 
1991/1107/sys/src/9/port/net.c:40,461991/1108/sys/src/9/port/net.c:43,49
1991/1107    
	} 
 
	/* second level contains clone plus all the conversations */ 
	if(c->qid.path == (CHDIR | Q2nd)){ 
1991/1108    
	if(STREAMID(c->qid.path) == 0){ 
1991/1107    
		if(i == 0){ 
			q.path = Qclone; 
			devdir(c, q, "clone", 0, 0666, dp); 
1991/1107/sys/src/9/port/net.c:53,611991/1108/sys/src/9/port/net.c:56,61
1991/1107    
		return 1; 
	} 
 
	if((c->qid.path & CHDIR) == 0) 
		return -1; 
                 
	/* third level depends on the number of info files */ 
	switch(i){ 
	case 0: 
1991/1107/sys/src/9/port/net.c:73,871991/1108/sys/src/9/port/net.c:73,139
1991/1107    
		devdir(c, q, "listen", 0, 0666, dp); 
		break; 
	default: 
		if(i >= 3 + np->ninfo) 
			return -1; 
		i -= 3; 
		q.path = Qlisten + i + 1; 
1991/1108    
		if(i >= np->ninfo) 
			return -1; 
		q.path = STREAMQID(STREAMID(c->qid.path), Qinf+i); 
1991/1107    
		devdir(c, q, np->info[i].name, 0, 0666, dp); 
1991/1108    
		break; 
1991/1107    
	} 
	return 1; 
} 
 
1991/1108    
int	  
netwalk(Chan *c, char *name, Network *np) 
{ 
	if(strcmp(name, "..") == 0) { 
		switch(STREAMTYPE(c->qid.path)){ 
		case Q2nd: 
			c->qid.path = CHDIR; 
			break; 
		case Q3rd: 
			c->qid.path = CHDIR|Q2nd; 
			break; 
		default: 
			panic("netwalk %lux", c->qid.path); 
		} 
		return 1; 
	} 
 
	return devwalk(c, name, (Dirtab*)np, 0, netgen); 
} 
 
void 
netstat(Chan *c, char *db, Network *np) 
{ 
	int i; 
	Dir dir; 
 
	for(i=0;; i++) 
		switch(netgen(c, (Dirtab*)np, 0, i, &dir)){ 
		case -1: 
			/* 
			 * devices with interesting directories usually don't get 
			 * here, which is good because we've lost the name by now. 
			 */ 
			if(c->qid.path & CHDIR){ 
				devdir(c, c->qid, ".", 0L, CHDIR|0700, &dir); 
				convD2M(&dir, db); 
				return; 
			} 
			print("netstat %c %lux\n", devchar[c->type], c->qid.path); 
			error(Enonexist); 
		case 0: 
			break; 
		case 1: 
			if(eqqid(c->qid, dir.qid)){ 
				convD2M(&dir, db); 
				return; 
			} 
			break; 
		} 
} 
 
1991/1107    
Chan * 
netopen(Chan *c, int omode, Network *np) 
{ 
1991/1107/sys/src/9/port/net.c:125,1311991/1108/sys/src/9/port/net.c:177,183
1991/1107    
long 
netread(Chan *c, void *a, long n, ulong offset, Network *np) 
{ 
	int i; 
1991/1108    
	int t; 
1991/1107    
	char buf[256]; 
 
	if(c->stream) 
1991/1107/sys/src/9/port/net.c:134,1431991/1108/sys/src/9/port/net.c:186,195
1991/1107    
	if(c->qid.path&CHDIR) 
		return devdirread(c, a, n, (Dirtab*)np, 0, netgen); 
 
	if(c->qid.path <= Qlisten || c->qid.path > Qlisten + np->ninfo) 
1991/1108    
	t = STREAMTYPE(c->qid.path); 
	if(t < Qinf || t >= Qinf + np->ninfo) 
1991/1107    
		error(Ebadusefd); 
 
	i = c->qid.path - Qlisten - 1; 
	(*np->info[i].fill)(c, buf, sizeof(buf)); 
1991/1108    
	(*np->info[t-Qinf].fill)(c, buf, sizeof(buf)); 
1991/1107    
	return stringread(c, a, n, buf, offset); 
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)