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 #include "nx_ipv4.h"
31
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _nx_udp_socket_extract PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* Yuxin Zhou, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function extracts the source IP and UDP port number from the */
47 /* supplied packet. */
48 /* */
49 /* INPUT */
50 /* */
51 /* packet_ptr Pointer to UDP packet pointer */
52 /* ip_address Pointer to packet source IP */
53 /* address */
54 /* port Pointer to source UDP port */
55 /* */
56 /* OUTPUT */
57 /* */
58 /* NX_SUCCESS Successful completion status */
59 /* */
60 /* CALLS */
61 /* */
62 /* None */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Application Code */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
73 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
74 /* resulting in version 6.1 */
75 /* */
76 /**************************************************************************/
_nx_udp_source_extract(NX_PACKET * packet_ptr,ULONG * ip_address,UINT * port)77 UINT _nx_udp_source_extract(NX_PACKET *packet_ptr, ULONG *ip_address, UINT *port)
78 {
79
80 #ifndef NX_DISABLE_IPV4
81 ULONG *temp_ptr;
82 NX_IPV4_HEADER *ipv4_header;
83
84 /* Build an address to the current top of the packet. */
85 /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */
86 temp_ptr = (ULONG *)packet_ptr -> nx_packet_prepend_ptr;
87
88 /* Pickup the source port. */
89 *port = (UINT)(*(temp_ptr - 2) >> NX_SHIFT_BY_16);
90
91 /* Obtain the IPv4 header. */
92 /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */
93 ipv4_header = (NX_IPV4_HEADER *)packet_ptr -> nx_packet_ip_header;
94
95 /* Pickup the source IP address. */
96 *ip_address = ipv4_header -> nx_ip_header_source_ip;
97
98 /* If trace is enabled, insert this event into the trace buffer. */
99 NX_TRACE_IN_LINE_INSERT(NX_TRACE_UDP_SOURCE_EXTRACT, packet_ptr, *ip_address, *port, 0, NX_TRACE_UDP_EVENTS, 0, 0);
100
101 return(NX_SUCCESS);
102 #else
103 NX_PARAMETER_NOT_USED(packet_ptr);
104 NX_PARAMETER_NOT_USED(ip_address);
105 NX_PARAMETER_NOT_USED(port);
106
107 return(NX_NOT_SUPPORTED);
108 #endif /* !NX_DISABLE_IPV4 */
109 }
110
111