Annotation of researchv8dc/cmd/inet/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 char *p;
        !            13: 
        !            14:        p = (char *)&in;
        !            15: #define        UC(b)   (((int)b)&0xff)
        !            16:        sprintf(b, "%d.%d.%d.%d", UC(p[3]), UC(p[2]), UC(p[1]), UC(p[0]));
        !            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;
        !            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:                                p++;
        !            39:                        x <<= 8;
        !            40:                        x |= atoi(p);
        !            41:                }
        !            42:                p++;
        !            43:        }
        !            44:        if((x & 0xffff0000) == 0){
        !            45:                /* probably like 126.1 */
        !            46:                x = ((x & 0xff00) << 16) | (x & 0xff);
        !            47:        }
        !            48:        return(x);
        !            49: }

unix.superglobalmegacorp.com

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