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 /** Transmission Control Protocol (TCP) */
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_tcp.h"
29
30
31 /* Bring in externs for caller checking code. */
32
33 NX_CALLER_CHECKING_EXTERNS
34
35
36 /**************************************************************************/
37 /* */
38 /* FUNCTION RELEASE */
39 /* */
40 /* _nxe_tcp_client_socket_connect PORTABLE C */
41 /* 6.1 */
42 /* AUTHOR */
43 /* */
44 /* Yuxin Zhou, Microsoft Corporation */
45 /* */
46 /* DESCRIPTION */
47 /* */
48 /* This function checks for errors in the TCP client socket connect */
49 /* function call. */
50 /* */
51 /* INPUT */
52 /* */
53 /* socket_ptr Pointer to TCP client socket */
54 /* server_ip IP address of server */
55 /* server_port Port number of server */
56 /* wait_option Suspension option */
57 /* */
58 /* OUTPUT */
59 /* */
60 /* status Completion status */
61 /* */
62 /* CALLS */
63 /* */
64 /* _nx_tcp_client_socket_connect Actual client socket connect */
65 /* function */
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 /**************************************************************************/
_nxe_tcp_client_socket_connect(NX_TCP_SOCKET * socket_ptr,ULONG server_ip,UINT server_port,ULONG wait_option)80 UINT _nxe_tcp_client_socket_connect(NX_TCP_SOCKET *socket_ptr, ULONG server_ip, UINT server_port, ULONG wait_option)
81 {
82
83 #ifndef NX_DISABLE_IPV4
84
85 UINT status;
86
87
88 /* Check for invalid input pointers. */
89 if ((socket_ptr == NX_NULL) || (socket_ptr -> nx_tcp_socket_id != NX_TCP_ID))
90 {
91 return(NX_PTR_ERROR);
92 }
93
94 /* Check to see if TCP is enabled. */
95 if (!(socket_ptr -> nx_tcp_socket_ip_ptr) -> nx_ip_tcp_packet_receive)
96 {
97 return(NX_NOT_ENABLED);
98 }
99
100 /* Check for invalid IP address. */
101 if (!server_ip)
102 {
103 return(NX_IP_ADDRESS_ERROR);
104 }
105
106 /* Check for invalid IP address. */
107 if (((server_ip & NX_IP_CLASS_A_MASK) != NX_IP_CLASS_A_TYPE) &&
108 ((server_ip & NX_IP_CLASS_B_MASK) != NX_IP_CLASS_B_TYPE) &&
109 ((server_ip & NX_IP_CLASS_C_MASK) != NX_IP_CLASS_C_TYPE))
110 {
111 return(NX_IP_ADDRESS_ERROR);
112 }
113
114 /* Check for an invalid port. */
115 if (((ULONG)server_port) > (ULONG)NX_MAX_PORT)
116 {
117 return(NX_INVALID_PORT);
118 }
119
120 /* Check for appropriate caller. */
121 NX_THREADS_ONLY_CALLER_CHECKING
122
123 /* Call actual TCP client socket connect function. */
124 status = _nx_tcp_client_socket_connect(socket_ptr, server_ip, server_port, wait_option);
125
126 /* Return completion status. */
127 return(status);
128 #else /* NX_DISABLE_IPV4 */
129 NX_PARAMETER_NOT_USED(socket_ptr);
130 NX_PARAMETER_NOT_USED(server_ip);
131 NX_PARAMETER_NOT_USED(server_port);
132 NX_PARAMETER_NOT_USED(wait_option);
133
134 return(NX_NOT_SUPPORTED);
135 #endif /* !NX_DISABLE_IPV4 */
136 }
137
138