home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / XINE-1.ZIP / INJECTOR.ZIP / SRC / PKTDRVR.C < prev    next >
C/C++ Source or Header  |  1996-08-28  |  4KB  |  172 lines

  1. /* Turbo C Driver for FTP Software's packet driver interface.
  2.  * Graciously donated to the public domain by Phil Karn.
  3.  */
  4. #include <stdio.h>
  5. #include <dos.h>
  6. #include <string.h>
  7. #include "pktdrvr.h"
  8.  
  9. int Derr;
  10. static char Pkt_sig[] = "PKT DRVR";    /* Packet driver signature */
  11.  
  12. /* Test for the presence of a packet driver at an interrupt number.
  13.  * Return 0 if no packet driver.
  14.  */
  15. int
  16. test_for_pd(int intno)
  17. {
  18.     long drvvec;
  19.     char sig[8];    /* Copy of driver signature "PKT DRVR" */
  20.  
  21.     /* Verify that there's really a packet driver there, so we don't
  22.      * go off into the ozone (if there's any left)
  23.      */
  24.     drvvec = (long)getvect(intno);
  25.     movedata(FP_SEG(drvvec),FP_OFF(drvvec)+3,FP_SEG(sig), FP_OFF(sig),
  26.         strlen(Pkt_sig));
  27.     return !strncmp(sig,Pkt_sig,strlen(Pkt_sig));
  28. }
  29.  
  30. int
  31. access_type(int intno,int if_class,int if_type,int if_number,char far * type,unsigned typelen)
  32. {
  33.     union REGS regs;
  34.     struct SREGS sregs;
  35.  
  36.     segread(&sregs);
  37.     regs.h.dl = if_number;        /* Number */
  38.     sregs.ds = FP_SEG(type);    /* Packet type template */
  39.     regs.x.si = FP_OFF(type);
  40.     regs.x.cx = typelen;        /* Length of type */
  41.     sregs.es = FP_SEG(receiver);    /* Address of receive handler */
  42.     regs.x.di = FP_OFF(receiver);
  43.     regs.x.bx = if_type;        /* Type */
  44.     regs.h.ah = ACCESS_TYPE;    /* Access_type() function */
  45.     regs.h.al = if_class;        /* Class */
  46.     int86x(intno,®s,®s,&sregs);
  47.     if(regs.x.cflag){
  48.         Derr = regs.h.dh;
  49.         return -1;
  50.     } else
  51.         return regs.x.ax;
  52. }
  53. int
  54. release_type(int intno,int handle)
  55. {
  56.     union REGS regs;
  57.  
  58.     regs.x.bx = handle;
  59.     regs.h.ah = RELEASE_TYPE;
  60.     int86(intno,®s,®s);
  61.     if(regs.x.cflag){
  62.         Derr = regs.h.dh;
  63.         return -1;
  64.     } else
  65.         return 0;
  66. }
  67. int
  68. send_pkt(int intno,char far * buffer,unsigned length)
  69. {
  70.     union REGS regs;
  71.     struct SREGS sregs;
  72.  
  73.     segread(&sregs);
  74.     sregs.ds = FP_SEG(buffer);
  75.     sregs.es = FP_SEG(buffer); /* for buggy univation pkt driver - CDY */
  76.     regs.x.si = FP_OFF(buffer);
  77.     regs.x.cx = length;
  78.     regs.h.ah = SEND_PKT;
  79.     int86x(intno,®s,®s,&sregs);
  80.     if(regs.x.cflag){
  81.         Derr = regs.h.dh;
  82.         return -1;
  83.     } else
  84.         return 0;
  85. }
  86. int
  87. driver_info(int intno,int handle,int *version,int *cclass,int *type,int *number,int *basic)
  88. {
  89.     union REGS regs;
  90.  
  91.     regs.x.bx = handle;
  92.     regs.h.ah = DRIVER_INFO;
  93.     regs.h.al = 0xff;
  94.     int86(intno,®s,®s);
  95.     if(regs.x.cflag){
  96.         Derr = regs.h.dh;
  97.         return -1;
  98.     }
  99.     if(version != NULL)
  100.         *version = regs.x.bx;
  101.     if(cclass != NULL)
  102.         *cclass = regs.h.ch;
  103.     if(type != NULL)
  104.         *type = regs.x.dx;
  105.     if(number != NULL)
  106.         *number = regs.h.cl;
  107.     if(basic != NULL)
  108.         *basic = regs.h.al;
  109.     return 0;
  110. }
  111. int
  112. get_mtu(int intno)
  113. {
  114.     union REGS regs;
  115.     struct SREGS sregs;
  116.     char far *param;
  117.  
  118.     regs.h.ah = GET_PARAMETERS;
  119.     int86x(intno,®s,®s,&sregs);
  120.     if(regs.x.cflag){
  121.         Derr = regs.h.dh;
  122.         return -1;
  123.     }
  124.     param = (char *) MK_FP(sregs.es, regs.x.di);
  125.     return ((unsigned char)param[4]) + 256 * ((unsigned char)param[5]);
  126. }
  127. int
  128. get_address(int intno,int handle,unsigned char far * buf,int len)
  129. {
  130.     union REGS regs;
  131.     struct SREGS sregs;
  132.  
  133.     segread(&sregs);
  134.     sregs.es = FP_SEG(buf);
  135.     regs.x.di = FP_OFF(buf);
  136.     regs.x.cx = len;
  137.     regs.x.bx = handle;
  138.     regs.h.ah = GET_ADDRESS;
  139.     int86x(intno,®s,®s,&sregs);
  140.     if(regs.x.cflag){
  141.         Derr = regs.h.dh;
  142.         return -1;
  143.     }
  144.     return 0;
  145. }
  146. /* set the mode -- returns the old mode or -1 if error. */
  147. int
  148. set_mode(int intno, int handle, int mode)
  149. {
  150.     union REGS regs;
  151.     int oldmode;
  152.  
  153.     regs.h.ah = GET_RCV_MODE;
  154.     regs.x.bx = handle;
  155.     int86(intno,®s,®s);
  156.     if(regs.x.cflag){
  157.         Derr = regs.h.dh;
  158.         return -1;
  159.     }
  160.     oldmode = regs.x.ax;
  161.  
  162.     regs.h.ah = SET_RCV_MODE;
  163.     regs.x.cx = mode;
  164.     regs.x.bx = handle;
  165.     int86(intno,®s,®s);
  166.     if(regs.x.cflag){
  167.         Derr = regs.h.dh;
  168.         return -1;
  169.     }
  170.     return oldmode;
  171. }
  172.