commit 24d464ac483301e2908d37a6bdef25796e3cf431
parent 89c60802d9c47a0502fe1a30e768cc208970b3fd
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date: Tue, 15 Jun 2010 23:18:25 +0200
bugfix, clean up, s/ve/pcap/
Diffstat:
3 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/src/9vx/etherpcap.c b/src/9vx/etherpcap.c
@@ -51,7 +51,6 @@ setup(char *dev, uchar *ea)
if(sprint(filter, "ether dst %2.2ux:%2.2ux:%2.2ux:%2.2ux:%2.2ux:%2.2ux",
ea[0], ea[1], ea[2],ea[3], ea[4], ea[5]) == -1)
return veerror("cannot create pcap filter");
-iprint("XXX FILTER: %s\n", filter);
if (!dev && (dev = pcap_lookupdev(errbuf)) == nil)
return veerror("cannot find network device");
@@ -72,7 +71,7 @@ iprint("XXX FILTER: %s\n", filter);
}
static Block *
-vepkt(Ctlr *c)
+pcappkt(Ctlr *c)
{
struct pcap_pkthdr hdr;
uchar *p;
@@ -104,19 +103,19 @@ vepkt(Ctlr *c)
}
static void
-verecvkproc(void *v)
+pcaprecvkproc(void *v)
{
Ether *e;
Block *b;
e = v;
- while ((b = vepkt(e->ctlr)))
+ while ((b = pcappkt(e->ctlr)))
if (b != nil)
etheriq(e, b, 1);
}
static void
-vetransmit(Ether* e)
+pcaptransmit(Ether* e)
{
const u_char *u;
Block *b;
@@ -138,7 +137,7 @@ vetransmit(Ether* e)
}
static long
-veifstat(Ether *e, void *a, long n, ulong offset)
+pcapifstat(Ether *e, void *a, long n, ulong offset)
{
char buf[128];
@@ -147,24 +146,23 @@ veifstat(Ether *e, void *a, long n, ulong offset)
}
static void
-veattach(Ether* e)
+pcapattach(Ether* e)
{
- kproc("verecv", verecvkproc, e);
+ kproc("pcaprecv", pcaprecvkproc, e);
}
static int
-vepnp(Ether* e)
+pcappnp(Ether* e)
{
Ctlr c;
static int cve = 0;
- if(cve == nve)
- return -1;
- while(ve[cve].tap == 1)
+ while(cve < nve && ve[cve].tap == 1)
cve++;
+ if(cve >= nve)
+ return -1;
memset(&c, 0, sizeof(c));
- iprint("cve = %d\n", cve);
c.pd = setup(ve[cve].dev, ve[cve].ea);
if (c.pd == nil) {
iprint("ve: pcap failed to initialize\n");
@@ -175,9 +173,9 @@ vepnp(Ether* e)
memcpy(e->ctlr, &c, sizeof(c));
e->tbdf = BUSUNKNOWN;
memcpy(e->ea, ve[cve].ea, Eaddrlen);
- e->attach = veattach;
- e->transmit = vetransmit;
- e->ifstat = veifstat;
+ e->attach = pcapattach;
+ e->transmit = pcaptransmit;
+ e->ifstat = pcapifstat;
e->ni.arg = e;
e->ni.link = 1;
cve++;
@@ -187,5 +185,5 @@ vepnp(Ether* e)
void
etherpcaplink(void)
{
- addethercard("ve", vepnp);
+ addethercard("pcap", pcappnp);
}
diff --git a/src/9vx/ethertap.c b/src/9vx/ethertap.c
@@ -152,10 +152,10 @@ tappnp(Ether* e)
Ctlr c;
static int cve = 0;
+ while(cve < nve && ve[cve].tap == 0)
+ cve++;
if(cve == nve)
return -1;
- while(ve[cve].tap == 0)
- cve++;
memset(&c, 0, sizeof c);
c.fd = setup(ve[cve].dev);
diff --git a/src/9vx/main.c b/src/9vx/main.c
@@ -51,9 +51,6 @@ int doabort = 1; // for now
int abortonfault;
char* argv0;
char* conffile = "9vx";
-char* macaddr;
-char* netdev;
-int nettap;
Conf conf;
static char* inifile;
@@ -174,7 +171,7 @@ main(int argc, char **argv)
if(vedev != nil && vedev[0] == '-'){
vedev = nil;
argc++;
- *argv--;
+ argv--;
}
addve(vedev, vetap);
break;
@@ -403,9 +400,9 @@ iniopt(char *name, char *value)
username = value;
else if(strcmp(name, "usetty") == 0)
usetty = 1;
- else if(strcmp(name, "macaddr") == 0 && !macaddr)
+ else if(strcmp(name, "macaddr") == 0)
setea(value);
- else if(strcmp(name, "netdev") == 0 && !netdev){
+ else if(strcmp(name, "netdev") == 0){
if(strncmp(value, "tap", 3) == 0) {
vetap = 1;
value += 4;