Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/dsslib/ip_t/ivfmt.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2000-2012 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 address or prefix to string
29
* return value in a short-lived buffer
30
*/
31
32
char*
33
ivfmt(Iv_t* iv, const unsigned char* addr, int bits)
34
{
35
char* b;
36
char* s;
37
char* e;
38
int i;
39
int n;
40
41
if (iv->size == 16)
42
return fmtip6(addr, bits);
43
n = (iv->size + (bits >= 0)) * 4 + 1;
44
s = b = fmtbuf(n);
45
e = b + n;
46
s += sfsprintf(s, e - s, "%d", addr[0]);
47
for (i = 1; i < iv->size; i++)
48
s += sfsprintf(s, e - s, ".%d", addr[i]);
49
if (bits >= 0 && bits <= iv->size * 8)
50
sfsprintf(s, e - s, "/%d", bits);
51
return b;
52
}
53
54