Annotation of 43BSDReno/lib/libc/net/iso_addr.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1989 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #if defined(LIBC_SCCS) && !defined(lint)
                     21: static char sccsid[] = "@(#)iso_addr.c 5.3 (Berkeley) 6/1/90";
                     22: #endif /* LIBC_SCCS and not lint */
                     23: 
                     24: #include <sys/types.h>
                     25: #include <netiso/iso.h>
                     26: /* States*/
                     27: #define VIRGIN 0
                     28: #define GOTONE 1
                     29: #define GOTTWO 2
                     30: /* Inputs */
                     31: #define        DIGIT   (4*0)
                     32: #define        END     (4*1)
                     33: #define DELIM  (4*2)
                     34: 
                     35: struct iso_addr *
                     36: iso_addr(addr)
                     37: register char *addr;
                     38: {
                     39:        static struct iso_addr out_addr;
                     40:        register char *cp = out_addr.isoa_genaddr;
                     41:        char *cplim = cp + sizeof(out_addr.isoa_genaddr);
                     42:        register int byte = 0, state = VIRGIN, new;
                     43: 
                     44:        bzero((char *)&out_addr, sizeof(out_addr));
                     45:        do {
                     46:                if ((*addr >= '0') && (*addr <= '9')) {
                     47:                        new = *addr - '0';
                     48:                } else if ((*addr >= 'a') && (*addr <= 'f')) {
                     49:                        new = *addr - 'a' + 10;
                     50:                } else if ((*addr >= 'A') && (*addr <= 'F')) {
                     51:                        new = *addr - 'A' + 10;
                     52:                } else if (*addr == 0) 
                     53:                        state |= END;
                     54:                else
                     55:                        state |= DELIM;
                     56:                addr++;
                     57:                switch (state /* | INPUT */) {
                     58:                case GOTTWO | DIGIT:
                     59:                        *cp++ = byte; /*FALLTHROUGH*/
                     60:                case VIRGIN | DIGIT:
                     61:                        state = GOTONE; byte = new; continue;
                     62:                case GOTONE | DIGIT:
                     63:                        state = GOTTWO; byte = new + (byte << 4); continue;
                     64:                default: /* | DELIM */
                     65:                        state = VIRGIN; *cp++ = byte; byte = 0; continue;
                     66:                case GOTONE | END:
                     67:                case GOTTWO | END:
                     68:                        *cp++ = byte; /* FALLTHROUGH */
                     69:                case VIRGIN | END:
                     70:                        break;
                     71:                }
                     72:                break;
                     73:        } while (cp < cplim); 
                     74:        out_addr.isoa_len = cp - out_addr.isoa_genaddr;
                     75:        return (&out_addr);
                     76: }
                     77: static char hexlist[] = "0123456789abcdef";
                     78: 
                     79: char *
                     80: iso_ntoa(isoa)
                     81: struct iso_addr *isoa;
                     82: {
                     83:        static char obuf[64];
                     84:        register char *out = obuf; 
                     85:        register int i;
                     86:        register u_char *in = (u_char *)isoa->isoa_genaddr;
                     87:        u_char *inlim = in + isoa->isoa_len;
                     88: 
                     89:        out[1] = 0;
                     90:        while (in < inlim) {
                     91:                i = *in++;
                     92:                *out++ = '.';
                     93:                if (i > 0xf) {
                     94:                        out[1] = hexlist[i & 0xf];
                     95:                        i >>= 4;
                     96:                        out[0] = hexlist[i];
                     97:                        out += 2;
                     98:                } else
                     99:                        *out++ = hexlist[i];
                    100:        }
                    101:        *out = 0;
                    102:        return(obuf + 1);
                    103: }

unix.superglobalmegacorp.com

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