/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. /* $Id: arpaname.c,v 1.4 2009/10/27 03:05:33 marka Exp $ */
  17. #include "config.h"
  18. #include <isc/net.h>
  19. #include <stdio.h>
  20. #define UNUSED(x) (void)(x)
  21. int
  22. main(int argc, char *argv[]) {
  23. unsigned char buf[16];
  24. int i;
  25. UNUSED(argc);
  26. while (argv[1]) {
  27. if (inet_pton(AF_INET6, argv[1], buf) == 1) {
  28. for (i = 15; i >= 0; i--)
  29. fprintf(stdout, "%X.%X.", buf[i] & 0xf,
  30. (buf[i] >> 4) & 0xf);
  31. fprintf(stdout, "IP6.ARPA\n");
  32. argv++;
  33. continue;
  34. }
  35. if (inet_pton(AF_INET, argv[1], buf) == 1) {
  36. fprintf(stdout, "%u.%u.%u.%u.IN-ADDR.ARPA\n",
  37. buf[3], buf[2], buf[1], buf[0]);
  38. argv++;
  39. continue;
  40. }
  41. return (1);
  42. }
  43. fflush(stdout);
  44. return(ferror(stdout));
  45. }