/*************************************************************************** * Copyright (c) 2024 Microsoft Corporation * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Transmission Control Protocol (TCP) */ /** */ /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_ip.h" #include "nx_tcp.h" /* Bring in externs for caller checking code. */ NX_CALLER_CHECKING_EXTERNS /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nxe_tcp_free_port_find PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function checks for errors in the TCP free port find */ /* function call. */ /* */ /* INPUT */ /* */ /* ip_ptr IP instance pointer */ /* port Starting port */ /* free_port_ptr Pointer to return free port */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* _nx_tcp_free_port_find Actual TCP free port find */ /* function */ /* */ /* CALLED BY */ /* */ /* Application Code */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */ /**************************************************************************/ UINT _nxe_tcp_free_port_find(NX_IP *ip_ptr, UINT port, UINT *free_port_ptr) { UINT status; /* Check for invalid input pointers. */ if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) || (free_port_ptr == NX_NULL)) { return(NX_PTR_ERROR); } /* Check to see if TCP is enabled. */ if (!ip_ptr -> nx_ip_tcp_packet_receive) { return(NX_NOT_ENABLED); } /* Check for an invalid port. */ if (((ULONG)port) > (ULONG)NX_MAX_PORT) { return(NX_INVALID_PORT); } /* Check for appropriate caller. */ NX_THREADS_ONLY_CALLER_CHECKING /* Call actual TCP free port find function. */ status = _nx_tcp_free_port_find(ip_ptr, port, free_port_ptr); /* Return completion status. */ return(status); }