PageRenderTime 24ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/bind9/bin/tools/arpaname.c

https://bitbucket.org/freebsd/freebsd-head/
C | 53 lines | 29 code | 8 blank | 16 comment | 6 complexity | dc4f4036014ec12b9ee1219e1e1d4a67 MD5 | raw file
 1/*
 2 * Copyright (C) 2009  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
23#include <stdio.h>
24
25#define UNUSED(x) (void)(x)
26
27int
28main(int argc, char *argv[]) {
29	unsigned char buf[16];
30	int i;
31
32	UNUSED(argc);
33
34	while (argv[1]) {
35		if (inet_pton(AF_INET6, argv[1], buf) == 1) {
36			for (i = 15; i >= 0; i--)
37				fprintf(stdout, "%X.%X.", buf[i] & 0xf,
38					(buf[i] >> 4) & 0xf);
39			fprintf(stdout, "IP6.ARPA\n");
40			argv++;
41			continue;
42		}
43		if (inet_pton(AF_INET, argv[1], buf) == 1) {
44			fprintf(stdout, "%u.%u.%u.%u.IN-ADDR.ARPA\n",
45				buf[3], buf[2], buf[1], buf[0]);
46			argv++;
47			continue;
48		}
49		return (1);
50	}
51	fflush(stdout);
52	return(ferror(stdout));
53}