Annotation of researchv9/ipc/src/libin/in_ntoa.c, revision 1.1

1.1     ! root        1: #include <sys/inet/in.h>
        !             2: 
        !             3: /*
        !             4:  * Convert network-format internet address
        !             5:  * to base 256 d.d.d.d representation.
        !             6:  */
        !             7: char *
        !             8: in_ntoa(in)
        !             9: in_addr in;
        !            10: {
        !            11:        static char b[18];
        !            12:        register int i;
        !            13: 
        !            14:        i = *(int *)&in;
        !            15: #define        UC(b)   (((int)b)&0xff)
        !            16:        sprintf(b, "%d.%d.%d.%d", UC(i>>24), UC(i>>16), UC(i>>8), UC(i));
        !            17:        return (b);
        !            18: }
        !            19: 
        !            20: /*
        !            21:  * Convert base 256 d.d.d.d representation
        !            22:  * to network-format internet address.
        !            23:  */
        !            24: in_addr
        !            25: in_aton(s)
        !            26: char *s;
        !            27: {
        !            28:        int x, dots=0;
        !            29:        char *p, c4[4];
        !            30: 
        !            31:        for(x = 0; x < 4; x++)
        !            32:                c4[x] = 0;
        !            33:        p = s;
        !            34:        x = 0;
        !            35:        while(*p){
        !            36:                if(p == s || *p == '.'){
        !            37:                        if(*p == '.') {
        !            38:                                dots++;
        !            39:                                p++;
        !            40:                        }
        !            41:                        x <<= 8;
        !            42:                        x |= atoi(p);
        !            43:                }
        !            44:                p++;
        !            45:        }
        !            46:        if((x & 0xffff0000) == 0){
        !            47:                /* probably class A net.host */
        !            48:                x = ((x & 0xff00) << 16) | (x & 0xff);
        !            49:        }
        !            50:        if((x & 0xff000000) == 0){
        !            51:                /* probably class B net.net.host */
        !            52:                x = ((x & 0xffff00) << 8) | (x & 0xff);
        !            53:        }
        !            54:        return(x);
        !            55: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.