1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** NetX Component */ 16 /** */ 17 /** Transmission Control Protocol (TCP) */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define NX_SOURCE_CODE 23 24 25 /* Include necessary system files. */ 26 27 #include "nx_api.h" 28 #include "nx_tcp.h" 29 30 /* Bring in externs for caller checking code. */ 31 NX_CALLER_CHECKING_EXTERNS 32 33 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _nxe_tcp_socket_peer_info_get PORTABLE C */ 38 /* 6.1 */ 39 /* AUTHOR */ 40 /* */ 41 /* Yuxin Zhou, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function retrieves IP address and port number of the peer */ 46 /* connected to the specified TCP socket. */ 47 /* */ 48 /* INPUT */ 49 /* */ 50 /* socket_ptr Pointer to the TCP sockete */ 51 /* peer_ip_address Pointer to the IP address */ 52 /* of the peer. */ 53 /* peer_port Pointer to the port number */ 54 /* of the peer. */ 55 /* */ 56 /* OUTPUT */ 57 /* */ 58 /* status Completion status */ 59 /* */ 60 /* CALLS */ 61 /* */ 62 /* _nx_tcp_socket_peer_info_get Actual TCP socket peer info */ 63 /* get function */ 64 /* CALLED BY */ 65 /* */ 66 /* Application Code */ 67 /* */ 68 /* RELEASE HISTORY */ 69 /* */ 70 /* DATE NAME DESCRIPTION */ 71 /* */ 72 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 73 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 74 /* resulting in version 6.1 */ 75 /* */ 76 /**************************************************************************/ _nxe_tcp_socket_peer_info_get(NX_TCP_SOCKET * socket_ptr,ULONG * peer_ip_address,ULONG * peer_port)77UINT _nxe_tcp_socket_peer_info_get(NX_TCP_SOCKET *socket_ptr, 78 ULONG *peer_ip_address, 79 ULONG *peer_port) 80 { 81 #ifndef NX_DISABLE_IPV4 82 UINT status; 83 84 85 /* Check for invalid input pointers. */ 86 if ((socket_ptr == NX_NULL) || (socket_ptr -> nx_tcp_socket_id != NX_TCP_ID)) 87 { 88 return(NX_PTR_ERROR); 89 } 90 91 if ((peer_ip_address == NX_NULL) || (peer_port == NX_NULL)) 92 { 93 return(NX_PTR_ERROR); 94 } 95 96 /* Check to see if TCP is enabled. */ 97 if (!(socket_ptr -> nx_tcp_socket_ip_ptr) -> nx_ip_tcp_packet_receive) 98 { 99 return(NX_NOT_ENABLED); 100 } 101 102 /* Check for appropriate caller. */ 103 NX_THREADS_ONLY_CALLER_CHECKING 104 105 /* Call actual TCP socket MSS get function. */ 106 status = _nx_tcp_socket_peer_info_get(socket_ptr, peer_ip_address, peer_port); 107 108 /* Return completion status. */ 109 return(status); 110 #else 111 NX_PARAMETER_NOT_USED(socket_ptr); 112 NX_PARAMETER_NOT_USED(peer_ip_address); 113 NX_PARAMETER_NOT_USED(peer_port); 114 115 return(NX_NOT_SUPPORTED); 116 #endif /* NX_DISABLE_IPV4 */ 117 } 118 119