]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/bin/tools/arpaname.c
Update BIND to 9.9.8
[FreeBSD/stable/9.git] / contrib / bind9 / bin / tools / arpaname.c
1 /*
2  * Copyright (C) 2009, 2015  Internet Systems Consortium, Inc. ("ISC")
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14  * PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 /* $Id: arpaname.c,v 1.4 2009/10/27 03:05:33 marka Exp $ */
18
19 #include "config.h"
20
21 #include <isc/net.h>
22 #include <isc/print.h>
23
24 #include <stdio.h>
25
26 #define UNUSED(x) (void)(x)
27
28 int
29 main(int argc, char *argv[]) {
30         unsigned char buf[16];
31         int i;
32
33         UNUSED(argc);
34
35         while (argv[1]) {
36                 if (inet_pton(AF_INET6, argv[1], buf) == 1) {
37                         for (i = 15; i >= 0; i--)
38                                 fprintf(stdout, "%X.%X.", buf[i] & 0xf,
39                                         (buf[i] >> 4) & 0xf);
40                         fprintf(stdout, "IP6.ARPA\n");
41                         argv++;
42                         continue;
43                 }
44                 if (inet_pton(AF_INET, argv[1], buf) == 1) {
45                         fprintf(stdout, "%u.%u.%u.%u.IN-ADDR.ARPA\n",
46                                 buf[3], buf[2], buf[1], buf[0]);
47                         argv++;
48                         continue;
49                 }
50                 return (1);
51         }
52         fflush(stdout);
53         return(ferror(stdout));
54 }