socket2.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Checking macros for socket functions.
  2. Copyright (C) 2005-2021 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 _SYS_SOCKET_H
  16. # error "Never include <bits/socket2.h> directly; use <sys/socket.h> instead."
  17. #endif
  18. extern ssize_t __recv_chk (int __fd, void *__buf, size_t __n, size_t __buflen,
  19. int __flags);
  20. extern ssize_t __REDIRECT (__recv_alias, (int __fd, void *__buf, size_t __n,
  21. int __flags), recv);
  22. extern ssize_t __REDIRECT (__recv_chk_warn,
  23. (int __fd, void *__buf, size_t __n, size_t __buflen,
  24. int __flags), __recv_chk)
  25. __warnattr ("recv called with bigger length than size of destination "
  26. "buffer");
  27. __fortify_function ssize_t
  28. recv (int __fd, void *__buf, size_t __n, int __flags)
  29. {
  30. if (__glibc_objsize0 (__buf) != (size_t) -1)
  31. {
  32. if (!__builtin_constant_p (__n))
  33. return __recv_chk (__fd, __buf, __n, __glibc_objsize0 (__buf),
  34. __flags);
  35. if (__n > __glibc_objsize0 (__buf))
  36. return __recv_chk_warn (__fd, __buf, __n, __glibc_objsize0 (__buf),
  37. __flags);
  38. }
  39. return __recv_alias (__fd, __buf, __n, __flags);
  40. }
  41. extern ssize_t __recvfrom_chk (int __fd, void *__restrict __buf, size_t __n,
  42. size_t __buflen, int __flags,
  43. __SOCKADDR_ARG __addr,
  44. socklen_t *__restrict __addr_len);
  45. extern ssize_t __REDIRECT (__recvfrom_alias,
  46. (int __fd, void *__restrict __buf, size_t __n,
  47. int __flags, __SOCKADDR_ARG __addr,
  48. socklen_t *__restrict __addr_len), recvfrom);
  49. extern ssize_t __REDIRECT (__recvfrom_chk_warn,
  50. (int __fd, void *__restrict __buf, size_t __n,
  51. size_t __buflen, int __flags,
  52. __SOCKADDR_ARG __addr,
  53. socklen_t *__restrict __addr_len), __recvfrom_chk)
  54. __warnattr ("recvfrom called with bigger length than size of "
  55. "destination buffer");
  56. __fortify_function ssize_t
  57. recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags,
  58. __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len)
  59. {
  60. if (__glibc_objsize0 (__buf) != (size_t) -1)
  61. {
  62. if (!__builtin_constant_p (__n))
  63. return __recvfrom_chk (__fd, __buf, __n, __glibc_objsize0 (__buf),
  64. __flags, __addr, __addr_len);
  65. if (__n > __glibc_objsize0 (__buf))
  66. return __recvfrom_chk_warn (__fd, __buf, __n, __glibc_objsize0 (__buf),
  67. __flags, __addr, __addr_len);
  68. }
  69. return __recvfrom_alias (__fd, __buf, __n, __flags, __addr, __addr_len);
  70. }