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 /**   Transmission Control Protocol (TCP)                                 */
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_tcp.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_tcp_client_socket_connect                       PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function handles the connect request for the supplied socket.  */
45 /*    If bound and not connected, this function will send the first SYN   */
46 /*    message to the specified server to initiate the connection process. */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    socket_ptr                            Pointer to TCP client socket  */
51 /*    server_ip                             IP address of server          */
52 /*    server_port                           Port number of server         */
53 /*    wait_option                           Suspension option             */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _nxd_tcp_client_socket_connect        Actual TCP client connect     */
62 /*                                            call                        */
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_tcp_client_socket_connect(NX_TCP_SOCKET * socket_ptr,ULONG server_ip,UINT server_port,ULONG wait_option)77 UINT  _nx_tcp_client_socket_connect(NX_TCP_SOCKET *socket_ptr,
78                                     ULONG server_ip,
79                                     UINT server_port,
80                                     ULONG wait_option)
81 {
82 
83 #ifndef NX_DISABLE_IPV4
84 NXD_ADDRESS server_ip_addr;
85 
86     /* Construct an IP address structure, and fill in IPv4 address information. */
87     server_ip_addr.nxd_ip_version = NX_IP_VERSION_V4;
88     server_ip_addr.nxd_ip_address.v4 = server_ip;
89 
90     /* Invoke the real connection call. */
91     return(_nxd_tcp_client_socket_connect(socket_ptr, &server_ip_addr, server_port, wait_option));
92 #else /* NX_DISABLE_IPV4  */
93     NX_PARAMETER_NOT_USED(socket_ptr);
94     NX_PARAMETER_NOT_USED(server_ip);
95     NX_PARAMETER_NOT_USED(server_port);
96     NX_PARAMETER_NOT_USED(wait_option);
97 
98     return(NX_NOT_SUPPORTED);
99 #endif /* !NX_DISABLE_IPV4  */
100 }
101 
102