summaryrefslogtreecommitdiff
path: root/libmailutils/tests/cidr.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmailutils/tests/cidr.c')
-rw-r--r--libmailutils/tests/cidr.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/libmailutils/tests/cidr.c b/libmailutils/tests/cidr.c
new file mode 100644
index 000000000..797fb248e
--- /dev/null
+++ b/libmailutils/tests/cidr.c
@@ -0,0 +1,77 @@
1/* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21#include <stdlib.h>
22#include <stdio.h>
23#include <mailutils/mailutils.h>
24
25static void
26print_bytes (unsigned char *b, size_t l)
27{
28 for (; l; l--, b++)
29 printf (" %02x", *b);
30 printf ("\n");
31}
32
33int
34main (int argc, char **argv)
35{
36 mu_set_program_name (argv[0]);
37 if (argc < 2)
38 {
39 mu_error ("usage: %s CIDR [CIDR...]", argv[0]);
40 return 1;
41 }
42
43 while (--argc)
44 {
45 char *arg = *++argv;
46 struct mu_cidr cidr;
47 int rc;
48 char *str;
49
50 rc = mu_cidr_from_string (&cidr, arg);
51 if (rc)
52 {
53 mu_error ("%s: %s", arg, mu_strerror (rc));
54 continue;
55 }
56
57 printf ("%s:\n", arg);
58 printf ("family = %d\n", cidr.family);
59 printf ("len = %d\n", cidr.len);
60 printf ("address =");
61 print_bytes (cidr.address, cidr.len);
62 printf ("netmask =");
63 print_bytes (cidr.netmask, cidr.len);
64 rc = mu_cidr_format (&cidr, 0, &str);
65 if (rc)
66 {
67 mu_error ("cannot covert to string: %s", mu_strerror (rc));
68 return 2;
69 }
70
71 printf ("string = %s\n", str);
72 free (str);
73 }
74 return 0;
75}
76
77

Return to:

Send suggestions and report system problems to the System administrator.