]>
Commit | Line | Data |
---|---|---|
997358a6 MW |
1 | /* |
2 | * convert binary form of address range to ASCII | |
3 | * Copyright (C) 1998, 1999 Henry Spencer. | |
4 | * | |
5 | * This library is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Library General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or (at your | |
8 | * option) any later version. See <http://www.fsf.org/copyleft/lgpl.txt>. | |
9 | * | |
10 | * This library is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | |
13 | * License for more details. | |
14 | * | |
15 | * RCSID $Id: rangetoa.c,v 1.1 2004/03/15 20:35:26 as Exp $ | |
16 | */ | |
17 | #include "internal.h" | |
18 | #include "freeswan.h" | |
19 | ||
20 | /* | |
21 | - rangetoa - convert address range to ASCII | |
22 | */ | |
23 | size_t /* space needed for full conversion */ | |
24 | rangetoa(addrs, format, dst, dstlen) | |
25 | struct in_addr addrs[2]; | |
26 | int format; /* character */ | |
27 | char *dst; /* need not be valid if dstlen is 0 */ | |
28 | size_t dstlen; | |
29 | { | |
30 | size_t len; | |
31 | size_t rest; | |
32 | int n; | |
33 | char *p; | |
34 | ||
35 | switch (format) { | |
36 | case 0: | |
37 | break; | |
38 | default: | |
39 | return 0; | |
40 | break; | |
41 | } | |
42 | ||
43 | len = addrtoa(addrs[0], 0, dst, dstlen); | |
44 | if (len < dstlen) | |
45 | for (p = dst + len - 1, n = 3; len < dstlen && n > 0; | |
46 | p++, len++, n--) | |
47 | *p = '.'; | |
48 | else | |
49 | p = NULL; | |
50 | if (len < dstlen) | |
51 | rest = dstlen - len; | |
52 | else { | |
53 | if (dstlen > 0) | |
54 | *(dst + dstlen - 1) = '\0'; | |
55 | rest = 0; | |
56 | } | |
57 | ||
58 | len += addrtoa(addrs[1], 0, p, rest); | |
59 | ||
60 | return len; | |
61 | } |