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 #ifdef FEATURE_NX_IPV6
30 #include "nx_ipv6.h"
31 #endif /* FEATURE_NX_IPV6 */
32 
33 /* Bring in externs for caller checking code.  */
34 NX_CALLER_CHECKING_EXTERNS
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _nxde_udp_socket_extract                            PORTABLE C      */
41 /*                                                           6.1          */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Yuxin Zhou, Microsoft Corporation                                   */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This function checks for errors in the UDP source extract           */
49 /*    function call.                                                      */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    packet_ptr                            Pointer to UDP packet pointer */
54 /*    ip_address                            Pointer to source IP address  */
55 /*    port                                  Pointer to ource UDP port     */
56 /*                                                                        */
57 /*  OUTPUT                                                                */
58 /*                                                                        */
59 /*    status                                Actual completion status      */
60 /*                                                                        */
61 /*  CALLS                                                                 */
62 /*                                                                        */
63 /*    _nxd_udp_source_extract               Actual UDP source extract     */
64 /*                                            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 /**************************************************************************/
_nxde_udp_source_extract(NX_PACKET * packet_ptr,NXD_ADDRESS * ip_address,UINT * port)79 UINT  _nxde_udp_source_extract(NX_PACKET *packet_ptr, NXD_ADDRESS *ip_address, UINT *port)
80 {
81 
82 UINT status;
83 
84     /* Check for invalid input pointers.  */
85     if ((packet_ptr == NX_NULL) || (ip_address == NX_NULL) || (port == NX_NULL))
86     {
87         return(NX_PTR_ERROR);
88     }
89 
90     if (packet_ptr -> nx_packet_ip_header == NX_NULL)
91     {
92         return(NX_INVALID_PACKET);
93     }
94 
95     /* Check for appropriate caller.  */
96     NX_THREADS_ONLY_CALLER_CHECKING
97 
98     /* Call actual UDP source extract function.  */
99     status =  _nxd_udp_source_extract(packet_ptr, ip_address, port);
100 
101     /* Return completion status.  */
102     return(status);
103 }
104 
105