diff -Nru usermode/pppoeci.c usb-pppoe-llc/pppoeci.c --- usermode/pppoeci.c Sat Jun 22 16:24:37 2002 +++ usb-pppoe-llc/pppoeci.c Fri Jun 28 03:58:47 2002 @@ -92,6 +92,8 @@ #include #include #include +#include +#include /* my USB library */ #include "pusb.h" @@ -341,7 +343,18 @@ do { - r = read(fd, ppp_buf, sizeof(ppp_buf)); + 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); @@ -356,17 +369,17 @@ { snprintf(errText, ERR_BUFSIZE, "reading from PPP: len=%d", r); message(errText); - dump(ppp_buf, r); + dump(ppp_buf, r + 10); } if(r <= 0) return(r); - /* suppress leading 2 bytes */ + /* don't suppress leading 2 bytes */ if(syncHDLC) { - if(r < 3) + if(r < 1) { snprintf(errText, ERR_BUFSIZE, "reading from PPP: short on data, r=%d => ignored", r); @@ -382,10 +395,10 @@ continue; } - *buf = ppp_buf + 2; - *n = r - 2; + *buf = ppp_buf; + *n = r + 10 ; - return(r - 2); + return(r + 10); } else message("async HDLC not handled"); @@ -406,23 +419,21 @@ 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) { snprintf(errText, ERR_BUFSIZE, - "writing to PPP: len=%d", n + 2); + "writing to PPP: len=%d", n); message(errText); - dump(ppp_buf, n + 2); + dump(ppp_buf, n - 10); } retries = 0; while (retries < NOBUF_RETRIES) { - 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 @@ -1196,11 +1207,33 @@ *var = value; } +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 = LOG_FILE; int fdin, fdout, log; int i; + char dev[20]=""; this_process = getpid(); log = 0; @@ -1252,9 +1285,7 @@ verbose?"en":"dis"); /* duplicate in and out fd */ - fdin = dup(0); - fdout = dup(1); - + fdin = fdout = tap_open(dev); /* * If the verbosity level is greater than 0 * we have to create a log @@ -1382,7 +1413,7 @@ if(isatty(fdin)) { -/* #undef N_HDLC */ +#undef N_HDLC #ifdef N_HDLC int disc = N_HDLC;