/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 2000-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* Phong Vo <[email protected]> *18* *19***********************************************************************/20#pragma prototyped2122#include "ivlib.h"2324#include <ip6.h>2526/*27* convert string to address or prefix28*/2930int31ivstr(Iv_t* iv, const char* s, char** e, unsigned char* addr, unsigned char* bits)32{33int c;34int i;35int n;36int r;3738if (iv->size == 16)39return strtoip6(s, e, addr, bits);40r = -1;41i = 0;42do43{44n = 0;45while ((c = *s++) >= '0' && c <= '9')46n = n * 10 + (c - '0');47if (n > 0xff)48goto done;49addr[i++] = n;50} while (c == '.' && i < iv->size);51if (bits)52{53if (c == '/')54{55n = 0;56while ((c = *s++) >= '0' && c <= '9')57n = n * 10 + (c - '0');58c = (n + 7) / 8;59if (i > c)60i = c;61}62else63n = i * 8;64*bits = n;65}66while (i < iv->size)67addr[i++] = 0;68r = 0;69done:70if (e)71*e = (char*)(s - 1);72return r;73}747576