From 92413034f68ff5d7bcd7bb00a5ca1cf5b228ddd6 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Thu, 1 Feb 2018 06:03:01 +0000 Subject: [PATCH] added a check for offsetof(struct sockaddr,sa_family) --- moo/configure | 37 +++++++++++++++++++++++++++++++++++++ moo/configure.ac | 19 +++++++++++++++++++ moo/lib/moo-cfg.h.in | 3 +++ moo/mod/_sck.h | 3 +++ 4 files changed, 62 insertions(+) diff --git a/moo/configure b/moo/configure index 98f36d1..08243ac 100755 --- a/moo/configure +++ b/moo/configure @@ -21357,6 +21357,25 @@ $as_echo "#define MOO_SA_FAMILY_T_IS_SIGNED 1" >>confdefs.h fi fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking offset of sa_family in struct sockaddr" >&5 +$as_echo_n "checking offset of sa_family in struct sockaddr... " >&6; } + if ac_fn_c_compute_int "$LINENO" "offsetof(struct sockaddr, sa_family)" "ac_cv_offsetof_sa_family" "#include + #include + #include "; then : + +else + ac_cv_offsteof_sa_family=0 +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_offsetof_sa_family" >&5 +$as_echo "$ac_cv_offsetof_sa_family" >&6; } + +cat >>confdefs.h <<_ACEOF +#define MOO_OFFSETOF_SA_FAMILY ${ac_cv_offsetof_sa_family} +_ACEOF + + else # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects @@ -21704,6 +21723,24 @@ $as_echo "#define MOO_SA_FAMILY_T_IS_SIGNED 1" >>confdefs.h fi fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking offset of sa_family in struct sockaddr" >&5 +$as_echo_n "checking offset of sa_family in struct sockaddr... " >&6; } + if ac_fn_c_compute_int "$LINENO" "offsetof(struct sockaddr, sa_family)" "ac_cv_offsetof_sa_family" "#include + #include + #include "; then : + +else + ac_cv_offsteof_sa_family=0 +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_offsetof_sa_family" >&5 +$as_echo "$ac_cv_offsetof_sa_family" >&6; } + +cat >>confdefs.h <<_ACEOF +#define MOO_OFFSETOF_SA_FAMILY ${ac_cv_offsetof_sa_family} +_ACEOF + fi if test ${ac_cv_sizeof___int128_t} -gt 0 diff --git a/moo/configure.ac b/moo/configure.ac index 5d46f23..ad9d667 100644 --- a/moo/configure.ac +++ b/moo/configure.ac @@ -369,6 +369,16 @@ then [#include #include ]) fi + + AC_MSG_CHECKING([offset of sa_family in struct sockaddr]) + AC_COMPUTE_INT([ac_cv_offsetof_sa_family], + [[offsetof(struct sockaddr, sa_family)]], + [#include + #include + #include ], [ac_cv_offsteof_sa_family=0]) + AC_MSG_RESULT([$ac_cv_offsetof_sa_family]) + AC_DEFINE_UNQUOTED(MOO_OFFSETOF_SA_FAMILY, ${ac_cv_offsetof_sa_family}, [offsetof(struct sockaddr, sa_family)]) + else AC_CHECK_SIZEOF(struct sockaddr_in,,[ #include @@ -417,6 +427,15 @@ else #include #include ]) fi + + AC_MSG_CHECKING([offset of sa_family in struct sockaddr]) + AC_COMPUTE_INT([ac_cv_offsetof_sa_family], + [[offsetof(struct sockaddr, sa_family)]], + [#include + #include + #include ], [ac_cv_offsteof_sa_family=0]) + AC_MSG_RESULT([$ac_cv_offsetof_sa_family]) + AC_DEFINE_UNQUOTED(MOO_OFFSETOF_SA_FAMILY, ${ac_cv_offsetof_sa_family}, [offsetof(struct sockaddr, sa_family)]) fi dnl gcc 3.4.3 on opensolaris x86 gave this warning without -msse or diff --git a/moo/lib/moo-cfg.h.in b/moo/lib/moo-cfg.h.in index d4887b8..77eb36b 100644 --- a/moo/lib/moo-cfg.h.in +++ b/moo/lib/moo-cfg.h.in @@ -416,6 +416,9 @@ /* MB_LEN_MAX */ #undef MOO_MBLEN_MAX +/* offsetof(struct sockaddr, sa_family) */ +#undef MOO_OFFSETOF_SA_FAMILY + /* Author */ #undef MOO_PACKAGE_AUTHOR diff --git a/moo/mod/_sck.h b/moo/mod/_sck.h index 246848e..90275af 100644 --- a/moo/mod/_sck.h +++ b/moo/mod/_sck.h @@ -102,6 +102,9 @@ struct sck_t struct sck_addr_t { +#if defined(MOO_OFFSETOF_SA_FAMILY) && (MOO_OFFSETOF_SA_FAMILY > 0) + moo_uint8_t filler[MOO_OFFSETOF_SA_FAMILY]; +#endif sck_addr_family_t family; moo_uint8_t data[1]; };