commit 1c3419dcc8372f87559d39f46a72a72dc789796c
parent fe6b9f1b95c3ea1a82407d20e7e84160219facb8
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date: Sun, 13 Jun 2010 10:36:54 +0200
copy the packet in vepkt(): pcap device working
Diffstat:
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/src/9vx/etherve.c b/src/9vx/etherve.c
@@ -63,7 +63,7 @@ setup(void)
return veerror("cannot find network device");
// if ((pd = pcap_open_live(netdev, 1514, 1, 1, errbuf)) == nil)
- if ((pd = pcap_open_live(netdev, 65000, 1, 1, errbuf)) == nil) // XXX
+ if ((pd = pcap_open_live(netdev, 65000, 1, 1, errbuf)) == nil)
return nil;
if (macaddr && (eafrom(macaddr, ea) == -1))
@@ -84,28 +84,30 @@ static Block *
vepkt(Ctlr *c)
{
struct pcap_pkthdr hdr;
+ uchar *p, *q;
Block *b;
- static int fn=0;
-
- b = allocb(65000);
- while ((b->rp = pcap_next(c->pd, &hdr)) == nil) ;
- if(hdr.caplen == 0)
- return nil;
+ while ((p = pcap_next(c->pd, &hdr)) == nil);
- b->wp = b->rp+hdr.caplen; // XXX ?
+ b = allocb(hdr.caplen);
+ b->wp += hdr.caplen;
+ for(q = b->rp; q != b->wp; q++)
+ *q = *(p++);
b->flag |= Btcpck|Budpck|Bpktck;
+/*
iprint("+++++++++++ packet %d (len %d):\n", ++fn, hdr.caplen);
- // iprint("wp-20: %s\n\n", b->wp-20);
- int i=0; uchar* p;
- for(p=b->rp; p<b->wp; p++){
+ int i=0; uchar* u;
+ static int fn=0;
+
+ for(u=b->rp; u<b->wp; u++){
if (i%16 == 0) iprint("%.4ux", i);
if (i%8 == 0) iprint(" ");
- iprint("%2.2ux ", *p);
+ iprint("%2.2ux ", *u);
if (++i%16 == 0) iprint("\n");
}
iprint("\n-------------\n");
+*/
return b;