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