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 /**   User Datagram Protocol (UDP)                                        */
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_udp.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_udp_packet_info_extract                         PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function extracts the source IP, protocol, (the protocol is    */
45 /*    always UDP), port number and the incoming interface from the        */
46 /*    incoming packet.                                                    */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    packet_ptr                            Pointer to UDP packet         */
51 /*    ip_address                            Pointer to sender IP address  */
52 /*    protocol                              Pointer to packet protocol.   */
53 /*                                             Always 17 (UDP)            */
54 /*    port                                  Pointer to sender source port */
55 /*    incoming_interface                    Pointer to interface index    */
56 /*                                            packet received on          */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    NX_SUCCESS                            Successful completion status  */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    nxd_udp_packet_info_extract           Invoke the NXD version of the */
65 /*                                            service.                    */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    Application Code                                                    */
70 /*                                                                        */
71 /*  RELEASE HISTORY                                                       */
72 /*                                                                        */
73 /*    DATE              NAME                      DESCRIPTION             */
74 /*                                                                        */
75 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
76 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
77 /*                                            resulting in version 6.1    */
78 /*                                                                        */
79 /**************************************************************************/
_nx_udp_packet_info_extract(NX_PACKET * packet_ptr,ULONG * ip_address,UINT * protocol,UINT * port,UINT * interface_index)80 UINT  _nx_udp_packet_info_extract(NX_PACKET *packet_ptr, ULONG *ip_address,
81                                   UINT *protocol, UINT *port, UINT *interface_index)
82 {
83 
84 #ifndef NX_DISABLE_IPV4
85 NXD_ADDRESS nxd_ip_address;
86 UINT        status;
87 
88 
89     /* Call the NXD version of the service. */
90     status = _nxd_udp_packet_info_extract(packet_ptr, &nxd_ip_address, protocol, port, interface_index);
91 
92     if (status == NX_SUCCESS)
93     {
94         if (ip_address)
95         {
96 
97             /*lint -e{644} suppress variable might not be initialized, since "nxd_ip_address" was initialized in _nxd_udp_packet_info_extract. */
98             if (nxd_ip_address.nxd_ip_version == NX_IP_VERSION_V4)
99             {
100                 *ip_address = nxd_ip_address.nxd_ip_address.v4;
101             }
102             else
103             {
104                 return(NX_INVALID_PACKET);
105             }
106         }
107     }
108 
109     return(status);
110 #else
111     NX_PARAMETER_NOT_USED(packet_ptr);
112     NX_PARAMETER_NOT_USED(ip_address);
113     NX_PARAMETER_NOT_USED(protocol);
114     NX_PARAMETER_NOT_USED(port);
115     NX_PARAMETER_NOT_USED(interface_index);
116 
117     return(NX_NOT_SUPPORTED);
118 #endif /* NX_DISABLE_IPV4 */
119 }
120 
121