MCPcopy Create free account
hub / github.com/crossuo/crossuo / tcp_connect

Function tcp_connect

src/Sockets.cpp:135–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135bool tcp_connect(tcp_socket socket, const char *address, uint16_t port)
136{
137 auto h = socket_fd(socket);
138 sockaddr_in caddr;
139 memset(&caddr, 0, sizeof(sockaddr_in));
140 caddr.sin_family = AF_INET;
141
142 struct hostent *he;
143 int rt = inet_addr(address);
144 if (rt != -1)
145 {
146 caddr.sin_addr.s_addr = rt;
147 }
148 else
149 {
150 he = gethostbyname(address);
151 if (he == nullptr)
152 return false;
153
154 memcpy(&caddr.sin_addr, he->h_addr, he->h_length);
155 }
156
157 caddr.sin_port = htons(port);
158 if (connect(h, (struct sockaddr *)&caddr, sizeof(caddr)) == -1)
159 {
160 //auto e = WSAGetLastError();
161 return false;
162 }
163
164 WSASetLastError(0);
165 return true;
166}
167
168int tcp_select(tcp_socket socket)
169{

Callers 1

ConnectMethod · 0.85

Calls 2

socket_fdFunction · 0.85
memcpyFunction · 0.85

Tested by

no test coverage detected