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 /* Bring in externs for caller checking code.  */
32 NX_CALLER_CHECKING_EXTERNS
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _nxe_tcp_socket_peer_info_get                       PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Yuxin Zhou, Microsoft Corporation                                   */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function retrieves IP address and port number of the peer      */
47 /*    connected to the specified TCP socket.                              */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    socket_ptr                            Pointer to the TCP sockete    */
52 /*    peer_ip_address                       Pointer to the IP address     */
53 /*                                             of the peer.               */
54 /*    peer_port                             Pointer to the port number    */
55 /*                                             of the peer.               */
56 /*                                                                        */
57 /*  OUTPUT                                                                */
58 /*                                                                        */
59 /*    status                                Completion status             */
60 /*                                                                        */
61 /*  CALLS                                                                 */
62 /*                                                                        */
63 /*    _nx_tcp_socket_peer_info_get          Actual TCP socket peer info   */
64 /*                                             get function               */
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 /**************************************************************************/
_nxe_tcp_socket_peer_info_get(NX_TCP_SOCKET * socket_ptr,ULONG * peer_ip_address,ULONG * peer_port)78 UINT  _nxe_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 
85 
86     /* Check for invalid input pointers.  */
87     if ((socket_ptr == NX_NULL) || (socket_ptr -> nx_tcp_socket_id != NX_TCP_ID))
88     {
89         return(NX_PTR_ERROR);
90     }
91 
92     if ((peer_ip_address == NX_NULL) || (peer_port == NX_NULL))
93     {
94         return(NX_PTR_ERROR);
95     }
96 
97     /* Check to see if TCP is enabled.  */
98     if (!(socket_ptr -> nx_tcp_socket_ip_ptr) -> nx_ip_tcp_packet_receive)
99     {
100         return(NX_NOT_ENABLED);
101     }
102 
103     /* Check for appropriate caller.  */
104     NX_THREADS_ONLY_CALLER_CHECKING
105 
106     /* Call actual TCP socket MSS get function.  */
107     status =  _nx_tcp_socket_peer_info_get(socket_ptr, peer_ip_address, peer_port);
108 
109     /* Return completion status.  */
110     return(status);
111 #else
112     NX_PARAMETER_NOT_USED(socket_ptr);
113     NX_PARAMETER_NOT_USED(peer_ip_address);
114     NX_PARAMETER_NOT_USED(peer_port);
115 
116     return(NX_NOT_SUPPORTED);
117 #endif /* NX_DISABLE_IPV4 */
118 }
119 
120