Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/dsslib/ip_t/ivstr.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2000-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* Phong Vo <[email protected]> *
19
* *
20
***********************************************************************/
21
#pragma prototyped
22
23
#include "ivlib.h"
24
25
#include <ip6.h>
26
27
/*
28
* convert string to address or prefix
29
*/
30
31
int
32
ivstr(Iv_t* iv, const char* s, char** e, unsigned char* addr, unsigned char* bits)
33
{
34
int c;
35
int i;
36
int n;
37
int r;
38
39
if (iv->size == 16)
40
return strtoip6(s, e, addr, bits);
41
r = -1;
42
i = 0;
43
do
44
{
45
n = 0;
46
while ((c = *s++) >= '0' && c <= '9')
47
n = n * 10 + (c - '0');
48
if (n > 0xff)
49
goto done;
50
addr[i++] = n;
51
} while (c == '.' && i < iv->size);
52
if (bits)
53
{
54
if (c == '/')
55
{
56
n = 0;
57
while ((c = *s++) >= '0' && c <= '9')
58
n = n * 10 + (c - '0');
59
c = (n + 7) / 8;
60
if (i > c)
61
i = c;
62
}
63
else
64
n = i * 8;
65
*bits = n;
66
}
67
while (i < iv->size)
68
addr[i++] = 0;
69
r = 0;
70
done:
71
if (e)
72
*e = (char*)(s - 1);
73
return r;
74
}
75
76