On Fri Sep 6 17:38:26 2024 +0000, Alex Henrie wrote:
It doesn't look like Linux and FreeBSD use the same values to represent each TCP state. [Linux has](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/incl...): ```c enum { TCP_ESTABLISHED = 1, TCP_SYN_SENT, TCP_SYN_RECV, TCP_FIN_WAIT1, TCP_FIN_WAIT2, TCP_TIME_WAIT, TCP_CLOSE, TCP_CLOSE_WAIT, TCP_LAST_ACK, TCP_LISTEN, TCP_CLOSING, /* Now a valid state */ TCP_NEW_SYN_RECV, TCP_BOUND_INACTIVE, /* Pseudo-state for inet_diag */ TCP_MAX_STATES /* Leave at the end! */ }; ``` [FreeBSD has](http://fxr.watson.org/fxr/source/netinet/tcp_fsm.h?v=FREEBSD-13-STABLE#L47): ```c #define TCPS_CLOSED 0 /* closed */ #define TCPS_LISTEN 1 /* listening for connection */ #define TCPS_SYN_SENT 2 /* active, have sent syn */ #define TCPS_SYN_RECEIVED 3 /* have sent and received syn */ /* states < TCPS_ESTABLISHED are those where connections not established */ #define TCPS_ESTABLISHED 4 /* established */ #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ /* states > TCPS_CLOSE_WAIT are those where user has closed */ #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ ``` [macOS has](https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/netinet/tcp_fsm.h....) the same values as FreeBSD. Never mind, I see what you did: On Linux, you defined the `TCPS_` constants yourself with the correct values for Linux. That should be fine, although the comment here is a bit misleading.
I wonder if it would be more clear to make the translation from Linux names to BSD names more explicit, for example: ```c #ifndef HAVE_NETINET_TCP_FSM_H #define TCPS_ESTABLISHED TCP_ESTABLISHED #define TCPS_SYN_SENT TCP_SYN_SENT #define TCPS_SYN_RECEIVED TCP_SYN_RECV #define TCPS_FIN_WAIT_1 TCP_FIN_WAIT1 #define TCPS_FIN_WAIT_2 TCP_FIN_WAIT2 #define TCPS_TIME_WAIT TCP_TIME_WAIT #define TCPS_CLOSED TCP_CLOSE #define TCPS_CLOSE_WAIT TCP_CLOSE_WAIT #define TCPS_LAST_ACK TCP_LAST_ACK #define TCPS_LISTEN TCP_LISTEN #define TCPS_CLOSING TCP_CLOSING #endif ``` -- https://gitlab.winehq.org/wine/wine/-/merge_requests/6399#note_81416