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 /** Internet Protocol (IP) */
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_ip.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _nx_ip_address_get PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Yuxin Zhou, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function retrieves the IP address and the network mask and */
44 /* returns them to the caller. */
45 /* */
46 /* INPUT */
47 /* */
48 /* ip_ptr IP control block pointer */
49 /* ip_address Pointer to IP address */
50 /* destination */
51 /* network_mask Pointer to network mask */
52 /* destination */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* status Completion status */
57 /* */
58 /* CALLS */
59 /* */
60 /* tx_mutex_get Get protection mutex */
61 /* tx_mutex_put Put protection mutex */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Application Code */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
72 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
73 /* resulting in version 6.1 */
74 /* */
75 /**************************************************************************/
_nx_ip_address_get(NX_IP * ip_ptr,ULONG * ip_address,ULONG * network_mask)76 UINT _nx_ip_address_get(NX_IP *ip_ptr, ULONG *ip_address, ULONG *network_mask)
77 {
78
79 #ifndef NX_DISABLE_IPV4
80 TX_INTERRUPT_SAVE_AREA
81
82 /* Get mutex protection. */
83 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
84
85 /* Disable interrupts. */
86 TX_DISABLE
87
88 /* Pickup the IP address and the network mask. This service assumes
89 the operation on the primary interface. */
90 *ip_address = ip_ptr -> nx_ip_interface[0].nx_interface_ip_address;
91 *network_mask = ip_ptr -> nx_ip_interface[0].nx_interface_ip_network_mask;
92
93 /* Restore interrupts. */
94 TX_RESTORE
95
96 /* Release mutex protection. */
97 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
98
99 /* If trace is enabled, insert this event into the trace buffer. */
100 NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_ADDRESS_GET, ip_ptr, ip_ptr -> nx_ip_interface[0].nx_interface_ip_address,
101 ip_ptr -> nx_ip_interface[0].nx_interface_ip_network_mask, 0, NX_TRACE_IP_EVENTS, 0, 0);
102
103 /* Return completion status. */
104 return(NX_SUCCESS);
105 #else /* NX_DISABLE_IPV4 */
106 NX_PARAMETER_NOT_USED(ip_ptr);
107 NX_PARAMETER_NOT_USED(ip_address);
108 NX_PARAMETER_NOT_USED(network_mask);
109
110 return(NX_NOT_SUPPORTED);
111 #endif /* !NX_DISABLE_IPV4 */
112 }
113
114