OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / lib / subnettot.c
1 /*
2  * convert binary form of subnet description to text
3  * Copyright (C) 2000  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: subnettot.c,v 1.2 2000/09/08 18:03:45 henry Exp $
16  */
17 #include "internal.h"
18 #include "freeswan.h"
19
20 /*
21  - subnettot - convert subnet to text "addr/bitcount"
22  */
23 size_t                          /* space needed for full conversion */
24 subnettot(sub, format, dst, dstlen)
25 const ip_subnet *sub;
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         char *p;
33
34         switch (format) {
35         case 0:
36                 break;
37         default:
38                 return 0;
39                 break;
40         }
41
42         len = addrtot(&sub->addr, format, dst, dstlen);
43         if (len < dstlen) {
44                 dst[len - 1] = '/';
45                 p = dst + len;
46                 rest = dstlen - len;
47         } else {
48                 p = NULL;
49                 rest = 0;
50         }
51
52
53         len += ultoa((unsigned long)sub->maskbits, 10, p, rest);
54
55         return len;
56 }