/*************************************************************************** * Copyright (c) 2024 Microsoft Corporation * Copyright (c) 2025-present Eclipse ThreadX Contributors * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Transmission Control Protocol (TCP) */ /** */ /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_tcp.h" /* Bring in externs for caller checking code. */ NX_CALLER_CHECKING_EXTERNS /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nxe_tcp_socket_peer_info_get PORTABLE C */ /* 6.4.3 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function retrieves IP address and port number of the peer */ /* connected to the specified TCP socket. */ /* */ /* INPUT */ /* */ /* socket_ptr Pointer to the TCP sockete */ /* peer_ip_address Pointer to the IP address */ /* of the peer. */ /* peer_port Pointer to the port number */ /* of the peer. */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* _nx_tcp_socket_peer_info_get Actual TCP socket peer info */ /* get function */ /* CALLED BY */ /* */ /* Application Code */ /* */ /**************************************************************************/ UINT _nxe_tcp_socket_peer_info_get(NX_TCP_SOCKET *socket_ptr, ULONG *peer_ip_address, ULONG *peer_port) { #ifndef NX_DISABLE_IPV4 UINT status; /* Check for invalid input pointers. */ if ((socket_ptr == NX_NULL) || (socket_ptr -> nx_tcp_socket_id != NX_TCP_ID)) { return(NX_PTR_ERROR); } if ((peer_ip_address == NX_NULL) || (peer_port == NX_NULL)) { return(NX_PTR_ERROR); } /* Check to see if TCP is enabled. */ if (!(socket_ptr -> nx_tcp_socket_ip_ptr) -> nx_ip_tcp_packet_receive) { return(NX_NOT_ENABLED); } /* Check for appropriate caller. */ NX_THREADS_ONLY_CALLER_CHECKING /* Call actual TCP socket MSS get function. */ status = _nx_tcp_socket_peer_info_get(socket_ptr, peer_ip_address, peer_port); /* Return completion status. */ return(status); #else NX_PARAMETER_NOT_USED(socket_ptr); NX_PARAMETER_NOT_USED(peer_ip_address); NX_PARAMETER_NOT_USED(peer_port); return(NX_NOT_SUPPORTED); #endif /* NX_DISABLE_IPV4 */ }