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 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_tcp_client_socket_connect                       PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function handles the connect request for the supplied socket.  */
44 /*    If bound and not connected, this function will send the first SYN   */
45 /*    message to the specified server to initiate the connection process. */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    socket_ptr                            Pointer to TCP client socket  */
50 /*    server_ip                             IP address of server          */
51 /*    server_port                           Port number of server         */
52 /*    wait_option                           Suspension option             */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _nxd_tcp_client_socket_connect        Actual TCP client connect     */
61 /*                                            call                        */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
72 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_nx_tcp_client_socket_connect(NX_TCP_SOCKET * socket_ptr,ULONG server_ip,UINT server_port,ULONG wait_option)76 UINT  _nx_tcp_client_socket_connect(NX_TCP_SOCKET *socket_ptr,
77                                     ULONG server_ip,
78                                     UINT server_port,
79                                     ULONG wait_option)
80 {
81 
82 #ifndef NX_DISABLE_IPV4
83 NXD_ADDRESS server_ip_addr;
84 
85     /* Construct an IP address structure, and fill in IPv4 address information. */
86     server_ip_addr.nxd_ip_version = NX_IP_VERSION_V4;
87     server_ip_addr.nxd_ip_address.v4 = server_ip;
88 
89     /* Invoke the real connection call. */
90     return(_nxd_tcp_client_socket_connect(socket_ptr, &server_ip_addr, server_port, wait_option));
91 #else /* NX_DISABLE_IPV4  */
92     NX_PARAMETER_NOT_USED(socket_ptr);
93     NX_PARAMETER_NOT_USED(server_ip);
94     NX_PARAMETER_NOT_USED(server_port);
95     NX_PARAMETER_NOT_USED(wait_option);
96 
97     return(NX_NOT_SUPPORTED);
98 #endif /* !NX_DISABLE_IPV4  */
99 }
100 
101