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 /* Bring in externs for caller checking code.  */
31 NX_CALLER_CHECKING_EXTERNS
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _nxe_ip_interface_address_get                       PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Yuxin Zhou, Microsoft Corporation                                   */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function checks for errors in the IP address get function      */
47 /*    call.                                                               */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    ip_ptr                                IP control block pointer      */
52 /*    interface_index                       IP Interface Index            */
53 /*    ip_address                            Pointer to IP address         */
54 /*                                            destination                 */
55 /*    network_mask                          Pointer to network mask       */
56 /*                                            destination                 */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                                Completion status             */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _nx_ip_interface_address_get          Actual IP address get function*/
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Application Code                                                    */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
75 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
_nxe_ip_interface_address_get(NX_IP * ip_ptr,UINT interface_index,ULONG * ip_address,ULONG * network_mask)79 UINT  _nxe_ip_interface_address_get(NX_IP *ip_ptr, UINT interface_index, ULONG *ip_address, ULONG *network_mask)
80 {
81 
82 #ifndef NX_DISABLE_IPV4
83 UINT status;
84 
85 
86     /* Check for invalid input pointers.  */
87     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) || (ip_address == NX_NULL) || (network_mask == NX_NULL))
88     {
89         return(NX_PTR_ERROR);
90     }
91 
92     /* Check for valid interface ID */
93     if (interface_index >= NX_MAX_PHYSICAL_INTERFACES)
94     {
95         return(NX_INVALID_INTERFACE);
96     }
97 
98     /* Check for interface being valid. */
99     if (!ip_ptr -> nx_ip_interface[interface_index].nx_interface_valid)
100     {
101         return(NX_INVALID_INTERFACE);
102     }
103 
104     /* Check for appropriate caller.  */
105     NX_INIT_AND_THREADS_CALLER_CHECKING
106 
107     /* Call actual IP address get function.  */
108     status =  _nx_ip_interface_address_get(ip_ptr, interface_index, ip_address, network_mask);
109 
110     /* Return completion status.  */
111     return(status);
112 #else /* NX_DISABLE_IPV4  */
113     NX_PARAMETER_NOT_USED(ip_ptr);
114     NX_PARAMETER_NOT_USED(interface_index);
115     NX_PARAMETER_NOT_USED(ip_address);
116     NX_PARAMETER_NOT_USED(network_mask);
117 
118     return(NX_NOT_SUPPORTED);
119 #endif /* !NX_DISABLE_IPV4  */
120 }
121 
122