diff -Nru eicon-linux-0.5a/usermode/pppoeci.c eicon-linux-0.5b/usermode/pppoeci.c --- eicon-linux-0.5a/usermode/pppoeci.c Fri May 24 22:16:49 2002 +++ eicon-linux-0.5b/usermode/pppoeci.c Mon Jun 10 20:11:58 2002 @@ -91,6 +91,9 @@ #include #include #include +#include +#include + /* my USB library */ #include "pusb.h" @@ -147,6 +150,7 @@ int gfdout; int g_fdin; + #define CRC32_REMAINDER CBF43926 #define CRC32_INITIAL 0xffffffff @@ -305,8 +309,17 @@ for(;;) { - do { - r = read(fd, ppp_buf, sizeof(ppp_buf)); + do { ppp_buf[0]=0xaa; + ppp_buf[1]=0xaa; + ppp_buf[2]=0x03; + ppp_buf[3]=0x00; + ppp_buf[4]=0x80; + ppp_buf[5]=0xc2; + ppp_buf[6]=0x00; + ppp_buf[7]=0x07; + ppp_buf[8]=0x00; + ppp_buf[9]=0x00; + r = read(fd, ppp_buf + 10, sizeof(ppp_buf)); } while(r < 0 && errno == EINTR); if(r < 0) @@ -320,17 +333,17 @@ if(verbose>1) { print_time(); printf(" Read from ppp, len = %d\n", r); - dump(ppp_buf, r); + dump(ppp_buf, r + 10); } if(r <= 0) return r; - /* supress leading 2 bytes */ + /* don't supress leading 2 bytes */ if(syncHDLC) { - if(r < 3) + if(r < 1) { print_time(); printf(" Read from ppp short on data, r=%d => ignored\n", r); @@ -344,10 +357,10 @@ continue; } - *buf = ppp_buf + 2; - *n = r - 2; + *buf = ppp_buf; + *n = r + 10; - return(r - 2); + return(r + 10); } else @@ -373,20 +386,17 @@ int retries = 0; if(syncHDLC) { - ppp_buf[0] = 0xff; //FRAME_ADDR; - ppp_buf[1] = 0x03; //FRAME_CTRL; - - memcpy(ppp_buf + 2, buf, n); + memcpy(ppp_buf, buf + 10, n - 10 ); if(verbose>1) { print_time(); - printf(" writing to ppp, len = %d\n", n + 2); - dump(ppp_buf, n + 2); + printf(" writing to ppp, len = %d\n", n); + dump(ppp_buf, n - 10); } retry: - if((r = write(fd, ppp_buf, n + 2)) < 0) { + if((r = write(fd, ppp_buf, n - 10)) < 0) { /* * We sometimes run out of mbufs doing simultaneous @@ -497,15 +507,13 @@ unsigned int crc1, crc2; if(vpi != my_vpi || vci != my_vci) { -/* - if(verbose) { + if(verbose){ printf("< pid=%d > ", this_process); print_time(); printf(" vpi.vci mismatch (%d/%d instead of %d/%d) ... ignored!\n", vpi, vci, my_vpi, my_vci); dump(cell_buf, CELL_DATA); - } -*/ + } return(0); } @@ -1094,11 +1102,36 @@ exit (-1); } + +int tap_open(char *dev) +{ + struct ifreq ifr; + int fd, err; + + if( (fd = open("/dev/net/tun", O_RDWR | O_SYNC)) < 0 ) + return -1; + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_flags = IFF_TAP | IFF_NO_PI; + if( *dev ) + strncpy(ifr.ifr_name, dev, IFNAMSIZ); + + if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){ + close(fd); + return err; + } + strcpy(dev, ifr.ifr_name); + return fd; +} + + + int main(int argc, char *argv[]) { const char *logfile = "/tmp/pppoa2.log"; int fdin, fdout, log; int i; + char dev[20]=""; this_process = getpid(); log = 0; @@ -1127,9 +1160,8 @@ if(verbose) fprintf(stderr, "Using vpi.vci=%d.%d\n", my_vpi, my_vci); - /*Duplicate in and out fd*/ - fdin = dup(0); - fdout = dup(1); + /*in and out fd assigned to tap device*/ + fdin = fdout = tap_open(dev); /* * If the verbosity level is greater than 0 @@ -1243,7 +1275,7 @@ */ if(isatty(fdin)) { -/*#undef N_HDLC*/ +#undef N_HDLC #ifdef N_HDLC int disc = N_HDLC;