- Main Page
- Data Structures
- Files
- Directories

- Search for |

- File List
- Globals

# net.c

Go to the documentation of this file.

    00001 /*****************************************************************************************
    00002  Copyright (c) 2002 The UbixOS Project
    00003  All rights reserved.
    00004
    00005 Redistribution and use in source and binary forms, with or without modification, are
    00006 permitted provided that the following conditions are met:
    00007
    00008 Redistributions of source code must retain the above copyright notice, this list of
    00009 conditions, the following disclaimer and the list of authors.  Redistributions in binary
    00010 form must reproduce the above copyright notice, this list of conditions, the following
    00011 disclaimer and the list of authors in the documentation and/or other materials provided
    00012 with the distribution. Neither the name of the UbixOS Project nor the names of its
    00013 contributors may be used to endorse or promote products derived from this software
    00014 without specific prior written permission.
    00015
    00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00025
    00026  $Log: net_8c-source.html,v $
    00026  Revision 1.7  2006/12/15 17:47:06  reddawg
    00026  Updates
    00026
    00027  Revision 1.1.1.1  2006/06/01 12:46:16  reddawg
    00028  ubix2
    00029
    00030  Revision 1.2  2005/10/12 00:13:37  reddawg
    00031  Removed
    00032
    00033  Revision 1.1.1.1  2005/09/26 17:24:12  reddawg
    00034  no message
    00035
    00036  Revision 1.6  2004/07/21 10:02:09  reddawg
    00037  devfs: renamed functions
    00038  device system: renamed functions
    00039  fdc: fixed a few potential bugs and cleaned up some unused variables
    00040  strol: fixed definition
    00041  endtask: made it print out freepage debug info
    00042  kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost
    00043  ld: fixed a pointer conversion
    00044  file: cleaned up a few unused variables
    00045  sched: broke task deletion
    00046  kprintf: fixed ogPrintf definition
    00047
    00048  Revision 1.5  2004/06/28 23:12:58  reddawg
    00049  file format now container:/path/to/file
    00050
    00051  Revision 1.4  2004/06/17 03:14:59  flameshadow
    00052  chg: added missing #include for kprintf()
    00053
    00054  Revision 1.3  2004/05/20 22:54:02  reddawg
    00055  Cleaned Up Warrnings
    00056
    00057  Revision 1.2  2004/04/30 14:16:04  reddawg
    00058  Fixed all the datatypes to be consistant uInt8,uInt16,uInt32,Int8,Int16,Int32
    00059
    00060  Revision 1.1.1.1  2004/04/15 12:07:10  reddawg
    00061  UbixOS v1.0
    00062
    00063  Revision 1.8  2004/04/13 21:29:52  reddawg
    00064  We now have sockets working. Lots of functionality to be added to continually
    00065  improve on the existing layers now its clean up time to get things in a better
    00066  working order.
    00067
    00068  Revision 1.7  2004/04/13 16:36:33  reddawg
    00069  Changed our copyright, it is all now under a BSD-Style license
    00070
    00071
    00072
    00073  $Id: net_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00074
    00075 *****************************************************************************************/
    00076
    00077 #include <ubixos/types.h>
    00078 #include <net/sockets.h>
    00079 #include <string.h>
    00080
    00081 #include "lib/kprintf.h"
    00082
    00083 #ifndef _IN_ADDR_T_DECLARED
    00084 typedef uInt32        in_addr_t;
    00085 #define _IN_ADDR_T_DECLARED
    00086 #endif
    00087
    00088 uInt32 htonl(uInt32 n) {
    00089   uInt32 retVal = 0x0;
    00090   retVal += ((n & 0xff) << 24);
    00091   retVal += ((n & 0xff00) << 8);
    00092   retVal += ((n & 0xff0000) >> 8);
    00093   retVal += ((n & 0xff000000) >> 24);
    00094   return(retVal);
    00095   }
    00096
    00097 uInt32 htons(uInt32 n) {
    00098   uInt32 retVal = 0x0;
    00099   retVal = (((n & 0xff) << 8) | ((n & 0xff00) >> 8));
    00100   return(retVal);
    00101   }
    00102
    00103 void bcopy(const void *src, void *dest, int len) {
    00104   memcpy(dest,src,len);
    00105   }
    00106
    00107 void bzero(void *data, int n) {
    00108   memset(data, 0, n);
    00109   }
    00110
    00111
    00112 int inet_aton(cp, addr)
    00113         const char *cp;
    00114         struct in_addr *addr;
    00115 {
    00116         uInt32 parts[4];
    00117         in_addr_t val;
    00118         char *c;
    00119         char *endptr;
    00120         int gotend, n;
    00121
    00122         c = (char *)cp;
    00123         n = 0;
    00124         /*
    00125          * Run through the string, grabbing numbers until
    00126          * the end of the string, or some error
    00127          */
    00128         gotend = 0;
    00129         while (!gotend) {
    00130                 //errno = 0;
    00131                 val = strtol(c, &endptr, 0);
    00132                 kprintf("VAL: [%x]",val);
    00133
    00134                 //if (errno == ERANGE)    /* Fail completely if it overflowed. */
    00135                 //        return (0);
    00136
    00137                 /*
    00138                  * If the whole string is invalid, endptr will equal
    00139                  * c.. this way we can make sure someone hasn't
    00140                  * gone '.12' or something which would get past
    00141                  * the next check.
    00142                  */
    00143                 if (endptr == c)
    00144                         return (0);
    00145                 parts[n] = val;
    00146                 c = endptr;
    00147
    00148                 /* Check the next character past the previous number's end */
    00149                 switch (*c) {
    00150                 case '.' :
    00151                         /* Make sure we only do 3 dots .. */
    00152                         if (n == 3)     /* Whoops. Quit. */
    00153                                 return (0);
    00154                         n++;
    00155                         c++;
    00156                         break;
    00157
    00158                 case '\0':
    00159                         gotend = 1;
    00160                         break;
    00161
    00162                 default:
    00163                        /*
    00164                         if (isspace((unsigned char)*c)) {
    00165                                 gotend = 1;
    00166                                 break;
    00167                         } else
    00168                        */
    00169                                 return (0);     /* Invalid character, so fail */
    00170                 }
    00171
    00172         }
    00173
    00174         /*
    00175          * Concoct the address according to
    00176          * the number of parts specified.
    00177          */
    00178
    00179         switch (n) {
    00180         case 0:                         /* a -- 32 bits */
    00181                 /*
    00182                  * Nothing is necessary here.  Overflow checking was
    00183                  * already done in strtoul().
    00184                  */
    00185                 break;
    00186         case 1:                         /* a.b -- 8.24 bits */
    00187                 if (val > 0xffffff || parts[0] > 0xff)
    00188                         return (0);
    00189                 val |= parts[0] << 24;
    00190                 break;
    00191
    00192         case 2:                         /* a.b.c -- 8.8.16 bits */
    00193                 if (val > 0xffff || parts[0] > 0xff || parts[1] > 0xff)
    00194                         return (0);
    00195                 val |= (parts[0] << 24) | (parts[1] << 16);
    00196                 break;
    00197
    00198         case 3:                         /* a.b.c.d -- 8.8.8.8 bits */
    00199                 if (val > 0xff || parts[0] > 0xff || parts[1] > 0xff ||
    00200                     parts[2] > 0xff)
    00201                         return (0);
    00202                 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
    00203                 break;
    00204         }
    00205
    00206         if (addr != NULL)
    00207                 addr->s_addr = htonl(val);
    00208         return (1);
    00209 }
    00210
    00211 /***
    00212  END
    00213  ***/
    00214