Skip to content

Commit

Permalink
Ensure sockaddr_any is future proof for new socket addresse sizes on
Browse files Browse the repository at this point in the history
platforms where sockaddr_storage is provided
  • Loading branch information
Richard Frith-Macdonald committed Sep 24, 2023
1 parent 5773700 commit 24653e6
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Headers/GNUstepBase/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H

/* if struct sockaddr_storage is defined */
#undef HAVE_STRUCT_SOCKADDR_STORAGE

/* Define to 1 if `st_birthtimespec' is a member of `struct stat64'. */
#undef HAVE_STRUCT_STAT64_ST_BIRTHTIMESPEC

Expand Down
3 changes: 3 additions & 0 deletions Source/GSSocketStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ typedef union {
#ifndef _WIN32
struct sockaddr_un u;
#endif
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
struct sockaddr_storage m;
#endif
} sockaddr_any;

#define SOCKIVARS \
Expand Down
44 changes: 39 additions & 5 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -5487,7 +5487,7 @@ else
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
Expand Down Expand Up @@ -5533,7 +5533,7 @@ else
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
Expand All @@ -5557,7 +5557,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
Expand Down Expand Up @@ -5602,7 +5602,7 @@ else
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
Expand All @@ -5626,7 +5626,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
Expand Down Expand Up @@ -9254,6 +9254,40 @@ _ACEOF
fi
#--------------------------------------------------------------------
# This needed by GSSocketStream.h
#--------------------------------------------------------------------
ac_fn_c_check_type "$LINENO" "struct sockaddr_storage" "ac_cv_type_struct_sockaddr_storage" "
#undef inline
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
#else
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#endif
"
if test "x$ac_cv_type_struct_sockaddr_storage" = xyes; then :
$as_echo "#define HAVE_STRUCT_SOCKADDR_STORAGE 1" >>confdefs.h
fi
#--------------------------------------------------------------------
# These headers/functions needed for stacktrace in NSException.m
#--------------------------------------------------------------------
Expand Down
29 changes: 29 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,35 @@ AC_CHECK_FUNCS(time ctime tzset)
#--------------------------------------------------------------------
AC_CHECK_HEADERS(sys/socket.h netinet/in.h)
AC_CHECK_TYPES([socklen_t])

#--------------------------------------------------------------------
# This needed by GSSocketStream.h
#--------------------------------------------------------------------
AC_CHECK_TYPE([struct sockaddr_storage],
AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
[if struct sockaddr_storage is defined]), ,[
#undef inline
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
#else
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#endif
])

dnl AC_REPLACE_FUNCS(recvfrom)

#--------------------------------------------------------------------
Expand Down

0 comments on commit 24653e6

Please sign in to comment.