fix copyright and condition notice for new sccs include
[unix-history] / usr / src / lib / libc / net / iso_addr.c
CommitLineData
5f4a344d
KS
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 the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17
18#if defined(LIBC_SCCS) && !defined(lint)
cce859a1 19static char sccsid[] = "@(#)iso_addr.c 5.2 (Berkeley) %G%";
5f4a344d
KS
20#endif /* LIBC_SCCS and not lint */
21
22#include <sys/types.h>
23#include <netiso/iso.h>
afb6a25b
KS
24/* States*/
25#define VIRGIN 0
26#define GOTONE 1
27#define GOTTWO 2
28/* Inputs */
29#define DIGIT (4*0)
30#define END (4*1)
31#define DELIM (4*2)
5f4a344d
KS
32
33struct iso_addr *
34iso_addr(addr)
35register char *addr;
36{
37 static struct iso_addr out_addr;
38 register char *cp = out_addr.isoa_genaddr;
39 char *cplim = cp + sizeof(out_addr.isoa_genaddr);
afb6a25b 40 register int byte = 0, state = VIRGIN, new;
5f4a344d
KS
41
42 bzero((char *)&out_addr, sizeof(out_addr));
afb6a25b 43 do {
5f4a344d 44 if ((*addr >= '0') && (*addr <= '9')) {
afb6a25b 45 new = *addr - '0';
5f4a344d 46 } else if ((*addr >= 'a') && (*addr <= 'f')) {
afb6a25b 47 new = *addr - 'a' + 10;
5f4a344d 48 } else if ((*addr >= 'A') && (*addr <= 'F')) {
afb6a25b
KS
49 new = *addr - 'A' + 10;
50 } else if (*addr == 0)
51 state |= END;
52 else
53 state |= DELIM;
5f4a344d 54 addr++;
afb6a25b
KS
55 switch (state /* | INPUT */) {
56 case GOTTWO | DIGIT:
57 *cp++ = byte; /*FALLTHROUGH*/
58 case VIRGIN | DIGIT:
59 state = GOTONE; byte = new; continue;
60 case GOTONE | DIGIT:
61 state = GOTTWO; byte = new + (byte << 4); continue;
62 default: /* | DELIM */
63 state = VIRGIN; *cp++ = byte; byte = 0; continue;
64 case GOTONE | END:
65 case GOTTWO | END:
66 *cp++ = byte; /* FALLTHROUGH */
67 case VIRGIN | END:
68 break;
5f4a344d 69 }
afb6a25b
KS
70 break;
71 } while (cp < cplim);
5f4a344d
KS
72 out_addr.isoa_len = cp - out_addr.isoa_genaddr;
73 return (&out_addr);
74}
afb6a25b 75static char hexlist[] = "0123456789abcdef";
5f4a344d
KS
76
77char *
78iso_ntoa(isoa)
79struct iso_addr *isoa;
80{
5f4a344d
KS
81 static char obuf[64];
82 register char *out = obuf;
83 register int i;
84 register u_char *in = (u_char *)isoa->isoa_genaddr;
85 u_char *inlim = in + isoa->isoa_len;
86
87 out[1] = 0;
88 while (in < inlim) {
89 i = *in++;
90 *out++ = '.';
91 if (i > 0xf) {
92 out[1] = hexlist[i & 0xf];
afb6a25b 93 i >>= 4;
5f4a344d
KS
94 out[0] = hexlist[i];
95 out += 2;
96 } else
97 *out++ = hexlist[i];
98 }
99 *out = 0;
100 return(obuf + 1);
101}