1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 #include "pal_config.h" 6 #include "pal_types.h" 7 #include "pal_tcpstate.h" 8 9 #if HAVE_TCP_FSM_H 10 #include <netinet/tcp_fsm.h> 11 #elif HAVE_TCP_H_TCPSTATE_ENUM 12 #include <netinet/tcp.h> 13 #else 14 #error System must have TCP states defined in either tcp.h or tcp_fsm.h. 15 #endif 16 SystemNative_MapTcpState(int32_t tcpState)17int32_t SystemNative_MapTcpState(int32_t tcpState) 18 { 19 switch (tcpState) 20 { 21 #if HAVE_TCP_FSM_H 22 case TCPS_CLOSED: 23 return TcpState_Closed; 24 case TCPS_LISTEN: 25 return TcpState_Listen; 26 case TCPS_SYN_SENT: 27 return TcpState_SynSent; 28 case TCPS_SYN_RECEIVED: 29 return TcpState_SynReceived; 30 case TCPS_ESTABLISHED: 31 return TcpState_Established; 32 case TCPS_CLOSE_WAIT: 33 return TcpState_CloseWait; 34 case TCPS_FIN_WAIT_1: 35 return TcpState_FinWait1; 36 case TCPS_CLOSING: 37 return TcpState_Closing; 38 case TCPS_FIN_WAIT_2: 39 return TcpState_FinWait2; 40 case TCPS_TIME_WAIT: 41 return TcpState_TimeWait; 42 default: 43 return TcpState_Unknown; 44 #elif HAVE_TCP_H_TCPSTATE_ENUM 45 case TCP_ESTABLISHED: 46 return TcpState_Established; 47 case TCP_SYN_SENT: 48 return TcpState_SynSent; 49 case TCP_SYN_RECV: 50 return TcpState_SynReceived; 51 case TCP_FIN_WAIT1: 52 return TcpState_FinWait1; 53 case TCP_FIN_WAIT2: 54 return TcpState_FinWait2; 55 case TCP_TIME_WAIT: 56 return TcpState_TimeWait; 57 case TCP_CLOSE: 58 return TcpState_Closing; 59 case TCP_CLOSE_WAIT: 60 return TcpState_CloseWait; 61 case TCP_LAST_ACK: 62 return TcpState_LastAck; 63 case TCP_LISTEN: 64 return TcpState_Listen; 65 case TCP_CLOSING: 66 return TcpState_Closing; 67 default: 68 return TcpState_Unknown; 69 #endif 70 } 71 } 72