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 /** Internet Protocol (IP) */
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_ip.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _nx_ip_gateway_address_get PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Yuxin Zhou, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function gets the IP gateway address that will be used for */
45 /* sending IP packets with destination address addresses not in the */
46 /* local network. */
47 /* */
48 /* INPUT */
49 /* */
50 /* ip_ptr IP control block pointer */
51 /* ip_address Gateway IP address */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* status Completion status */
56 /* */
57 /* CALLS */
58 /* */
59 /* tx_mutex_get Obtain protection mutex */
60 /* tx_mutex_put Release protection mutex */
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_ip_gateway_address_get(NX_IP * ip_ptr,ULONG * ip_address)75 UINT _nx_ip_gateway_address_get(NX_IP *ip_ptr, ULONG *ip_address)
76 {
77
78 #ifndef NX_DISABLE_IPV4
79 UINT status;
80
81
82 /* Initialize the return value to be NX_NOT_FOUND. If the gateway address
83 is set, the return value changes to NX_SUCCESS. */
84 status = NX_NOT_FOUND;
85
86 /* Obtain the IP internal mutex to get the Gateway IP address. */
87 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
88
89 if (ip_ptr -> nx_ip_gateway_address)
90 {
91
92 /* Setup the Gateway IP address. */
93 *ip_address = ip_ptr -> nx_ip_gateway_address;
94
95 status = NX_SUCCESS;
96 }
97
98 /* Release the protection mutex. */
99 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
100
101 /* Return completion status. */
102 return(status);
103 #else /* NX_DISABLE_IPV4 */
104 NX_PARAMETER_NOT_USED(ip_ptr);
105 NX_PARAMETER_NOT_USED(ip_address);
106
107 return(NX_NOT_SUPPORTED);
108 #endif /* !NX_DISABLE_IPV4 */
109 }
110
111