home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / comm / amitcp-3.0ß2.lha / AmiTCP / src / amitcp / api / amiga_libcalls.c < prev    next >
C/C++ Source or Header  |  1994-01-04  |  11KB  |  398 lines

  1. RCS_ID_C="$Id: amiga_libcalls.c,v 1.19 1993/06/11 19:01:41 too Exp $";
  2. /*
  3.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  4.  *                    Helsinki University of Technology, Finland.
  5.  *                    All rights reserved.
  6.  * 
  7.  * HISTORY
  8.  * $Log: amiga_libcalls.c,v $
  9.  * Revision 1.19  1993/06/11  19:01:41  too
  10.  * Changed register argument from a0 to d0 in functions
  11.  * Inet_NtoA, Inet_LnaOf and Inet_NetOf
  12.  *
  13.  * Revision 1.18  1993/06/07  12:37:20  too
  14.  * Changed inet_ntoa, netdatabase functions and WaitSelect() use
  15.  * separate buffers for their dynamic buffers
  16.  *
  17.  * Revision 1.17  1993/06/04  11:16:15  jraja
  18.  * Fixes for first public release.
  19.  *
  20.  * Revision 1.16  1993/05/17  01:07:47  ppessi
  21.  * Changed RCS version.
  22.  *
  23.  * Revision 1.15  1993/05/04  14:08:05  too
  24.  * Changed local api function names to the same as the names given
  25.  * to API programmer, but w/ starting _
  26.  *
  27.  * Revision 1.14  93/05/04  12:05:28  12:05:28  jraja (Jarno Tapio Rajahalme)
  28.  * fix.
  29.  * 
  30.  * Revision 1.13  93/04/29  02:21:17  02:21:17  jraja (Jarno Tapio Rajahalme)
  31.  * Added function rresvport().
  32.  * 
  33.  * Revision 1.12  93/04/26  13:18:50  13:18:50  jraja (Jarno Tapio Rajahalme)
  34.  * Changed inet_ntoa() to use return buffer as defined in amiga_api.h.
  35.  * 
  36.  * Revision 1.11  93/04/26  12:32:51  12:32:51  too (Tomi Ollila)
  37.  * Added #Include <allocdatabinclude <api/allocdatabuffer.h>
  38.  * 
  39.  * Revision 1.10  93/04/26  11:52:35  11:52:35  too (Tomi Ollila)
  40.  * Changed include paths of amiga_api.h, amiga_libcallentry.h and amiga_raf.h
  41.  * from kern to api
  42.  * 
  43.  * Revision 1.9  93/04/26  11:06:20  11:06:20  too (Tomi Ollila)
  44.  * Added CHECK_TASK2()
  45.  * 
  46.  * Revision 1.8  93/04/25  19:58:43  19:58:43  too (Tomi Ollila)
  47.  * Changed inet_ntoa to use dynamic buffers for return string
  48.  * 
  49.  * Revision 1.1  93/04/25  19:56:18  19:56:18  too (Tomi Ollila)
  50.  * Initial revision
  51.  * 
  52.  * Revision 1.7  93/04/06  15:15:18  15:15:18  jraja (Jarno Tapio Rajahalme)
  53.  * Changed spl function return value storage to spl_t,
  54.  * changed bcopys and bzeros to aligned and/or const when possible,
  55.  * added inclusion of conf.h to every .c file.
  56.  * 
  57.  * Revision 1.6  93/03/16  08:30:05  08:30:05  jraja (Jarno Tapio Rajahalme)
  58.  * Removed redundant include of sys/stat.h.
  59.  * 
  60.  * Revision 1.5  93/03/12  23:59:14  23:59:14  ppessi (Pekka Pessi)
  61.  * Added inte_addr() return tyep.
  62.  * 
  63.  * Revision 1.4  93/03/10  21:06:18  21:06:18  too (Tomi Ollila)
  64.  * Changed use of libPtr->buffer to the new union member
  65.  * 
  66.  * Revision 1.3  93/03/09  17:52:22  17:52:22  ppessi (Pekka Pessi)
  67.  * Removed passign struct in_addr passing, now passes only a LONG;
  68.  * fixed inet_ntoa not to print excessive spaces
  69.  * 
  70.  * Revision 1.2  93/03/07  00:46:15  00:46:15  jraja (Jarno Tapio Rajahalme)
  71.  * Added SAVEDS to API function definitions.
  72.  * 
  73.  * Revision 1.1  93/03/06  02:08:48  02:08:48  jraja (Jarno Tapio Rajahalme)
  74.  * Initial revision
  75.  * 
  76.  */
  77.  
  78. /*
  79.  * Copyright (c) 1983, 1990 Regents of the University of California.
  80.  * All rights reserved.
  81.  *
  82.  * Redistribution and use in source and binary forms, with or without
  83.  * modification, are permitted provided that the following conditions
  84.  * are met:
  85.  * 1. Redistributions of source code must retain the above copyright
  86.  *    notice, this list of conditions and the following disclaimer.
  87.  * 2. Redistributions in binary form must reproduce the above copyright
  88.  *    notice, this list of conditions and the following disclaimer in the
  89.  *    documentation and/or other materials provided with the distribution.
  90.  * 3. All advertising materials mentioning features or use of this software
  91.  *    must display the following acknowledgement:
  92.  *    This product includes software developed by the University of
  93.  *    California, Berkeley and its contributors.
  94.  * 4. Neither the name of the University nor the names of its contributors
  95.  *    may be used to endorse or promote products derived from this software
  96.  *    without specific prior written permission.
  97.  *
  98.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  99.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  100.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  101.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  102.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  103.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  104.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  105.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  106.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  107.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  108.  * SUCH DAMAGE.
  109.  */
  110.  
  111. #include <conf.h>
  112.  
  113. #include <sys/param.h>
  114. #include <sys/systm.h>
  115. #include <sys/socketvar.h>
  116. #include <sys/kernel.h>
  117. #include <sys/ioctl.h>
  118. #include <sys/protosw.h>
  119. #include <sys/malloc.h>
  120. #include <sys/synch.h>
  121. #include <sys/socket.h>
  122. #include <sys/errno.h>
  123.  
  124. #include <netinet/in.h>
  125.  
  126. #include <kern/amiga_includes.h>
  127.  
  128. #include <api/amiga_api.h>
  129. #include <api/amiga_libcallentry.h>
  130. #include <api/allocdatabuffer.h>
  131.  
  132. #include <ctype.h>
  133.  
  134. /*
  135.  * Functions which are defined in link library in unix systems
  136.  */
  137.  
  138. /* from inet_ntoa.c */
  139. /*
  140.  * Convert network-format internet address
  141.  * to base 256 d.d.d.d representation.
  142.  */
  143. char *SAVEDS RAF2(_Inet_NtoA,
  144.          struct SocketBase *,    libPtr,    a6,
  145.          ULONG,            s_addr,    d0)
  146. #if 0
  147. {
  148. #endif
  149.   NTOHL(s_addr);
  150.  
  151.   CHECK_TASK2();
  152.  
  153.   sprintf(libPtr->inet_ntoa,
  154.       "%ld.%ld.%ld.%ld", 
  155.       (s_addr>>24) & 0xff, 
  156.       (s_addr>>16) & 0xff, 
  157.       (s_addr>>8) & 0xff, 
  158.       s_addr & 0xff);
  159.   return ((char *)libPtr->inet_ntoa);
  160. }
  161.  
  162. /* from inet_addr.c */
  163. /* 
  164.  * Check whether "cp" is a valid ascii representation
  165.  * of an Internet address and convert to a binary address.
  166.  * Returns 1 if the address is valid, 0 if not.
  167.  * This replaces inet_addr, the return value from which
  168.  * cannot distinguish between failure and a local broadcast address.
  169.  */
  170.  
  171. int
  172. inet_aton(register const char *cp, struct in_addr *addr)
  173. {
  174.     register u_long val, base, n;
  175.     register char c;
  176.     u_long parts[4], *pp = parts;
  177.     
  178.     for (;;) {
  179.         /*
  180.          * Collect number up to ``.''.
  181.          * Values are specified as for C:
  182.          * 0x=hex, 0=octal, other=decimal.
  183.          */
  184.         val = 0; base = 10;
  185.         if (*cp == '0') {
  186.             if (*++cp == 'x' || *cp == 'X')
  187.                 base = 16, cp++;
  188.             else
  189.                 base = 8;
  190.         }
  191.         while ((c = *cp) != '\0') {
  192.             if (isascii(c) && isdigit(c)) {
  193.                 val = (val * base) + (c - '0');
  194.                 cp++;
  195.                 continue;
  196.             }
  197.             if (base == 16 && isascii(c) && isxdigit(c)) {
  198.                 val = (val << 4) + 
  199.                     (c + 10 - (islower(c) ? 'a' : 'A'));
  200.                 cp++;
  201.                 continue;
  202.             }
  203.             break;
  204.         }
  205.         if (*cp == '.') {
  206.             /*
  207.              * Internet format:
  208.              *    a.b.c.d
  209.              *    a.b.c    (with c treated as 16-bits)
  210.              *    a.b    (with b treated as 24 bits)
  211.              */
  212.             if (pp >= parts + 3 || val > 0xff)
  213.                 return (0);
  214.             *pp++ = val, cp++;
  215.         } else
  216.             break;
  217.     }
  218.     /*
  219.      * Check for trailing characters.
  220.      */
  221.     if (*cp && (!isascii(*cp) || !isspace(*cp)))
  222.         return (0);
  223.     /*
  224.      * Concoct the address according to
  225.      * the number of parts specified.
  226.      */
  227.     n = pp - parts + 1;
  228.     switch (n) {
  229.  
  230.     case 1:                /* a -- 32 bits */
  231.         break;
  232.  
  233.     case 2:                /* a.b -- 8.24 bits */
  234.         if (val > 0xffffff)
  235.             return (0);
  236.         val |= parts[0] << 24;
  237.         break;
  238.  
  239.     case 3:                /* a.b.c -- 8.8.16 bits */
  240.         if (val > 0xffff)
  241.             return (0);
  242.         val |= (parts[0] << 24) | (parts[1] << 16);
  243.         break;
  244.  
  245.     case 4:                /* a.b.c.d -- 8.8.8.8 bits */
  246.         if (val > 0xff)
  247.             return (0);
  248.         val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
  249.         break;
  250.     }
  251.     if (addr)
  252.         addr->s_addr = htonl(val);
  253.     return (1);
  254. }
  255.  
  256. /*
  257.  * Ascii internet address interpretation routine.
  258.  * The value returned is in network order.
  259.  */
  260.  
  261. ULONG SAVEDS RAF2(_inet_addr,
  262.           struct SocketBase *,    libPtr,    a6,
  263.           const char *,        cp,    a0)
  264. #if 0
  265. {
  266. #endif
  267.     struct in_addr val;
  268.  
  269.     if (inet_aton(cp, &val))
  270.         return (val.s_addr);
  271.     return (INADDR_NONE);
  272. }
  273.  
  274. /* from inet_lnaof.c */
  275. /*
  276.  * Return the local network address portion of an
  277.  * internet address; handles class a/b/c network
  278.  * number formats.
  279.  */
  280. ULONG SAVEDS RAF2(_Inet_LnaOf,
  281.           struct SocketBase *,    libPtr,    a6,
  282.           ULONG,            s_addr, d0)
  283. #if 0
  284. {
  285. #en