inet-fortified.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Checking macros for inet functions.
  17. Copyright (C) 2025-2026 Free Software Foundation, Inc.
  18. This file is part of the GNU C Library.
  19. The GNU C Library is free software; you can redistribute it and/or
  20. modify it under the terms of the GNU Lesser General Public
  21. License as published by the Free Software Foundation; either
  22. version 2.1 of the License, or (at your option) any later version.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. #ifndef _BITS_INET_FORTIFIED_H
  31. #define _BITS_INET_FORTIFIED_H 1
  32. #ifndef _ARPA_INET_H
  33. # error "Never include <bits/inet-fortified.h> directly; use <arpa/inet.h> instead."
  34. #endif
  35. #include <bits/inet-fortified-decl.h>
  36. __fortify_function __attribute_overloadable__ const char *
  37. __NTH (inet_ntop (int __af,
  38. __fortify_clang_overload_arg (const void *, __restrict, __src),
  39. char *__restrict __dst, socklen_t __dst_size))
  40. __fortify_clang_warning_only_if_bos_lt (__dst_size, __dst,
  41. "inet_ntop called with bigger length "
  42. "than size of destination buffer")
  43. {
  44. return __glibc_fortify (inet_ntop, __dst_size, sizeof (char),
  45. __glibc_objsize (__dst),
  46. __af, __src, __dst, __dst_size);
  47. };
  48. __fortify_function __attribute_overloadable__ int
  49. __NTH (inet_pton (int __af,
  50. const char *__restrict __src,
  51. __fortify_clang_overload_arg (void *, __restrict, __dst)))
  52. __fortify_clang_warning_only_if_bos0_lt
  53. (4, __dst, "inet_pton called with destination buffer size less than 4")
  54. {
  55. #if !__fortify_use_clang
  56. size_t __sz = 0;
  57. if (__af == AF_INET)
  58. __sz = sizeof (struct in_addr);
  59. else if (__af == AF_INET6)
  60. __sz = sizeof (struct in6_addr);
  61. else
  62. return __inet_pton_alias (__af, __src, __dst);
  63. #endif
  64. return __glibc_fortify (inet_pton, __sz, sizeof (char),
  65. __glibc_objsize (__dst),
  66. __af, __src, __dst);
  67. };
  68. #endif /* bits/inet-fortified.h. */