sa_len.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Helper for SA_LEN macro.
  2. Copyright (C) 2013-2019 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. <http://www.gnu.org/licenses/>. */
  15. #include <sys/socket.h>
  16. /* If _HAVE_SA_LEN is defined, then SA_LEN just uses sockaddr.sa_len
  17. and there is no need for a helper function. */
  18. #ifndef _HAVE_SA_LEN
  19. /* All configurations have at least these two headers
  20. and their associated address families. */
  21. # include <netinet/in.h>
  22. # include <sys/un.h>
  23. /* More-specific sa_len.c files #define these various HAVE_*_H
  24. macros and then #include this file. */
  25. # ifdef HAVE_NETASH_ASH_H
  26. # include <netash/ash.h>
  27. # endif
  28. # ifdef HAVE_NETATALK_AT_H
  29. # include <netatalk/at.h>
  30. # endif
  31. # ifdef HAVE_NETAX25_AX25_H
  32. # include <netax25/ax25.h>
  33. # endif
  34. # ifdef HAVE_NETECONET_EC_H
  35. # include <neteconet/ec.h>
  36. # endif
  37. # ifdef HAVE_NETIPX_IPX_H
  38. # include <netipx/ipx.h>
  39. # endif
  40. # ifdef HAVE_NETPACKET_PACKET_H
  41. # include <netpacket/packet.h>
  42. # endif
  43. # ifdef HAVE_NETROSE_ROSE_H
  44. # include <netrose/rose.h>
  45. # endif
  46. # ifdef HAVE_NETIUCV_IUCV_H
  47. # include <netiucv/iucv.h>
  48. # endif
  49. int
  50. __libc_sa_len (sa_family_t af)
  51. {
  52. switch (af)
  53. {
  54. # ifdef HAVE_NETATALK_AT_H
  55. case AF_APPLETALK:
  56. return sizeof (struct sockaddr_at);
  57. # endif
  58. # ifdef HAVE_NETASH_ASH_H
  59. case AF_ASH:
  60. return sizeof (struct sockaddr_ash);
  61. # endif
  62. # ifdef HAVE_NETAX25_AX25_H
  63. case AF_AX25:
  64. return sizeof (struct sockaddr_ax25);
  65. # endif
  66. # ifdef HAVE_NETECONET_EC_H
  67. case AF_ECONET:
  68. return sizeof (struct sockaddr_ec);
  69. # endif
  70. case AF_INET:
  71. return sizeof (struct sockaddr_in);
  72. case AF_INET6:
  73. return sizeof (struct sockaddr_in6);
  74. # ifdef HAVE_NETIPX_IPX_H
  75. case AF_IPX:
  76. return sizeof (struct sockaddr_ipx);
  77. # endif
  78. # ifdef HAVE_NETIUCV_IUCV_H
  79. case AF_IUCV:
  80. return sizeof (struct sockaddr_iucv);
  81. # endif
  82. case AF_LOCAL:
  83. return sizeof (struct sockaddr_un);
  84. # ifdef HAVE_NETPACKET_PACKET_H
  85. case AF_PACKET:
  86. return sizeof (struct sockaddr_ll);
  87. # endif
  88. # ifdef HAVE_NETROSE_ROSE_H
  89. case AF_ROSE:
  90. return sizeof (struct sockaddr_rose);
  91. # endif
  92. }
  93. return 0;
  94. }
  95. libc_hidden_def (__libc_sa_len)
  96. #endif /* Not _HAVE_SA_LEN. */