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 /** User Datagram Protocol (UDP) */
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_udp.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _nx_udp_socket_port_get PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Yuxin Zhou, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function retrieves the bound port of the specified socket, */
45 /* which is especially useful in situations where NX_ANY_PORT was */
46 /* used to bind. */
47 /* */
48 /* INPUT */
49 /* */
50 /* socket_ptr Pointer to UDP socket */
51 /* port_ptr Destination for port bound to */
52 /* this socket */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* status Completion status */
57 /* */
58 /* CALLS */
59 /* */
60 /* None */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* Application Code */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
71 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* */
74 /**************************************************************************/
_nx_udp_socket_port_get(NX_UDP_SOCKET * socket_ptr,UINT * port_ptr)75 UINT _nx_udp_socket_port_get(NX_UDP_SOCKET *socket_ptr, UINT *port_ptr)
76 {
77 TX_INTERRUPT_SAVE_AREA
78
79
80 /* If trace is enabled, insert this event into the trace buffer. */
81 NX_TRACE_IN_LINE_INSERT(NX_TRACE_UDP_SOCKET_PORT_GET, socket_ptr -> nx_udp_socket_ip_ptr, socket_ptr, socket_ptr -> nx_udp_socket_port, 0, NX_TRACE_UDP_EVENTS, 0, 0);
82
83 /* Lockout interrupts. */
84 TX_DISABLE
85
86 /* Determine if the socket is currently bound. */
87 if (!socket_ptr -> nx_udp_socket_bound_next)
88 {
89
90 /* Restore interrupts. */
91 TX_RESTORE
92
93 /* Socket is not bound, return an error message. */
94 return(NX_NOT_BOUND);
95 }
96
97 /* Pickup the bound port for the UDP socket. */
98 *port_ptr = socket_ptr -> nx_udp_socket_port;
99
100 /* Restore interrupts. */
101 TX_RESTORE
102
103 /* Return a successful status. */
104 return(NX_SUCCESS);
105 }
106
107