Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

clib/TCPIP.C

Go to the documentation of this file.
00001 /****************************************************************************
00002 *
00003 * (C) 2000 by BECK IPC GmbH
00004 *
00005 *  BECK IPC GmbH
00006 *  Garbenheimerstr. 38
00007 *  D-35578 Wetzlar
00008 *
00009 *  Phone : (49)-6441-905-240
00010 *  Fax   : (49)-6441-905-245
00011 *
00012 * ---------------------------------------------------------------------------
00013 * Module         : IPC@Chip SC12 API :tcpip.c
00014 *
00015 * Function       : TCPIP API socket functions
00016 *                  Use memory model large!!!!
00017 *
00018 * Author        : bartat
00019 * Date          : 22.01.00
00020 * ---------------------------------------------------------------------------
00021 $Log:
00022  25   IPC@CHIP  1.24        23.05.2002 12:04:08  Markus Bartat   Modified htons
00023       function: Implemented as a simple byte exchange,
00024       not necessayr to call int86x for this
00025  24   IPC@CHIP  1.23        07.05.2002 14:50:50  Markus Bartat   added
00026       C-function for TCPAPI call 0x22 Get_tcp-socket_state
00027  23   IPC@CHIP  1.22        01.03.2002 18:49:25  Markus Bartat   added functions
00028       for API calls 0x45,0x44,0x55
00029  22   IPC@CHIP  1.21        26.02.2002 18:45:51  Christoph Stoidner Add
00030       PPPSetPPPOption
00031  21   IPC@CHIP  1.20        30.01.2002 12:52:06  Markus Bartat   added extendend
00032       dhcp_stat function 0x73
00033  20   IPC@CHIP  1.19        23.01.2002 16:40:26  Christoph Stoidner delete
00034       unused timeout variable
00035  19   IPC@CHIP  1.18        14.01.2002 13:33:36  Christoph Stoidner add new
00036       functions (Set/get Idle timeout: 0x79)
00037  18   IPC@CHIP  1.17        14.01.2002 13:19:05  Christoph Stoidner add new
00038       functions
00039  17   IPC@CHIP  1.16        14.12.2001 11:55:07  Markus Bartat   Added C
00040       functions and define for TCPIP API calls 0x90-0x92
00041  16   IPC@CHIP  1.15        17.09.2001 12:40:22  Markus Bartat   added tcpip api
00042       call 0x67
00043  15   IPC@CHIP  1.14        23.07.2001 10:18:10  Christoph Stoidner Bugfix in
00044       CloseSocket func.
00045  14   IPC@CHIP  1.13        21.06.2001 13:53:31  Markus Bartat   added tcpip api
00046       call 0x19
00047  13   IPC@CHIP  1.12        19.06.2001 13:35:08  Markus Bartat   start: Added
00048       comments to the c functions
00049  12   IPC@CHIP  1.11        01.06.2001 12:20:28  Markus Bartat   added new
00050       functions
00051  11   IPC@CHIP  1.10        31.05.2001 16:19:03  Christoph Stoidner
00052  10   IPC@CHIP  1.9         31.05.2001 14:27:46  Christoph Stoidner
00053  9    IPC@CHIP  1.8         31.05.2001 09:18:00  Markus Bartat   bugfix snmp_get
00054  8    IPC@CHIP  1.7         29.05.2001 16:04:20  Markus Bartat   added aPI call
00055       0x60 Get access to internal snmp variables
00056  7    IPC@CHIP  1.6         19.04.2001 10:44:25  Markus Bartat   bugfix at
00057       tcp_connect: parameter error was overwritten by
00058       closesocket calls
00059  6    IPC@CHIP  1.5         14.03.2001 16:56:21  Christoph Stoidner
00060  5    IPC@CHIP  1.4         14.03.2001 16:55:09  Christoph Stoidner convert
00061       datatypes to prevent compiler warnings
00062  4    IPC@CHIP  1.3         14.03.2001 16:52:42  Christoph Stoidner
00063  3    IPC@CHIP  1.2         08.03.2001 15:30:17  Christoph Stoidner
00064  2    IPC@CHIP  1.1         08.03.2001 11:33:19  Ernest Schlösser Added a
00065       tcp_connect function to create a socket and connect to a server
00066  1    IPC@CHIP  1.0         14.02.2001 16:09:59  Christoph Stoidner
00067 $
00068 
00069 * History       :
00070 *
00071 *  Vx.yy                   Author  Changes
00072 *
00073 *             22.01.00      mb    Create
00074 *             28.01.00      mb     add calls setlinger and set reuse
00075 *             06.05.00      mb     add ppp client API calls
00076 *             26.06.00      mb     add ppp server API calls
00077 *             14.07.00      mb     add reconfig, dhcp  and ip setting API calls
00078               18.07.00      mb     add TCPIP statistics
00079               24.08.00      mb     add PPP client API calls
00080               06.09.00      mb     add set and getsockopt calls
00081               15.09.00      mb     add ping api calls
00082               07.11.00      mb     add memory information call
00083               08.12.00      mb     add routing calls
00084               22.12.00      mb     add blocking mode call for sockets
00085               30.05.01      mb    add API_SNMP_GET function
00086               01.06.01      mb    add telnet and ftp login functions
00087               20.06.01      mb     add register callback function
00088               17.09.01      mb     add get telnet state function
00089               30.01.02      mb     add dhcp_stat_ext function (requires BIOS 1.03B or higher)
00090               25.02.02      mb/cs  added new function PPP_GET_DNSIP 0x44 and pppsetoptions 0x45,0x55
00091               07.05.02      mb     added TCP API function 0x22, get state of tcp socket
00092 *****************************************************************************/
00093 #include <DOS.H>
00094 #include <STDLIB.H>
00095 #include "CLIB/TCPIPAPI.H"
00096 #include "CLIB/TCPIP.H"
00097 
00098 
00099 
00100 /*****************************************************************************
00101 *
00102 * open a tcp connection
00103 *
00104 * DestIPStr: destionation IP address format xxx.xxx.xxx.xxx
00105 * ClientPort: local port (0=random port)
00106 * HostPort: remote port
00107 * error: TCP/IP error
00108 *
00109 *
00110 * return: socket descriptor (-1 = error)
00111 */
00112 
00113 int tcp_connect(char *DestIPStr, unsigned int ClientPort, unsigned int HostPort, int *error)
00114 {
00115   struct sockaddr_in addr;
00116   unsigned long DestIPAddr;
00117   int sd; // socket descriptor
00118         int dummyerror;
00119 
00120   // open socket
00121   sd = opensocket(SOCK_STREAM,error);
00122   if (sd==-1 || *error!=0)
00123   {
00124     return -1;
00125   }
00126 
00127   addr.sin_family = PF_INET;
00128   addr.sin_port = htons(ClientPort);  // convert byte order
00129   addr.sin_addr.s_addr =  0;
00130   if (ClientPort!=0)
00131   { // force client port
00132     bind(sd, (struct sockaddr *)&addr, error);
00133     if (*error!=0)
00134     {
00135                    closesocket(sd, &dummyerror);
00136       return -1;
00137     }
00138   }
00139   addr.sin_port = htons(HostPort);  // convert byte order
00140 
00141   // convert server IP address string to binary
00142   *error = inet_addr(DestIPStr,&DestIPAddr);
00143   if (*error!=0)
00144   {
00145              closesocket(sd, &dummyerror);
00146     return -1;
00147   }
00148   addr.sin_addr.s_addr = DestIPAddr;
00149 
00150   // establish a connection to the FTP server
00151   connect(sd, (struct sockaddr *) &addr, error);
00152   if (*error!=0)
00153   {
00154             closesocket(sd, &dummyerror);
00155     return -1;
00156   };
00157 
00158   *error = 0;
00159   return sd;
00160 
00161 } // tcp_connect()
00162 
00163 
00164 
00165 /*************************************************************************/
00166 //accept
00167 /*************************************************************************/
00168 int accept(int sd, struct sockaddr * addressPtr, int *error)
00169 {
00170 
00171     union  REGS  inregs;
00172     union  REGS  outregs;
00173 
00174     *error = 0;
00175 
00176     inregs.h.ah     = API_ACCEPT;
00177     inregs.x.bx     = sd;
00178 
00179     inregs.x.dx     = FP_SEG(addressPtr);
00180     inregs.x.si     = FP_OFF(addressPtr);
00181 
00182     int86(TCPIPVECT,&inregs,&outregs);
00183 
00184     if(outregs.x.dx == (unsigned int)API_ERROR)
00185     {
00186       *error =  outregs.x.ax;
00187       return API_ERROR;
00188     }
00189     //return socketdescriptor
00190     *error = 0;
00191     return outregs.x.ax;
00192 }
00193 
00194 /*************************************************************************/
00195 //sleep
00196 /*************************************************************************/
00197 void api_sleep(unsigned int howlong)
00198 {
00199   union  REGS  inregs;
00200   union  REGS  outregs;
00201 
00202   inregs.h.ah     = API_SLEEP;
00203   inregs.x.bx     = howlong;
00204   int86(TCPIPVECT,&inregs,&outregs);
00205 }
00206 /*************************************************************************/
00207 //bind
00208 /*************************************************************************/
00209 int bind(int sd, struct sockaddr * addressPtr, int *error)
00210 {
00211 
00212   union  REGS  inregs;
00213   union  REGS  outregs;
00214 
00215   *error = 0;
00216   inregs.h.ah     = API_BIND;
00217   inregs.x.bx     = sd;
00218   inregs.x.dx     = FP_SEG(addressPtr);
00219   inregs.x.si     = FP_OFF(addressPtr);
00220   int86(TCPIPVECT,&inregs,&outregs);
00221 
00222   if(outregs.x.dx == (unsigned int)API_ERROR)
00223   {
00224      *error = outregs.x.ax;
00225   }
00226   return outregs.x.dx;
00227 }
00228 /*************************************************************************/
00229 //connect
00230 /*************************************************************************/
00231 int connect(int sd, struct sockaddr * addressPtr, int *error)
00232 {
00233 
00234   union  REGS  inregs;
00235   union  REGS  outregs;
00236 
00237 
00238   *error = 0;
00239 
00240   inregs.h.ah     = API_CONNECT;
00241   inregs.x.bx     = sd;
00242   inregs.x.dx     = FP_SEG(addressPtr);
00243   inregs.x.si     = FP_OFF(addressPtr);
00244   int86(TCPIPVECT,&inregs,&outregs);
00245 
00246   if(outregs.x.dx == (unsigned int)API_ERROR)
00247   {
00248      *error = outregs.x.ax;
00249 
00250   }
00251   return outregs.x.dx;
00252 }
00253 
00254 
00255 /*************************************************************************/
00256 //closesocket
00257 /*************************************************************************/
00258 int closesocket(int sd, int *error)
00259 {
00260 
00261   union  REGS  inregs;
00262   union  REGS  outregs;
00263 
00264   inregs.h.ah = API_CLOSESOCKET;
00265   inregs.x.bx = sd;
00266   int86(TCPIPVECT,&inregs,&outregs);
00267 
00268   if(outregs.x.dx==(unsigned int)API_ERROR)
00269   {
00270     *error = outregs.x.ax;
00271           return API_ERROR;
00272   }
00273   *error = 0;
00274   return outregs.x.dx;
00275 }
00276 
00277 /*************************************************************************/
00278 //get waiting bytes
00279 /*************************************************************************/
00280 int GetWaitingBytes(int sd, int *error)
00281 {
00282   union  REGS  inregs;
00283   union  REGS  outregs;
00284 
00285   inregs.h.ah      = API_GETRCV_BYTES;
00286   inregs.x.bx      = sd;
00287   int86(TCPIPVECT,&inregs,&outregs);
00288 
00289   if(outregs.x.dx==(unsigned int)API_ERROR)
00290   {
00291     *error = outregs.x.ax;
00292     return API_ERROR;
00293   }
00294   *error = 0;
00295   return outregs.x.ax;
00296 }
00297 /*************************************************************************/
00298 //htons
00299 /*************************************************************************/
00300 unsigned int htons(unsigned int value)
00301 {
00302 
00303     asm
00304     {
00305       mov ax,value
00306       ror ax, 8
00307     }
00308     return  (unsigned short)_AX;
00309 }
00310 
00311 /*************************************************************************/
00312 //listen
00313 /*************************************************************************/
00314 int listen(int sd,int backlog, int *error)
00315 {
00316   union  REGS  inregs;
00317   union  REGS  outregs;
00318 
00319   inregs.h.ah      = API_LISTEN;
00320   inregs.x.bx      = sd;
00321   inregs.x.cx      = backlog;
00322 
00323   int86(TCPIPVECT,&inregs,&outregs);
00324 
00325   if(outregs.x.dx == (unsigned int)API_ERROR)
00326   {
00327     *error = outregs.x.ax;
00328     return API_ERROR;
00329   }
00330   *error = 0;
00331   return 0;
00332 }
00333 /*************************************************************************/
00334 //inet_addr
00335 /*************************************************************************/
00336 int inet_addr(char * IPAddressStringPtr, unsigned long * IPAddress)
00337 {
00338   union  REGS  inregs;
00339   union  REGS  outregs;
00340   struct SREGS sregs;
00341 
00342   inregs.h.ah      = API_INETADDR;
00343   inregs.x.bx      = FP_SEG(IPAddressStringPtr);
00344   inregs.x.si      = FP_OFF(IPAddressStringPtr);
00345   sregs.es         = FP_SEG(IPAddress);
00346   inregs.x.di      = FP_OFF(IPAddress);
00347   int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00348   return outregs.x.dx;
00349 }
00350 /*************************************************************************/
00351 //inet_to ascii
00352 /*************************************************************************/
00353 int InetToAscii(unsigned long * IPAddress, char * IPAddressStringPtr)
00354 {
00355 
00356     union  REGS  inregs;
00357     union  REGS  outregs;
00358     struct SREGS sregs;
00359 
00360     inregs.h.ah     = API_INETTOASCII;
00361     inregs.x.bx     = FP_SEG(IPAddress);
00362     inregs.x.si     = FP_OFF(IPAddress);
00363     sregs.es        = FP_SEG(IPAddressStringPtr);
00364     inregs.x.di     = FP_OFF(IPAddressStringPtr);
00365     int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00366     return 0;
00367 }
00368 /*************************************************************************/
00369 //recvfrom
00370 /*************************************************************************/
00371 int recvfrom(int sd, char * bufptr, int bufLen, int flags,
00372          unsigned long timeout,struct sockaddr * fromPtr, int *error)
00373 {
00374     int fromLen;
00375     struct recv_params R;
00376     union  REGS  inregs;
00377     union  REGS  outregs;
00378 
00379     //fill the struct recv_param R
00380     fromLen          =   sizeof(struct sockaddr_in);
00381     R.bufferPtr      =   bufptr;
00382     R.bufferLength   =   bufLen;
00383     R.flags          =   flags;
00384     R.fromPtr        =   (struct sockaddr *)fromPtr;
00385     R.fromlengthPtr  =   &fromLen;
00386     R.timeout        =   timeout; /*milliseconds*/
00387 
00388     //API
00389     inregs.h.ah      = API_RECVFROM;
00390     inregs.x.bx      = sd;
00391     inregs.x.dx      = FP_SEG(&R);
00392     inregs.x.si      = FP_OFF(&R);
00393     int86(TCPIPVECT,&inregs,&outregs);
00394 
00395     if(outregs.x.dx == (unsigned int)API_ERROR)
00396     {
00397       *error = outregs.x.ax;
00398       return API_ERROR;
00399     }
00400 
00401     *error = 0;
00402     return outregs.x.ax;
00403 }
00404 /*************************************************************************/
00405 //recv
00406 /*************************************************************************/
00407 int recv(int sd, char * bufptr, int bufLen, int flags, unsigned long timeout,
00408       int *error)
00409 {
00410 
00411     struct recv_params R;
00412     union  REGS  inregs;
00413     union  REGS  outregs;
00414 
00415     //fill the struct recv_param R
00416     R.bufferPtr      =   bufptr;
00417     R.bufferLength   =   bufLen;
00418     R.flags          =   flags;
00419     R.timeout        =   timeout;
00420     R.fromPtr        =   NULL;
00421     R.fromlengthPtr  =   NULL;
00422 
00423     inregs.h.ah      = API_RECV;
00424     inregs.x.bx      = sd;
00425     inregs.x.dx      = FP_SEG(&R);
00426     inregs.x.si      = FP_OFF(&R);
00427     int86(TCPIPVECT,&inregs,&outregs);
00428 
00429     if(outregs.x.dx == (unsigned int)API_ERROR)
00430     {
00431       *error = outregs.x.ax;
00432       return API_ERROR;
00433     }
00434     *error = 0;
00435     return outregs.x.ax;
00436 }
00437 /*************************************************************************/
00438 //reset connection
00439 /*************************************************************************/
00440 int ResetConnection(int sd, int *error)
00441 {
00442     union  REGS  inregs;
00443     union  REGS  outregs;
00444 
00445     inregs.h.ah      = API_RESETCONNECTION;
00446     inregs.x.bx      = sd;
00447     int86(TCPIPVECT,&inregs,&outregs);
00448      if(outregs.x.dx == (unsigned int)API_ERROR)
00449     {
00450       *error = outregs.x.ax;
00451       return API_ERROR;
00452     }
00453     *error = 0;
00454     return 0;
00455 }
00456 /*************************************************************************/
00457 //sendto
00458 /*************************************************************************/
00459 int sendto(int sd, char * bufptr, int bufLen, int flags,
00460         const struct sockaddr * toPtr, int *error)
00461 {
00462 
00463     int toLen;
00464     struct send_params S;
00465     union  REGS  inregs;
00466     union  REGS  outregs;
00467 
00468     //Init the struct send_param S for API-Call
00469     toLen            = sizeof(struct sockaddr_in);
00470     S.bufferPtr      = bufptr;
00471     S.bufferLength   = bufLen;
00472     S.flags          = flags;
00473     S.toPtr          = (struct sockaddr *)toPtr;
00474     S.tolengthPtr    = &toLen;
00475 
00476     inregs.h.ah      = API_SENDTO;
00477     inregs.x.bx      = sd;
00478     inregs.x.dx      = FP_SEG(&S);
00479     inregs.x.si      = FP_OFF(&S);
00480     int86(TCPIPVECT,&inregs,&outregs);
00481 
00482     if(outregs.x.dx == (unsigned int)API_ERROR)
00483     {
00484      *error = outregs.x.ax;
00485      return API_ERROR;
00486     }
00487     *error = 0;
00488     return outregs.x.ax;
00489 }
00490 
00491 /*************************************************************************/
00492 //send
00493 /*************************************************************************/
00494 int send(int sd, char * bufptr, int bufLen, int flags, int *error)
00495 {
00496     struct send_params S;
00497     union  REGS  inregs;
00498     union  REGS  outregs;
00499 
00500     //fill the struct send_param S
00501     S.bufferPtr      =   bufptr;
00502     S.bufferLength   =   bufLen;
00503     S.flags          =   flags;
00504     S.toPtr          =   NULL;
00505     S.tolengthPtr    =   NULL;
00506 
00507     inregs.h.ah      = API_SEND;
00508     inregs.x.bx      = sd;
00509     inregs.x.dx      = FP_SEG(&S);
00510     inregs.x.si      = FP_OFF(&S);
00511     int86(TCPIPVECT,&inregs,&outregs);
00512 
00513     if(outregs.x.dx == (unsigned int)API_ERROR)
00514     {
00515       *error = outregs.x.ax;
00516       return API_ERROR;
00517     }
00518     *error = 0;
00519     return outregs.x.ax;
00520 }
00521 /*************************************************************************/
00522 //set linger time on close
00523 /*************************************************************************/
00524 int setlinger(int sd, int seconds, int *error)
00525 {
00526    union  REGS  inregs;
00527    union  REGS  outregs;
00528    inregs.h.ah = API_SETLINGER;
00529    inregs.x.bx = sd;
00530    inregs.x.cx = seconds;
00531 
00532    int86(TCPIPVECT,&inregs,&outregs);
00533 
00534    if(outregs.x.dx == (unsigned int)API_ERROR)
00535    {
00536       *error = outregs.x.ax;
00537       return API_ERROR;
00538    }
00539    *error = 0;
00540    return outregs.x.ax;
00541 }
00542 /*************************************************************************/
00543 //set resuse option on a listening socket
00544 /*************************************************************************/
00545 int setreuse(int sd,int *error)
00546 {
00547    union  REGS  inregs;
00548    union  REGS  outregs;
00549    inregs.h.ah = API_SETREUSE;
00550    inregs.x.bx = sd;
00551 
00552    int86(TCPIPVECT,&inregs,&outregs);
00553 
00554    if(outregs.x.dx == (unsigned int)API_ERROR)
00555    {
00556       *error = outregs.x.ax;
00557       return API_ERROR;
00558    }
00559    *error = 0;
00560    return outregs.x.ax;
00561 }
00562 
00563 /*********************************************************************************/
00564 //@CHIP-RTOS with SNMP support only:
00565 // search for tcp socket by lgiven local and return state,remote ip and local port
00566 /*********************************************************************************/
00567 
00568 unsigned char Get_TCP_Socket_State(unsigned int localPort, unsigned long * remoteIP, unsigned int * remotePort)
00569 {
00570 
00571    union  REGS  inregs;
00572   union  REGS  outregs;
00573   struct SREGS sregs;
00574 
00575   inregs.h.ah      = API_GET_TCP_STATE;
00576    inregs.x.bx      = localPort;
00577   sregs.es         = FP_SEG(remoteIP);
00578   inregs.x.di      = FP_OFF(remoteIP);
00579   int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00580    *remotePort = outregs.x.cx;
00581   return outregs.h.al;
00582 }
00583 /*************************************************************************/
00584 //get last socket error
00585 /*************************************************************************/
00586 int get_socketerror(int sd)
00587 {
00588    union  REGS  inregs;
00589    union  REGS  outregs;
00590 
00591    inregs.h.ah = API_GET_SOCKETERROR;
00592    inregs.x.bx = sd;
00593 
00594    int86(TCPIPVECT,&inregs,&outregs);
00595 
00596    return outregs.x.ax;
00597 }
00598 
00599 /*************************************************************************/
00600 //Set IP Type-Of-Service on a socket
00601 /*************************************************************************/
00602 int Set_IP_Type_Of_Service(int sd, unsigned char TOS, int *error)
00603 {
00604 
00605    union  REGS  inregs;
00606   union  REGS  outregs;
00607 
00608    *error=0;
00609    inregs.h.ah = API_SETIPTOS;
00610    inregs.h.al = TOS;
00611    inregs.x.bx = sd;
00612   int86(TCPIPVECT,&inregs,&outregs);
00613    if((int)outregs.x.ax==-1)
00614    {
00615       *error = outregs.x.dx;
00616    }
00617    return  outregs.x.ax;
00618 
00619 }
00620 
00621 /*************************************************************************/
00622 //get and set socket option
00623 /*************************************************************************/
00624 
00625 int setsockopt(int sd, SetSocketOption *sockoptptr, int *error)
00626 {
00627   union  REGS  inregs;
00628   union  REGS  outregs;
00629    struct SREGS sregs;
00630 
00631    *error=0;
00632    inregs.h.ah = API_SETSOCKOPT;
00633    inregs.x.bx = sd;
00634    sregs.es    = FP_SEG(sockoptptr);
00635    inregs.x.di = FP_OFF(sockoptptr);
00636    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00637 
00638    if((int)outregs.x.dx==-1)
00639    {
00640       *error = outregs.x.ax;
00641    }
00642    return  outregs.x.dx;
00643 }
00644 
00645 int getsockopt(int sd, GetSocketOption *sockoptptr, int *error)
00646 {
00647    union  REGS  inregs;
00648   union  REGS  outregs;
00649    struct SREGS sregs;
00650 
00651    *error=0;
00652    inregs.h.ah = API_GETSOCKOPT;
00653    inregs.x.bx = sd;
00654    sregs.es    = FP_SEG(sockoptptr);
00655    inregs.x.di = FP_OFF(sockoptptr);
00656    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00657 
00658    if((int)outregs.x.dx==-1)
00659    {
00660       *error = outregs.x.ax;
00661    }
00662    return  outregs.x.dx;
00663 }
00664 
00665 
00666 /*************************************************************************/
00667 //Set blocking mode on a socket (default is blocking!!)
00668 /*************************************************************************/
00669 int Set_Blocking_Mode(int sd, unsigned char mode, int *error)
00670 {
00671 
00672    union  REGS  inregs;
00673    union  REGS  outregs;
00674 
00675    *error=0;
00676    inregs.h.ah = API_SETBLOCKINGMODE;
00677    inregs.h.al = mode;
00678    inregs.x.bx = sd;
00679    int86(TCPIPVECT,&inregs,&outregs);
00680    if((int)outregs.x.dx==-1)
00681    {
00682       *error = outregs.x.ax;
00683    }
00684    return  outregs.x.dx;
00685 }
00686 
00687 /*************************************************************************/
00688 //open socket
00689 /*************************************************************************/
00690 int opensocket(unsigned char type, int *error)
00691 {
00692 
00693   union  REGS  inregs;
00694   union  REGS  outregs;
00695 
00696   inregs.h.ah = API_OPENSOCKET;
00697   inregs.h.al = type;
00698 
00699 
00700   int86(TCPIPVECT,&inregs,&outregs);
00701 
00702   if(outregs.x.dx == (unsigned int)API_ERROR)
00703   {
00704     *error = outregs.x.ax;
00705     return API_ERROR;
00706   }
00707   *error = 0;
00708   return outregs.x.ax;
00709 }
00710 
00711 
00712 /*************************************************************************/
00713 //Register callback function on socket events
00714 /*************************************************************************/
00715 int RegisterCallbackFunction(int sd, void * funcptr, int eventflagmask ,int *error)
00716 {
00717 
00718    union  REGS  inregs;
00719   union  REGS  outregs;
00720    struct SREGS sregs;
00721 
00722    *error=0;
00723    inregs.h.ah      = API_REGISTERCALLBACK;
00724    inregs.x.bx      = sd;
00725    inregs.x.cx      = eventflagmask;
00726   sregs.es         = FP_SEG(funcptr);
00727   inregs.x.di      = FP_OFF(funcptr);
00728    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00729 
00730    if((int)outregs.x.dx==-1)
00731    {
00732       *error = outregs.x.ax;
00733    }
00734    return  outregs.x.dx;
00735 }
00736 
00737 
00738 
00739 /*************************************************************************/
00740 //PPP client installed
00741 /*************************************************************************/
00742 int PPP_Client_Installed(void)
00743 {
00744 
00745    union  REGS  inregs;
00746   union  REGS  outregs;
00747 
00748    inregs.h.ah      = PPPCLIENT_INSTALLED;
00749    int86(TCPIPVECT,&inregs,&outregs);
00750 
00751    return  outregs.x.ax;
00752 }
00753 
00754 
00755 /*************************************************************************/
00756 //PPP client open
00757 /*************************************************************************/
00758 int PPP_Client_Open(PPPClient_Init * ptr, int *error)
00759 {
00760 
00761    union  REGS  inregs;
00762   union  REGS  outregs;
00763    struct SREGS sregs;
00764 
00765    *error=0;
00766 
00767    inregs.h.ah      = PPPCLIENT_OPEN;
00768   sregs.es         = FP_SEG(ptr);
00769   inregs.x.di      = FP_OFF(ptr);
00770    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00771 
00772    if((int)outregs.x.dx==-1)
00773    {
00774       *error = outregs.x.ax;
00775    }
00776 
00777    return  outregs.x.dx;
00778 }
00779 
00780 
00781 
00782 /*************************************************************************/
00783 //PPP client close
00784 /*************************************************************************/
00785 int PPP_Client_Close(int *error)
00786 {
00787 
00788    union  REGS  inregs;
00789   union  REGS  outregs;
00790 
00791    *error=0;
00792    inregs.h.ah = PPPCLIENT_CLOSE;
00793   int86(TCPIPVECT,&inregs,&outregs);
00794 
00795    if((int)outregs.x.dx==-1)
00796    {
00797       *error = outregs.x.ax;
00798    }
00799    return  outregs.x.ax;
00800 }
00801 
00802 /*************************************************************************/
00803 //PPP client get status
00804 /*************************************************************************/
00805 int PPP_Client_GetStatus(int *error)
00806 {
00807 
00808    union  REGS  inregs;
00809   union  REGS  outregs;
00810 
00811    inregs.h.ah = PPPCLIENT_GET_STATUS;
00812   int86(TCPIPVECT,&inregs,&outregs);
00813 
00814    if((int)outregs.x.ax==-1)
00815    {
00816       *error = outregs.x.dx;
00817    }
00818    return  outregs.x.ax;
00819 }
00820 
00821 
00822 /*************************************************************************/
00823 //PPP client set options
00824 /*************************************************************************/
00825 int PPP_Client_SetOptions(PPP_Option *ptr)
00826 {
00827 
00828    union  REGS  inregs;
00829   union  REGS  outregs;
00830    struct SREGS segregs;
00831 
00832    inregs.h.ah = PPPCLIENT_SET_OPTIONS;
00833    segregs.es  = FP_SEG(ptr);
00834    inregs.x.di = FP_OFF(ptr);
00835   int86x(TCPIPVECT,&inregs,&outregs,&segregs);
00836 
00837    return  outregs.x.ax;
00838 }
00839 
00840 
00841 /*************************************************************************/
00842 //PPP client get DNS IP as negotiated by the remote PPP server
00843 /*************************************************************************/
00844 int PPP_Client_Get_DNSIP(unsigned long * IPaddress, int primary_sec, int *error)
00845 {
00846 
00847    union  REGS  inregs;
00848   union  REGS  outregs;
00849    struct SREGS sregs;
00850 
00851    *error=0;
00852 
00853    inregs.h.ah      = PPPCLIE_GET_DNSIP;
00854    inregs.x.bx      = primary_sec;
00855   sregs.es         = FP_SEG(IPaddress);
00856   inregs.x.di      = FP_OFF(IPaddress);
00857    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00858 
00859    if((int)outregs.x.ax==-1)
00860    {
00861       *error = outregs.x.dx;
00862    }
00863 
00864    return  outregs.x.dx;
00865 }
00866 
00867 /*************************************************************************/
00868 //PPP server installed
00869 /*************************************************************************/
00870 
00871 int PPP_Server_Installed(void)
00872 {
00873    union  REGS  inregs;
00874   union  REGS  outregs;
00875 
00876    inregs.h.ah = PPPSERVER_INSTALLED;
00877   int86(TCPIPVECT,&inregs,&outregs);
00878    return  outregs.x.ax;
00879 }
00880 
00881 
00882 /*************************************************************************/
00883 //PPP server suspend
00884 /*************************************************************************/
00885 int PPP_Server_Suspend(int timeoutsecs, int *error)
00886 {
00887 
00888    union  REGS  inregs;
00889   union  REGS  outregs;
00890 
00891    *error=0;
00892    inregs.h.ah = PPPSERVER_SUSPEND;
00893    inregs.x.bx = timeoutsecs;
00894   int86(TCPIPVECT,&inregs,&outregs);
00895    if((int)outregs.x.ax==-1)
00896    {
00897       *error = outregs.x.dx;
00898    }
00899    return  outregs.x.ax;
00900 
00901 }
00902 
00903 /*************************************************************************/
00904 //PPP server  activate
00905 /*************************************************************************/
00906 int PPP_Server_Activate(int timeoutsecs,int *error)
00907 {
00908    union  REGS  inregs;
00909   union  REGS  outregs;
00910 
00911    *error=0;
00912    inregs.h.ah = PPPSERVER_ACTIVATE;
00913    inregs.x.bx = timeoutsecs;
00914   int86(TCPIPVECT,&inregs,&outregs);
00915    if((int)outregs.x.ax==-1)
00916    {
00917       *error = outregs.x.dx;
00918    }
00919    return  outregs.x.ax;
00920 }
00921 
00922 
00923 /*************************************************************************/
00924 //PPP server  get config
00925 /*************************************************************************/
00926 int PPP_Server_Get_Cfg(PPP_IPCfg_Data *ptr , int *error)
00927 {
00928    union  REGS  inregs;
00929   union  REGS  outregs;
00930    struct SREGS sregs;
00931 
00932    *error=0;
00933 
00934    inregs.h.ah = PPPSERVER_GET_CFG;
00935    sregs.es    = FP_SEG(ptr);
00936    inregs.x.di = FP_OFF(ptr);
00937    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00938 
00939    if((int)outregs.x.ax==-1)
00940    {
00941       *error = outregs.x.dx;
00942    }
00943    return  outregs.x.ax;
00944 }
00945 /*************************************************************************/
00946 //PPP server, get status
00947 /*************************************************************************/
00948 int PPP_Server_GetStatus(void)
00949 {
00950 
00951    union  REGS  inregs;
00952   union  REGS  outregs;
00953 
00954 
00955    inregs.h.ah = PPPSERVER_GET_STATUS;
00956 
00957   int86(TCPIPVECT,&inregs,&outregs);
00958    return  outregs.x.ax;
00959 }
00960 
00961 /*************************************************************************/
00962 //PPP server set options
00963 /*************************************************************************/
00964 int PPP_Server_SetOptions(PPP_Option *ptr)
00965 {
00966 
00967    union  REGS  inregs;
00968   union  REGS  outregs;
00969    struct SREGS segregs;
00970 
00971    inregs.h.ah = PPPSERVER_SET_OPTIONS;
00972    segregs.es  = FP_SEG(ptr);
00973    inregs.x.di = FP_OFF(ptr);
00974   int86x(TCPIPVECT,&inregs,&outregs,&segregs);
00975 
00976    return  outregs.x.ax;
00977 }
00978 
00979 
00980 /*************************************************************************/
00981 //Get pointer to internal TCIP SNMP mib structures
00982 /*************************************************************************/
00983 int Get_SNMP_Data(unsigned char which , void * * snmp_mib_ptr)
00984 {
00985    union  REGS  inregs;
00986   union  REGS  outregs;
00987    struct SREGS sregs;
00988 
00989 
00990    inregs.h.ah = API_SNMP_GET;
00991    inregs.h.al = which;
00992    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
00993 
00994    if((int)outregs.x.ax==0)
00995    {
00996       *snmp_mib_ptr = (void *)MK_FP(sregs.es,outregs.x.di);
00997       return 0;
00998    }
00999    return  outregs.x.ax;
01000 }
01001 
01002 /*************************************************************************/
01003 //FTP server: Return the addresss of the FTPserver login counters
01004 /*************************************************************************/
01005 int Get_FTP_Login_Counters(unsigned long * * FTP_Login_Count,unsigned long * * FTP_Login_failCount)
01006 {
01007   union  REGS  inregs;
01008   union  REGS  outregs;
01009   struct SREGS sregs;
01010 
01011 
01012   inregs.h.ah = API_FTP_GET_LOGIN;
01013   int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01014 
01015   *FTP_Login_Count     = NULL;
01016   *FTP_Login_failCount = NULL;
01017   if(outregs.x.ax==0)
01018   {
01019     *FTP_Login_Count     = (unsigned long *)MK_FP(sregs.es,outregs.x.di);
01020     *FTP_Login_failCount = (unsigned long *)MK_FP(sregs.ds,outregs.x.si);
01021   }
01022   return outregs.x.ax;
01023 }
01024 
01025 /*************************************************************************/
01026 //Telnet server: Return the addresss of the Telnetserver login counters
01027 /*************************************************************************/
01028 int Get_Telnet_Login_Counters(unsigned long * * Telnet_Login_Count,unsigned long * * Telnet_Login_failCount)
01029 {
01030   union  REGS  inregs;
01031   union  REGS  outregs;
01032   struct SREGS sregs;
01033 
01034 
01035   *Telnet_Login_Count     = NULL;
01036   *Telnet_Login_failCount = NULL;
01037 
01038   inregs.h.ah = API_TELNET_GET_LOGIN;
01039   int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01040 
01041   if(outregs.x.ax==0)
01042   {
01043     *Telnet_Login_Count     = (unsigned long *)MK_FP(sregs.es,outregs.x.di);
01044     *Telnet_Login_failCount = (unsigned long *)MK_FP(sregs.ds,outregs.x.si);
01045   }
01046   return outregs.x.ax;
01047 }
01048 
01049 /*************************************************************************/
01050 //Set FTP Server Idle timeout (using: Set/Get Server Idle Timeout)
01051 /*************************************************************************/
01052 int Set_FTPServer_Idle_Timeout( unsigned timeout )
01053 {
01054    union  REGS  inregs;
01055    union  REGS  outregs;
01056 
01057    inregs.h.ah = SET_SERVER_IDLE_TIMEOUT;
01058    inregs.h.al = 0x00; // set timeout
01059    inregs.x.bx = 0x00; // Ftp server
01060    inregs.x.dx = timeout;
01061    int86( TCPIPVECT, &inregs, &outregs );
01062 
01063    return outregs.x.ax;
01064 }
01065 
01066 /*************************************************************************/
01067 //Set Telnet Server Idle timeout (using: Set/Get Server Idle Timeout)
01068 /*************************************************************************/
01069 int Set_TelnetServer_Idle_Timeout( unsigned timeout )
01070 {
01071    union  REGS  inregs;
01072    union  REGS  outregs;
01073 
01074    inregs.h.ah = SET_SERVER_IDLE_TIMEOUT;
01075    inregs.h.al = 0x00; // set timeout
01076    inregs.x.bx = 0x01; // Telnet server
01077    inregs.x.dx = timeout;
01078    int86( TCPIPVECT, &inregs, &outregs );
01079 
01080    return outregs.x.ax;
01081 }
01082 
01083 /*************************************************************************/
01084 //Get FTP Server Idle timeout (using: Set/Get Server Idle Timeout)
01085 /*************************************************************************/
01086 unsigned Get_FTPServer_Idle_Timeout(void)
01087 {
01088    union  REGS  inregs;
01089    union  REGS  outregs;
01090 
01091    inregs.h.ah = SET_SERVER_IDLE_TIMEOUT;
01092    inregs.h.al = 0x01; // get timeout
01093    inregs.x.bx = 0x00; // ftp server
01094    int86( TCPIPVECT, &inregs, &outregs );
01095 
01096    return outregs.x.dx;
01097 }
01098 
01099 
01100 /*************************************************************************/
01101 //Get Telnet Server Idle timeout (using: Set/Get Server Idle Timeout)
01102 /*************************************************************************/
01103 unsigned Get_TelnetServer_Idle_Timeout(void)
01104 {
01105    union  REGS  inregs;
01106    union  REGS  outregs;
01107 
01108    inregs.h.ah = SET_SERVER_IDLE_TIMEOUT;
01109    inregs.h.al = 0x01; // get timeout
01110    inregs.x.bx = 0x01; // Telnet server
01111    int86( TCPIPVECT, &inregs, &outregs );
01112 
01113    return outregs.x.dx;
01114 }
01115 
01116 /*************************************************************************/
01117 //Get telnet state
01118 /*************************************************************************/
01119 int Get_Telnet_State(int *error)
01120 {
01121    union  REGS  inregs;
01122   union  REGS  outregs;
01123 
01124    *error=0;
01125    inregs.h.ah = API_GET_TELNET_STATE;
01126   int86(TCPIPVECT,&inregs,&outregs);
01127    if((int)outregs.x.dx==-1)
01128    {
01129       *error = outregs.x.dx;
01130    }
01131    return  outregs.x.ax;
01132 }
01133 
01134 
01135 /*************************************************************************/
01136 //Get installed servers and devices of the SC12
01137 /*************************************************************************/
01138 void Get_Installed_Servers(unsigned int * AX, unsigned int *DX)
01139 {
01140   union  REGS  inregs;
01141   union  REGS  outregs;
01142 
01143   inregs.h.ah = GET_INSTALLED_SERVERS;
01144   int86(TCPIPVECT,&inregs,&outregs);
01145   *AX = outregs.x.ax;
01146   *DX = outregs.x.dx;
01147 }
01148 
01149 
01150 
01151 /*************************************************************************/
01152 //Reconfigure ethernet interface
01153 /*************************************************************************/
01154 int Reconfigure_ethernet(void)
01155 {
01156   union  REGS  inregs;
01157   union  REGS  outregs;
01158   inregs.h.ah = REINIT_ETHERNET;
01159   int86(TCPIPVECT,&inregs,&outregs);
01160   return outregs.x.ax;
01161 }
01162 
01163 /*************************************************************************/
01164 //DHCP use   dhcp_use 0/1
01165 /*************************************************************************/
01166 int DHCP_use(unsigned char dhcp_use)
01167 {
01168   union  REGS  inregs;
01169   union  REGS  outregs;
01170   inregs.h.ah = DHCP_USE;
01171   inregs.h.al = dhcp_use;
01172   int86(TCPIPVECT,&inregs,&outregs);
01173   return outregs.x.ax;
01174 }
01175 
01176 /*************************************************************************/
01177 //DHCP Stat
01178 /*************************************************************************/
01179 void Get_DHCP_Status(unsigned int * dhcp_use, unsigned int *dhcp_stat)
01180 {
01181   union  REGS  inregs;
01182   union  REGS  outregs;
01183   inregs.h.ah = DHCP_STAT;
01184   int86(TCPIPVECT,&inregs,&outregs);
01185   *dhcp_use = outregs.x.ax;
01186   *dhcp_stat = outregs.x.dx;
01187 }
01188 
01189 /*************************************************************************/
01190 //DHCP Stat extended function with getting dhcp config data
01191 //(requires BIOS 1.03B or higher)
01192 /*************************************************************************/
01193 void Get_DHCP_Status_Ext(unsigned int * dhcp_use, unsigned int *dhcp_stat, UserEthDhcp_Entry * * dhcpptr)
01194 {
01195   union  REGS  inregs;
01196   union  REGS  outregs;
01197   struct SREGS sregs;
01198   inregs.h.ah = DHCP_STAT;
01199   int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01200   *dhcp_use = outregs.x.ax;
01201   *dhcp_stat = outregs.x.dx;
01202   if(outregs.x.dx==1)
01203      *dhcpptr = (tag_UserDhcpEthEntry*)MK_FP(sregs.es,outregs.x.di);
01204   else
01205      *dhcpptr = NULL;
01206 }
01207 /*************************************************************************/
01208 //Get IP of the ethernet interface
01209 /*************************************************************************/
01210 void Get_IPConfig(char *IP, char * Mask, char *Gateway)
01211 {
01212   union  REGS  inregs;
01213   union  REGS  outregs;
01214   struct SREGS sregs;
01215 
01216   inregs.h.ah = 0x01;
01217   sregs.es    = FP_SEG(IP);
01218   inregs.x.dx = FP_OFF(IP);
01219   int86x(0xA0,&inregs,&outregs,&sregs);
01220 
01221   inregs.h.ah = 0x03;
01222   sregs.es    = FP_SEG(Mask);
01223   inregs.x.dx = FP_OFF(Mask);
01224   int86x(0xA0,&inregs,&outregs,&sregs);
01225 
01226 
01227   inregs.h.ah = 0x05;
01228   sregs.es    = FP_SEG(Gateway);
01229   inregs.x.dx = FP_OFF(Gateway);
01230   int86x(0xA0,&inregs,&outregs,&sregs);
01231 }
01232 
01233 /*************************************************************************/
01234 //Set IP configuration,becomes valid after call of reconfigure Ethernet
01235 /*************************************************************************/
01236 void Set_IPConfig(char *IP, char * Mask, char *Gateway)
01237 {
01238   union  REGS  inregs;
01239   union  REGS  outregs;
01240   struct SREGS sregs;
01241 
01242   inregs.h.ah = 0x02;
01243   sregs.es    = FP_SEG(IP);
01244   inregs.x.dx = FP_OFF(IP);
01245   int86x(0xA0,&inregs,&outregs,&sregs);
01246 
01247   inregs.h.ah = 0x04;
01248   sregs.es    = FP_SEG(Mask);
01249   inregs.x.dx = FP_OFF(Mask);
01250   int86x(0xA0,&inregs,&outregs,&sregs);
01251 
01252   inregs.h.ah = 0x06;
01253   sregs.es    = FP_SEG(Gateway);
01254   inregs.x.dx = FP_OFF(Gateway);
01255   int86x(0xA0,&inregs,&outregs,&sregs);
01256 }
01257 
01258 /*************************************************************************/
01259 //return the address of TCPIP packet counter struct
01260 /*************************************************************************/
01261 void Get_TCPIP_Statistics(Packet_Count * * Packet_Count_Pointer)
01262 {
01263   union  REGS  inregs;
01264   union  REGS  outregs;
01265   struct SREGS sregs;
01266 
01267   inregs.h.ah = TCPIP_STATISTICS;
01268   int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01269 
01270   *Packet_Count_Pointer = (Packet_Count *)MK_FP(sregs.es,outregs.x.di);
01271 
01272 }
01273 
01274 /*************************************************************************/
01275 //ping open
01276 /*************************************************************************/
01277 int Ping_Open(Ping * pingptr, int * errorcode)
01278 {
01279   union  REGS  inregs;
01280   union  REGS  outregs;
01281   struct SREGS sregs;
01282 
01283 
01284   inregs.h.ah = PING_OPEN;
01285   sregs.es    = FP_SEG(pingptr);
01286   inregs.x.di = FP_OFF(pingptr);
01287   int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01288   *errorcode=outregs.x.ax;
01289   return outregs.x.dx;
01290 }
01291 
01292 
01293 /*************************************************************************/
01294 //ping close
01295 /*************************************************************************/
01296 int Ping_Close(int sd)
01297 {
01298   union  REGS  inregs;
01299   union  REGS  outregs;
01300 
01301   inregs.h.ah = PING_CLOSE;
01302   inregs.x.bx = sd;
01303   int86(TCPIPVECT,&inregs,&outregs);
01304   return outregs.x.dx;
01305 }
01306 /*************************************************************************/
01307 //ping statistics
01308 /*************************************************************************/
01309 int Ping_Statistics(Ping * pingptr)
01310 {
01311   union  REGS  inregs;
01312   union  REGS  outregs;
01313   struct SREGS sregs;
01314 
01315 
01316 
01317   inregs.h.ah = PING_STATISTICS;
01318   sregs.es    = FP_SEG(pingptr);
01319   inregs.x.di = FP_OFF(pingptr);
01320   int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01321   return outregs.x.dx;
01322 }
01323 
01324 /*************************************************************************/
01325 //memory
01326 /*************************************************************************/
01327 void Get_TCPIP_Memory_Status(unsigned long * total, unsigned long * used)
01328 {
01329    union  REGS  inregs;
01330    union  REGS  outregs;
01331    struct SREGS sregs;
01332 
01333    inregs.h.ah = GET_MEMORY_INFO;
01334    sregs.es    = FP_SEG(total);
01335    inregs.x.di = FP_OFF(total);
01336    sregs.ds    = FP_SEG(used);
01337    inregs.x.si = FP_OFF(used);
01338    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01339 }
01340 
01341 /*************************************************************************/
01342 //Add gateway
01343 /*************************************************************************/
01344 int  AddDefaultGateway( int interface , unsigned long * Gateway, int * errorcode)
01345 {
01346    union  REGS  inregs;
01347    union  REGS  outregs;
01348    struct SREGS sregs;
01349 
01350    inregs.h.ah = ADD_DEFAULT_GATEWAY;
01351    inregs.x.bx = interface;
01352    sregs.es    = FP_SEG(Gateway);
01353    inregs.x.di = FP_OFF(Gateway);
01354 
01355    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01356    *errorcode=outregs.x.ax;
01357    return outregs.x.dx;
01358 }
01359 
01360 /*************************************************************************/
01361 //Delete gateway
01362 /*************************************************************************/
01363 int  DelDefaultGateway(unsigned long * Gateway, int * errorcode)
01364 {
01365    union  REGS  inregs;
01366    union  REGS  outregs;
01367    struct SREGS sregs;
01368 
01369    inregs.h.ah = DEL_DEFAULT_GATEWAY;
01370    sregs.es    = FP_SEG(Gateway);
01371    inregs.x.di = FP_OFF(Gateway);
01372 
01373    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01374    *errorcode=outregs.x.ax;
01375    return outregs.x.dx;
01376 }
01377 
01378 /*************************************************************************/
01379 //Get gateway
01380 /*************************************************************************/
01381 int  GetDefaultGateway(unsigned long * Gateway, int * errorcode)
01382 {
01383    union  REGS  inregs;
01384    union  REGS  outregs;
01385    struct SREGS sregs;
01386 
01387    inregs.h.ah = GET_DEFAULT_GATEWAY;
01388    sregs.es    = FP_SEG(Gateway);
01389    inregs.x.di = FP_OFF(Gateway);
01390 
01391    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01392    *errorcode=outregs.x.ax;
01393    return outregs.x.dx;
01394 }
01395 
01396 
01397 /*************************************************************************/
01398 //Add a static route
01399 /*************************************************************************/
01400 int  AddStaticRoute(int interface, Route_Entry * route, int * errorcode)
01401 {
01402    union  REGS  inregs;
01403    union  REGS  outregs;
01404    struct SREGS sregs;
01405 
01406    inregs.h.ah = ADD_STATIC_ROUTE;
01407    inregs.x.bx = interface;
01408    sregs.es    = FP_SEG(route);
01409    inregs.x.di = FP_OFF(route);
01410 
01411    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01412    *errorcode=outregs.x.ax;
01413    return outregs.x.dx;
01414 }
01415 
01416 
01417 /*************************************************************************/
01418 //Delete a static route
01419 /*************************************************************************/
01420 int  DelStaticRoute(int interface, Route_Entry * route, int * errorcode)
01421 {
01422    union  REGS  inregs;
01423    union  REGS  outregs;
01424    struct SREGS sregs;
01425 
01426    inregs.h.ah = DEL_STATIC_ROUTE;
01427    inregs.x.bx = interface;
01428    sregs.es    = FP_SEG(route);
01429    inregs.x.di = FP_OFF(route);
01430 
01431    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01432    *errorcode=outregs.x.ax;
01433    return outregs.x.dx;
01434 }
01435 
01436 
01437 /*************************************************************************/
01438 //Install an IP multicast address, join a multicast group
01439 /*************************************************************************/
01440 int  Add_IGMP_Membership(unsigned long * MulticastIP, unsigned char * MacAddress, int * errorcode)
01441 {
01442     union  REGS  inregs;
01443     union  REGS  outregs;
01444     struct SREGS sregs;
01445 
01446    inregs.h.ah = ADD_IGMP_MEMBERSHIP;
01447    //inregs.x.bx = sd;
01448    sregs.es    = FP_SEG(MulticastIP);
01449    inregs.x.di = FP_OFF(MulticastIP);
01450    sregs.ds    = FP_SEG(MacAddress);
01451    inregs.x.si = FP_OFF(MacAddress);
01452 
01453    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01454    *errorcode=outregs.x.ax;
01455    return outregs.x.dx;
01456 }
01457 /*************************************************************************/
01458 //Delete an IP multicast address, leave a multicast group
01459 /*************************************************************************/
01460 int  Drop_IGMP_Membership(unsigned long * MulticastIP, int * errorcode)
01461 {
01462     union  REGS  inregs;
01463     union  REGS  outregs;
01464     struct SREGS sregs;
01465 
01466    inregs.h.ah = DROP_IGMP_MEMBERSHIP;
01467    sregs.es    = FP_SEG(MulticastIP);
01468    inregs.x.di = FP_OFF(MulticastIP);
01469 
01470    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01471    *errorcode=outregs.x.ax;
01472    return outregs.x.dx;
01473 }
01474 
01475 
01476 /*************************************************************************/
01477 //Map IP multicast to Ethernet multicast
01478 /*************************************************************************/
01479 int  IPMulticast_to_MacAddr(unsigned long * MulticastIP, unsigned char * MacAddress, int * errorcode)
01480 {
01481     union  REGS  inregs;
01482     union  REGS  outregs;
01483     struct SREGS sregs;
01484 
01485    inregs.h.ah = MCASTIP_TO_MACADDR;
01486    sregs.es    = FP_SEG(MulticastIP);
01487    inregs.x.di = FP_OFF(MulticastIP);
01488    sregs.ds    = FP_SEG(MacAddress);
01489    inregs.x.si = FP_OFF(MacAddress);
01490 
01491    int86x(TCPIPVECT,&inregs,&outregs,&sregs);
01492    *errorcode=outregs.x.ax;
01493    return outregs.x.dx;
01494 }
01495 
01496 
01497 
01498 
01499 
01500 
01501 /*************************************************************************/
01502 //end tcpip.c
01503 /*************************************************************************/

Generated on Sun Aug 4 21:47:27 2002 for k/os mp3v2 by doxygen1.2.16