@@ -533,19 +533,14 @@ assert_wasi_layout(offsetof(__wasi_subscription_t, userdata) == 0, "witx calcula
533533assert_wasi_layout (offsetof(__wasi_subscription_t , u ) == 8 , "witx calculated offset" );
534534
535535/* keep syncing with wasi_socket_ext.h */
536- typedef enum {
537- /* Used only for sock_addr_resolve hints */
538- SOCKET_ANY = -1 ,
539- SOCKET_DGRAM = 0 ,
540- SOCKET_STREAM ,
541- } __wasi_sock_type_t ;
542536
543537typedef uint16_t __wasi_ip_port_t ;
544538
545539/* Ensure that __wasi_addr_type_t has a size of 4 byte (I32).
546540 However, it will not have the type safety of enum. */
547541typedef uint32_t __wasi_addr_type_t ;
548- enum { IPv4 = 0 , IPv6 };
542+ #define IPv4 (0)
543+ #define IPv6 (1)
549544
550545/* n0.n1.n2.n3 */
551546typedef struct __wasi_addr_ip4_t {
@@ -592,25 +587,45 @@ typedef struct __wasi_addr_t {
592587 } addr ;
593588} __wasi_addr_t ;
594589
595- typedef enum { INET4 = 0 , INET6 , INET_UNSPEC } __wasi_address_family_t ;
590+ /* Force 32-bit wire width for cross-boundary fields */
591+ typedef int32_t __wasi_sock_type_t ;
592+ #define SOCKET_ANY (-1)
593+ #define SOCKET_DGRAM (0)
594+ #define SOCKET_STREAM (1)
595+
596+ typedef int32_t __wasi_address_family_t ;
597+ #define INET4 (0)
598+ #define INET6 (1)
599+ #define INET_UNSPEC (2)
596600
597601typedef struct __wasi_addr_info_t {
598- __wasi_addr_t addr ;
602+ __wasi_addr_t addr ;
599603 __wasi_sock_type_t type ;
600604} __wasi_addr_info_t ;
601605
602606typedef struct __wasi_addr_info_hints_t {
603- __wasi_sock_type_t type ;
604- __wasi_address_family_t family ;
605- // this is to workaround lack of optional parameters
606- uint8_t hints_enabled ;
607+ __wasi_sock_type_t type ; // 4 bytes
608+ __wasi_address_family_t family ; // 4 bytes
609+ uint8_t hints_enabled ; // 1 byte
610+ uint8_t _pad [ 3 ]; // enforce layout
607611} __wasi_addr_info_hints_t ;
608612
613+ assert_wasi_layout (sizeof (__wasi_sock_type_t ) == 4 , "sock_type must be 4 bytes" );
614+ assert_wasi_layout (sizeof (__wasi_address_family_t ) == 4 , "addr_family must be 4 bytes" );
615+
616+ assert_wasi_layout (sizeof (__wasi_addr_info_hints_t ) == 12 , "hints_t must be 12 bytes" );
617+ assert_wasi_layout (offsetof(__wasi_addr_info_hints_t , type ) == 0 , "hints.type@0" );
618+ assert_wasi_layout (offsetof(__wasi_addr_info_hints_t , family ) == 4 , "hints.family@4" );
619+ assert_wasi_layout (offsetof(__wasi_addr_info_hints_t , hints_enabled ) == 8 , "hints.enabled@8" );
620+
621+ assert_wasi_layout (offsetof(__wasi_addr_info_t , type ) == sizeof (__wasi_addr_t ),
622+ "addr_info.type follows addr" );
623+
609624#undef assert_wasi_layout
610625
611626/* clang-format on */
612627#ifdef __cplusplus
613628}
614629#endif
615630
616- #endif /* end of _PLATFORM_WASI_TYPES_H */
631+ #endif /* end of _PLATFORM_WASI_TYPES_H */
0 commit comments