1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
34 * convert string to ipv6 network byte order ip address
35 * with optional prefix bits
36 * pointer to first unused char placed in *e, even on error
37 * return 0:ok <0:error
46 strtoip6(register const char* s
, char** e
, unsigned char* addr
, unsigned char* bits
)
48 register unsigned char* b
= addr
;
49 register unsigned char* x
= b
+ IP6ADDR
;
50 register unsigned char* z
;
54 static unsigned char lex
[256];
58 for (c
= 0; c
< sizeof(lex
); ++c
)
70 lex
['A'] = lex
['a'] = 10;
71 lex
['B'] = lex
['b'] = 11;
72 lex
['C'] = lex
['c'] = 12;
73 lex
['D'] = lex
['d'] = 13;
74 lex
['E'] = lex
['e'] = 14;
75 lex
['F'] = lex
['f'] = 15;
87 switch (c
= lex
[*((unsigned char*)s
++)])
110 if ((c
= lex
[*((unsigned char*)++s
)]) >= 16)
123 *b
++ = ((a
>> 8) & 0xf) * 100 + ((a
>> 4) & 0xf) * 10 + (a
& 0xf);
127 switch (c
= lex
[*((unsigned char*)s
++)])
158 if ((c
= lex
[*((unsigned char*)++s
)]) >= 16)
164 if ((b
- addr
) == 6 && addr
[0] == 0x20 && addr
[1] == 0x02)
192 while ((c
= lex
[*((unsigned char*)s
++)]) < 10)
199 return c
== END
? 0 : -1;