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