1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Component                                                        */
17 /**                                                                       */
18 /**   Transmission Control Protocol (TCP)                                 */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "nx_api.h"
29 #include "nx_tcp.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_tcp_socket_peer_info_get                        PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function retrieves IP address and port number of the peer      */
45 /*    connected to the specified TCP socket.                              */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    socket_ptr                            Pointer to the TCP sockete    */
50 /*    peer_ip_address                       Pointer to the IP address     */
51 /*                                             of the peer.               */
52 /*    peer_port                             Pointer to the port number    */
53 /*                                             of the peer.               */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    tx_mutex_get                          Obtain protection             */
62 /*    tx_mutex_put                          Release protection            */
63 /*    _nxd_tcp_socket_peer_info_get         Obtain TCP socket information */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application Code                                                    */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
74 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_nx_tcp_socket_peer_info_get(NX_TCP_SOCKET * socket_ptr,ULONG * peer_ip_address,ULONG * peer_port)78 UINT  _nx_tcp_socket_peer_info_get(NX_TCP_SOCKET *socket_ptr,
79                                    ULONG *peer_ip_address,
80                                    ULONG *peer_port)
81 {
82 #ifndef NX_DISABLE_IPV4
83 UINT        status;
84 NXD_ADDRESS ip_address;
85 
86     status = _nxd_tcp_socket_peer_info_get(socket_ptr, &ip_address, peer_port);
87     if (status == NX_SUCCESS)
88     {
89 
90         /*lint -e{644} suppress variable might not be initialized, since "ip_address" was initialized as long as status is NX_SUCCESS. */
91         *peer_ip_address = ip_address.nxd_ip_address.v4;
92     }
93 
94 
95     /* Return successful completion status.  */
96     return(status);
97 #else
98     NX_PARAMETER_NOT_USED(socket_ptr);
99     NX_PARAMETER_NOT_USED(peer_ip_address);
100     NX_PARAMETER_NOT_USED(peer_port);
101 
102     return(NX_NOT_SUPPORTED);
103 #endif /* NX_DISABLE_IPV4 */
104 }
105 
106