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