ns_samename.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* Check if two domain names are equal after trailing dot normalization.
  2. * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (c) 1995,1999 by Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
  10. * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
  11. * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
  12. * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  15. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  16. * SOFTWARE.
  17. */
  18. #include <arpa/nameser.h>
  19. #include <string.h>
  20. /* Determines whether domain name A is the same as domain name B.
  21. Returns -1 on error, 0 if names differ, 1 if names are the
  22. same. */
  23. int
  24. __libc_ns_samename (const char *a, const char *b)
  25. {
  26. char ta[NS_MAXDNAME], tb[NS_MAXDNAME];
  27. if (__libc_ns_makecanon (a, ta, sizeof ta) < 0 ||
  28. __libc_ns_makecanon (b, tb, sizeof tb) < 0)
  29. return -1;
  30. if (__strcasecmp (ta, tb) == 0)
  31. return 1;
  32. else
  33. return 0;
  34. }
  35. libc_hidden_def (__libc_ns_samename)