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_ip.h" 30 #include "nx_udp.h" 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _nxe_udp_source_extract PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Yuxin Zhou, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function checks for errors in the extract UDP source call. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* packet_ptr Pointer to UDP packet pointer */ 49 /* ip_address Pointer to packet source IP */ 50 /* address */ 51 /* port Pointer to source UDP port */ 52 /* */ 53 /* OUTPUT */ 54 /* */ 55 /* status Actual completion status */ 56 /* NX_PTR_ERROR Invalid pointer input */ 57 /* NX_INVALID_PACKET Malformed packet to process */ 58 /* */ 59 /* CALLS */ 60 /* */ 61 /* _nx_udp_source_extract Actual UDP source extract */ 62 /* function */ 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 /**************************************************************************/ _nxe_udp_source_extract(NX_PACKET * packet_ptr,ULONG * ip_address,UINT * port)77UINT _nxe_udp_source_extract(NX_PACKET *packet_ptr, ULONG *ip_address, UINT *port) 78 { 79 80 #ifndef NX_DISABLE_IPV4 81 UINT status; 82 83 84 /* Check for invalid input pointers. */ 85 if ((packet_ptr == NX_NULL) || (ip_address == NX_NULL) || (port == NX_NULL)) 86 { 87 88 return(NX_PTR_ERROR); 89 } 90 91 /* Check for invalid packet pointer. */ 92 if (packet_ptr -> nx_packet_ip_header == NX_NULL) 93 { 94 95 return(NX_INVALID_PACKET); 96 } 97 98 99 if (packet_ptr -> nx_packet_ip_version != NX_IP_VERSION_V4) 100 { 101 102 return(NX_INVALID_PACKET); 103 } 104 105 /* Check to see if the packet has enough room in front for backing up. */ 106 /*lint -e{946} -e{947} suppress pointer subtraction, since it is necessary. */ 107 if ((UINT)(packet_ptr -> nx_packet_prepend_ptr - packet_ptr -> nx_packet_data_start) < 108 (sizeof(NX_UDP_HEADER) + sizeof(NX_IPV4_HEADER))) 109 { 110 111 return(NX_INVALID_PACKET); 112 } 113 114 /* Call actual UDP source extract function. */ 115 status = _nx_udp_source_extract(packet_ptr, ip_address, port); 116 117 /* Return completion status. */ 118 return(status); 119 #else 120 NX_PARAMETER_NOT_USED(packet_ptr); 121 NX_PARAMETER_NOT_USED(ip_address); 122 NX_PARAMETER_NOT_USED(port); 123 124 return(NX_NOT_SUPPORTED); 125 #endif /* !NX_DISABLE_IPV4 */ 126 } 127 128