From 8d7b6b4cb27d4dec1dd5f7960298c1699275f962 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Sat, 18 May 2024 09:33:19 +0200 Subject: socket: Use may_alias on sockaddr structs (bug 19622) This supports common coding patterns. The GCC C front end before version 7 rejects the may_alias attribute on a struct definition if it was not present in a previous forward declaration, so this attribute can only be conditionally applied. This implements the spirit of the change in Austin Group issue 1641. Suggested-by: Marek Polacek Suggested-by: Jakub Jelinek Reviewed-by: Sam James Reviewed-by: Carlos O'Donell --- inet/netinet/in.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'inet') diff --git a/inet/netinet/in.h b/inet/netinet/in.h index fa57b61..f684be5 100644 --- a/inet/netinet/in.h +++ b/inet/netinet/in.h @@ -244,7 +244,7 @@ extern const struct in6_addr in6addr_loopback; /* ::1 */ /* Structure describing an Internet socket address. */ -struct sockaddr_in +struct __attribute_struct_may_alias__ sockaddr_in { __SOCKADDR_COMMON (sin_); in_port_t sin_port; /* Port number. */ @@ -257,9 +257,11 @@ struct sockaddr_in - sizeof (struct in_addr)]; }; -#if !__USE_KERNEL_IPV6_DEFS +#if __USE_KERNEL_IPV6_DEFS +struct __attribute_struct_may_alias__ sockaddr_in6; +#else /* Ditto, for IPv6. */ -struct sockaddr_in6 +struct __attribute_struct_may_alias__ sockaddr_in6 { __SOCKADDR_COMMON (sin6_); in_port_t sin6_port; /* Transport layer port # */ -- cgit v1.1