1
0

inet-fortified.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Checking macros for inet functions.
  2. Copyright (C) 2025-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _BITS_INET_FORTIFIED_H
  16. #define _BITS_INET_FORTIFIED_H 1
  17. #ifndef _ARPA_INET_H
  18. # error "Never include <bits/inet-fortified.h> directly; use <arpa/inet.h> instead."
  19. #endif
  20. #include <bits/inet-fortified-decl.h>
  21. __fortify_function __attribute_overloadable__ const char *
  22. __NTH (inet_ntop (int __af,
  23. __fortify_clang_overload_arg (const void *, __restrict, __src),
  24. char *__restrict __dst, socklen_t __dst_size))
  25. __fortify_clang_warning_only_if_bos_lt (__dst_size, __dst,
  26. "inet_ntop called with bigger length "
  27. "than size of destination buffer")
  28. {
  29. return __glibc_fortify (inet_ntop, __dst_size, sizeof (char),
  30. __glibc_objsize (__dst),
  31. __af, __src, __dst, __dst_size);
  32. };
  33. __fortify_function __attribute_overloadable__ int
  34. __NTH (inet_pton (int __af,
  35. const char *__restrict __src,
  36. __fortify_clang_overload_arg (void *, __restrict, __dst)))
  37. __fortify_clang_warning_only_if_bos0_lt
  38. (4, __dst, "inet_pton called with destination buffer size less than 4")
  39. {
  40. #if !__fortify_use_clang
  41. size_t __sz = 0;
  42. if (__af == AF_INET)
  43. __sz = sizeof (struct in_addr);
  44. else if (__af == AF_INET6)
  45. __sz = sizeof (struct in6_addr);
  46. else
  47. return __inet_pton_alias (__af, __src, __dst);
  48. #endif
  49. return __glibc_fortify (inet_pton, __sz, sizeof (char),
  50. __glibc_objsize (__dst),
  51. __af, __src, __dst);
  52. };
  53. #endif /* bits/inet-fortified.h. */