net.c
ubixos/types.h
net/sockets.h
string.h
lib/kprintf.h
src/sys/lib/net.c
net/sockets.h
ubixos/types.h
sys/_types.h
string.h
lib/kprintf.h
uInt32 typedef uInt32 in_addr_t in_addr_t
void void bcopy (const void *src, void *dest, int len) bcopy const void * src void * dest int len memcpy
void void bzero (void *data, int n) bzero void * data int n memset
uInt32 uInt32 htonl (uInt32 n) htonl uInt32 n inet_aton
uInt32 uInt32 htons (uInt32 n) htons uInt32 n
int int inet_aton (char *cp, struct in_addr *addr) const inet_aton char * cp struct in_addr * addr htonl kprintf NULL strtol

    /*****************************************************************************************
    Copyright(c)2002TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Log: net_8c.xml,v $
    Revision 1.6  2006/12/19 14:12:52  reddawg
    rtld-elf almost workign

    Revision1.1.1.12006/06/0112:46:16reddawg
    ubix2

    Revision1.22005/10/1200:13:37reddawg
    Removed

    Revision1.1.1.12005/09/2617:24:12reddawg
    nomessage

    Revision1.62004/07/2110:02:09reddawg
    devfs:renamedfunctions
    devicesystem:renamedfunctions
    fdc:fixedafewpotentialbugsandcleanedupsomeunusedvariables
    strol:fixeddefinition
    endtask:madeitprintoutfreepagedebuginfo
    kmalloc:fixedahugememoryleakwehadsomeunhandleddescriptorinsertionsosomedescriptorswerelost
    ld:fixedapointerconversion
    file:cleanedupafewunusedvariables
    sched:broketaskdeletion
    kprintf:fixedogPrintfdefinition

    Revision1.52004/06/2823:12:58reddawg
    fileformatnowcontainer:/path/to/file

    Revision1.42004/06/1703:14:59flameshadow
    chg:addedmissing#includeforkprintf()

    Revision1.32004/05/2022:54:02reddawg
    CleanedUpWarrnings

    Revision1.22004/04/3014:16:04reddawg
    FixedallthedatatypestobeconsistantuInt8,uInt16,uInt32,Int8,Int16,Int32

    Revision1.1.1.12004/04/1512:07:10reddawg
    UbixOSv1.0

    Revision1.82004/04/1321:29:52reddawg
    Wenowhavesocketsworking.Lotsoffunctionalitytobeaddedtocontinually
    improveontheexistinglayersnowitscleanuptimetogetthingsinabetter
    workingorder.

    Revision1.72004/04/1316:36:33reddawg
    Changedourcopyright,itisallnowunderaBSD-Stylelicense

    $Id: net_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<ubixos/types.h>
    #include<net/sockets.h>
    #include<string.h>

    #include"lib/kprintf.h"

    #ifndef_IN_ADDR_T_DECLARED
    typedefuInt32in_addr_t;
    #define_IN_ADDR_T_DECLARED
    #endif

    uInt32htonl(uInt32n){
    uInt32retVal=0x0;
    retVal+=((n&0xff)<<24);
    retVal+=((n&0xff00)<<8);
    retVal+=((n&0xff0000)>>8);
    retVal+=((n&0xff000000)>>24);
    return(retVal);
    }

    uInt32htons(uInt32n){
    uInt32retVal=0x0;
    retVal=(((n&0xff)<<8)|((n&0xff00)>>8));
    return(retVal);
    }

    voidbcopy(constvoid*src,void*dest,intlen){
    memcpy(dest,src,len);
    }

    voidbzero(void*data,intn){
    memset(data,0,n);
    }

    intinet_aton(cp,addr)
    constchar*cp;
    structin_addr*addr;
    {
    uInt32parts[4];
    in_addr_tval;
    char*c;
    char*endptr;
    intgotend,n;

    c=(char*)cp;
    n=0;
    /*
    *Runthroughthestring,grabbingnumbersuntil
    *theendofthestring,orsomeerror
    */
    gotend=0;
    while(!gotend){
    //errno=0;
    val=strtol(c,&endptr,0);
    kprintf("VAL:[%x]",val);

    //if(errno==ERANGE)/*Failcompletelyifitoverflowed.*/
    //return(0);

    /*
    *Ifthewholestringisinvalid,endptrwillequal
    *c..thiswaywecanmakesuresomeonehasn't
    *gone'.12'orsomethingwhichwouldgetpast
    *thenextcheck.
    */
    if(endptr==c)
    return(0);
    parts[n]=val;
    c=endptr;

    /*Checkthenextcharacterpastthepreviousnumber'send*/
    switch(*c){
    case'.':
    /*Makesureweonlydo3dots..*/
    if(n==3)/*Whoops.Quit.*/
    return(0);
    n++;
    c++;
    break;

    case'\0':
    gotend=1;
    break;

    default:
    /*
    if(isspace((unsignedchar)*c)){
    gotend=1;
    break;
    }else
    */
    return(0);/*Invalidcharacter,sofail*/
    }

    }

    /*
    *Concocttheaddressaccordingto
    *thenumberofpartsspecified.
    */

    switch(n){
    case0:/*a--32bits*/
    /*
    *Nothingisnecessaryhere.Overflowcheckingwas
    *alreadydoneinstrtoul().
    */
    break;
    case1:/*a.b--8.24bits*/
    if(val>0xffffff||parts[0]>0xff)
    return(0);
    val|=parts[0]<<24;
    break;

    case2:/*a.b.c--8.8.16bits*/
    if(val>0xffff||parts[0]>0xff||parts[1]>0xff)
    return(0);
    val|=(parts[0]<<24)|(parts[1]<<16);
    break;

    case3:/*a.b.c.d--8.8.8.8bits*/
    if(val>0xff||parts[0]>0xff||parts[1]>0xff||
    parts[2]>0xff)
    return(0);
    val|=(parts[0]<<24)|(parts[1]<<16)|(parts[2]<<8);
    break;
    }

    if(addr!=NULL)
    addr->s_addr=htonl(val);
    return(1);
    }

    /***
    END
    ***/