master
1/* Checking macros for inet functions.
2 Copyright (C) 2025 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 size_t sz = 0;
49 if (__af == AF_INET)
50 sz = sizeof (struct in_addr);
51 else if (__af == AF_INET6)
52 sz = sizeof (struct in6_addr);
53 else
54 return __inet_pton_alias (__af, __src, __dst);
55
56 return __glibc_fortify (inet_pton, sz, sizeof (char),
57 __glibc_objsize (__dst),
58 __af, __src, __dst);
59};
60
61#endif /* bits/inet-fortified.h. */