socket2.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 socket functions.
  17. Copyright (C) 2005-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 _SYS_SOCKET_H
  31. # error "Never include <bits/socket2.h> directly; use <sys/socket.h> instead."
  32. #endif
  33. extern ssize_t __recv_chk (int __fd, void *__buf, size_t __n, size_t __buflen,
  34. int __flags);
  35. extern ssize_t __REDIRECT (__recv_alias, (int __fd, void *__buf, size_t __n,
  36. int __flags), recv);
  37. extern ssize_t __REDIRECT (__recv_chk_warn,
  38. (int __fd, void *__buf, size_t __n, size_t __buflen,
  39. int __flags), __recv_chk)
  40. __warnattr ("recv called with bigger length than size of destination "
  41. "buffer");
  42. __fortify_function __attribute_overloadable__ ssize_t
  43. recv (int __fd, __fortify_clang_overload_arg0 (void *, ,__buf), size_t __n,
  44. int __flags)
  45. __fortify_clang_warning_only_if_bos0_lt (__n, __buf,
  46. "recv called with bigger length than "
  47. "size of destination buffer")
  48. {
  49. size_t __sz = __glibc_objsize0 (__buf);
  50. if (__glibc_safe_or_unknown_len (__n, sizeof (char), __sz))
  51. return __recv_alias (__fd, __buf, __n, __flags);
  52. #if !__fortify_use_clang
  53. if (__glibc_unsafe_len (__n, sizeof (char), __sz))
  54. return __recv_chk_warn (__fd, __buf, __n, __sz, __flags);
  55. #endif
  56. return __recv_chk (__fd, __buf, __n, __sz, __flags);
  57. }
  58. extern ssize_t __recvfrom_chk (int __fd, void *__restrict __buf, size_t __n,
  59. size_t __buflen, int __flags,
  60. __SOCKADDR_ARG __addr,
  61. socklen_t *__restrict __addr_len);
  62. extern ssize_t __REDIRECT (__recvfrom_alias,
  63. (int __fd, void *__restrict __buf, size_t __n,
  64. int __flags, __SOCKADDR_ARG __addr,
  65. socklen_t *__restrict __addr_len), recvfrom);
  66. extern ssize_t __REDIRECT (__recvfrom_chk_warn,
  67. (int __fd, void *__restrict __buf, size_t __n,
  68. size_t __buflen, int __flags,
  69. __SOCKADDR_ARG __addr,
  70. socklen_t *__restrict __addr_len), __recvfrom_chk)
  71. __warnattr ("recvfrom called with bigger length than size of "
  72. "destination buffer");
  73. __fortify_function __attribute_overloadable__ ssize_t
  74. recvfrom (int __fd, __fortify_clang_overload_arg0 (void *, __restrict, __buf),
  75. size_t __n, int __flags,
  76. __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len)
  77. __fortify_clang_warning_only_if_bos0_lt (__n, __buf,
  78. "recvfrom called with bigger length "
  79. "than size of destination buffer")
  80. {
  81. size_t __sz = __glibc_objsize0 (__buf);
  82. if (__glibc_safe_or_unknown_len (__n, sizeof (char), __sz))
  83. return __recvfrom_alias (__fd, __buf, __n, __flags, __addr, __addr_len);
  84. #if !__fortify_use_clang
  85. if (__glibc_unsafe_len (__n, sizeof (char), __sz))
  86. return __recvfrom_chk_warn (__fd, __buf, __n, __sz, __flags, __addr,
  87. __addr_len);
  88. #endif
  89. return __recvfrom_chk (__fd, __buf, __n, __sz, __flags, __addr, __addr_len);
  90. }