From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/ip6_scan.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/libstddjb/ip6_scan.c (limited to 'src/libstddjb/ip6_scan.c') diff --git a/src/libstddjb/ip6_scan.c b/src/libstddjb/ip6_scan.c new file mode 100644 index 0000000..cb2dc49 --- /dev/null +++ b/src/libstddjb/ip6_scan.c @@ -0,0 +1,35 @@ +/* ISC license. */ + +#include +#include +#include + +unsigned int ip6_scan (char const *s, char *ip6) +{ + static const unsigned char class[256] = "2222222222222222222222222222222222222222222222220000000000122222200000022222222222222222222222222000000222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" ; + static const unsigned char table[5][3] = { "\024#\005", "\024\"\005", "\024\005\006", "\005\002\005", "\024\t\016" } ; + uint16 tmp[8] = { 0, 0, 0, 0, 0, 0, 0, 0 } ; + unsigned int pos = 8, j = 0, state = 0, i = 0 ; + + while (state < 5) + { + register unsigned char c = table[state][class[(unsigned char)s[i]] - '0'] ; + state = c & 7 ; + if (c & 0x20) { if (pos < 8) state = 5 ; else pos = j ; } + if (c & 0x10) + { + if (tmp[j] & 0xf000) state = 5 ; + else tmp[j] = (tmp[j] << 4) + fmtscan_num(s[i], 16) ; + } + if (c & 0x08) if ((++j > 7) && (state < 5)) state = 5 ; + i++ ; + } + + if (((pos < 8) && (j > 6)) || ((pos == 8) && (j < 8))) state = 5 ; + if (state == 5) return (errno = EINVAL, 0) ; + for (state = j ; state > pos ; state--) tmp[state - j + 7] = tmp[state - 1] ; + for (; state < pos + 8 - j ; state++) tmp[state] = 0 ; + + for (j = 0 ; j < 8 ; j++) uint16_pack_big(ip6 + (j<<1), tmp[j]) ; + return i - 1 ; +} -- cgit v1.2.3