diff -Nru speedtouch-1.1/src/pppoa2.c speedtouch-1.1.pppoe/src/pppoa2.c --- speedtouch-1.1/src/pppoa2.c Sat Jun 1 01:34:25 2002 +++ speedtouch-1.1.pppoe/src/pppoa2.c Sun Jul 21 03:05:48 2002 @@ -46,6 +46,9 @@ #include #include #include /* setpriority() */ +#include +#include + #ifdef USE_SYSLOG #include @@ -137,10 +140,38 @@ * Description : Initializes the HDLC, log, and handle endpoints 07, 87 * then exit the main process. */ + + +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[]) { int fdin, fdout; int i; + char dev[20]=""; + #ifndef USE_SYSLOG time_t ourtime; @@ -182,8 +213,9 @@ usage(); /*Duplicate in and out fd*/ - fdin = dup(STDIN_FILENO); - fdout = dup(STDOUT_FILENO); + + fdin = fdout = tap_open(dev); + /*Get process pid*/ parent_process = this_process = getpid(); @@ -645,8 +677,21 @@ return(0); } for(;;) { - do { - r = read(fd, buffer, size); + do { + buffer[0]=0xaa; + buffer[1]=0xaa; + buffer[2]=0xaa; + buffer[3]=0xaa; + buffer[4]=0x03; + buffer[5]=0x00; + buffer[6]=0x80; + buffer[7]=0xc2; + buffer[8]=0x00; + buffer[9]=0x07; + buffer[10]=0x00; + buffer[11]=0x00; + + r = read(fd, buffer + 12, size); } while(r < 0 && errno == EINTR); if(r < 0) { @@ -670,7 +715,7 @@ continue; } - return(r - HDLC_HEADER_SIZE); + return(r + 10); } else { report(0, REPORT_ERROR|REPORT_DATE, "async HDLC not handled\n"); @@ -795,8 +840,7 @@ report(0, REPORT_INFO, "I'm the children process, I handle the endpoint 0x87\n", this_process); /* Prepares ppp buffer for HDLC */ - ppp_write_buf[0] = 0xff; - ppp_write_buf[1] = 0x03; + /* Prepares pos */ pos = 0; @@ -845,7 +889,7 @@ } else { /* Writes the result buffer */ - if(ppp_write(gfdout, ppp_write_buf, n + HDLC_HEADER_SIZE) > 0) + if(ppp_write(gfdout, ppp_write_buf + 12, n - 10) > 0) report(2, REPORT_DEBUG|REPORT_DATE, "Extracted PPP packet sent to ppp(d)\n\n"); } /* Reinitializes pos and n*/