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 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_tcp_socket_peer_info_get                        PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function retrieves IP address and port number of the peer      */
44 /*    connected to the specified TCP socket.                              */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    socket_ptr                            Pointer to the TCP sockete    */
49 /*    peer_ip_address                       Pointer to the IP address     */
50 /*                                             of the peer.               */
51 /*    peer_port                             Pointer to the port number    */
52 /*                                             of the peer.               */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    tx_mutex_get                          Obtain protection             */
61 /*    tx_mutex_put                          Release protection            */
62 /*    _nxd_tcp_socket_peer_info_get         Obtain TCP socket information */
63 /*                                                                        */
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 /**************************************************************************/
_nx_tcp_socket_peer_info_get(NX_TCP_SOCKET * socket_ptr,ULONG * peer_ip_address,ULONG * peer_port)77 UINT  _nx_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 NXD_ADDRESS ip_address;
84 
85     status = _nxd_tcp_socket_peer_info_get(socket_ptr, &ip_address, peer_port);
86     if (status == NX_SUCCESS)
87     {
88 
89         /*lint -e{644} suppress variable might not be initialized, since "ip_address" was initialized as long as status is NX_SUCCESS. */
90         *peer_ip_address = ip_address.nxd_ip_address.v4;
91     }
92 
93 
94     /* Return successful completion status.  */
95     return(status);
96 #else
97     NX_PARAMETER_NOT_USED(socket_ptr);
98     NX_PARAMETER_NOT_USED(peer_ip_address);
99     NX_PARAMETER_NOT_USED(peer_port);
100 
101     return(NX_NOT_SUPPORTED);
102 #endif /* NX_DISABLE_IPV4 */
103 }
104 
105