xref: /netbsd-src/external/mpl/bind/dist/bin/tools/arpaname.c (revision bcda20f65a8566e103791ec395f7f499ef322704)
1 /*	$NetBSD: arpaname.c,v 1.7 2025/01/26 16:25:10 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * SPDX-License-Identifier: MPL-2.0
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11  *
12  * See the COPYRIGHT file distributed with this work for additional
13  * information regarding copyright ownership.
14  */
15 
16 #include <stdio.h>
17 
18 #include <isc/net.h>
19 
20 #define UNUSED(x) (void)(x)
21 
22 int
23 main(int argc, char *argv[]) {
24 	unsigned char buf[16];
25 	int i;
26 
27 	UNUSED(argc);
28 
29 	while (argv[1]) {
30 		if (inet_pton(AF_INET6, argv[1], buf) == 1) {
31 			for (i = 15; i >= 0; i--) {
32 				fprintf(stdout, "%X.%X.", buf[i] & 0xf,
33 					(buf[i] >> 4) & 0xf);
34 			}
35 			fprintf(stdout, "IP6.ARPA\n");
36 			argv++;
37 			continue;
38 		}
39 		if (inet_pton(AF_INET, argv[1], buf) == 1) {
40 			fprintf(stdout, "%u.%u.%u.%u.IN-ADDR.ARPA\n", buf[3],
41 				buf[2], buf[1], buf[0]);
42 			argv++;
43 			continue;
44 		}
45 		return 1;
46 	}
47 	fflush(stdout);
48 	return ferror(stdout);
49 }
50