Skip to content

Commit

Permalink
fix addrinfo struct def
Browse files Browse the repository at this point in the history
Fixes #4816
  • Loading branch information
laytan committed Feb 12, 2025
1 parent 4c4b481 commit 5530228
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
31 changes: 22 additions & 9 deletions core/sys/posix/netdb.odin
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,28 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
// The highest reserved port number.
IPPORT_RESERVED :: 1024

addrinfo :: struct {
ai_flags: Addrinfo_Flags, /* [PSX] input flags */
ai_family: AF, /* [PSX] address family of socket */
ai_socktype: Sock, /* [PSX] socket type */
ai_protocol: Protocol, /* [PSX] protocol of socket */
ai_addrlen: socklen_t, /* [PSX] length of socket address */
ai_canonname: cstring, /* [PSX] canonical name of service location */
ai_addr: ^sockaddr, /* [PSX] binary address */
ai_next: ^addrinfo, /* [PSX] pointer to next in list */
when ODIN_OS == .Linux || ODIN_OS == .OpenBSD {
addrinfo :: struct {
ai_flags: Addrinfo_Flags, /* [PSX] input flags */
ai_family: AF, /* [PSX] address family of socket */
ai_socktype: Sock, /* [PSX] socket type */
ai_protocol: Protocol, /* [PSX] protocol of socket */
ai_addrlen: socklen_t, /* [PSX] length of socket address */
ai_addr: ^sockaddr, /* [PSX] binary address */
ai_canonname: cstring, /* [PSX] canonical name of service location */
ai_next: ^addrinfo, /* [PSX] pointer to next in list */
}
} else {
addrinfo :: struct {
ai_flags: Addrinfo_Flags, /* [PSX] input flags */
ai_family: AF, /* [PSX] address family of socket */
ai_socktype: Sock, /* [PSX] socket type */
ai_protocol: Protocol, /* [PSX] protocol of socket */
ai_addrlen: socklen_t, /* [PSX] length of socket address */
ai_canonname: cstring, /* [PSX] canonical name of service location */
ai_addr: ^sockaddr, /* [PSX] binary address */
ai_next: ^addrinfo, /* [PSX] pointer to next in list */
}
}

when ODIN_OS == .Darwin {
Expand Down
2 changes: 2 additions & 0 deletions tests/core/sys/posix/structs/structs.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stddef.h>
#include <dirent.h>
#include <fcntl.h>
#include <glob.h>
Expand Down Expand Up @@ -70,6 +71,7 @@ int main(int argc, char *argv[])
printf("protoent %zu %zu\n", sizeof(struct protoent), _Alignof(struct protoent));
printf("servent %zu %zu\n", sizeof(struct servent), _Alignof(struct servent));
printf("addrinfo %zu %zu\n", sizeof(struct addrinfo), _Alignof(struct addrinfo));
printf("ai_canonname %zu\n", offsetof(struct addrinfo, ai_canonname));

printf("pollfd %zu %zu\n", sizeof(struct pollfd), _Alignof(struct pollfd));

Expand Down
1 change: 1 addition & 0 deletions tests/core/sys/posix/structs/structs.odin
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ main :: proc() {
fmt.println("protoent", size_of(posix.protoent), align_of(posix.protoent))
fmt.println("servent", size_of(posix.servent), align_of(posix.servent))
fmt.println("addrinfo", size_of(posix.addrinfo), align_of(posix.addrinfo))
fmt.println("ai_canonname", offset_of(posix.addrinfo, ai_canonname))

fmt.println("pollfd", size_of(posix.pollfd), align_of(posix.pollfd))
fmt.println("passwd", size_of(posix.passwd), align_of(posix.passwd))
Expand Down

0 comments on commit 5530228

Please sign in to comment.