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