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