#ifndef HEADER_CURL_CF_SOCKET_H1#define HEADER_CURL_CF_SOCKET_H2/***************************************************************************3* _ _ ____ _4* Project ___| | | | _ \| |5* / __| | | | |_) | |6* | (__| |_| | _ <| |___7* \___|\___/|_| \_\_____|8*9* Copyright (C) Daniel Stenberg, <[email protected]>, et al.10*11* This software is licensed as described in the file COPYING, which12* you should have received as part of this distribution. The terms13* are also available at https://curl.se/docs/copyright.html.14*15* You may opt to use, copy, modify, merge, publish, distribute and/or sell16* copies of the Software, and permit persons to whom the Software is17* furnished to do so, under the terms of the COPYING file.18*19* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY20* KIND, either express or implied.21*22* SPDX-License-Identifier: curl23*24***************************************************************************/25#include "curl_setup.h"2627#include "sockaddr.h" /* required for Curl_sockaddr_storage */2829struct Curl_addrinfo;30struct Curl_cfilter;31struct Curl_easy;32struct connectdata;33struct Curl_sockaddr_ex;34struct ip_quadruple;3536/*37* The Curl_sockaddr_ex structure is basically libcurl's external API38* curl_sockaddr structure with enough space available to directly hold any39* protocol-specific address structures. The variable declared here will be40* used to pass / receive data to/from the fopensocket callback if this has41* been set, before that, it is initialized from parameters.42*/43struct Curl_sockaddr_ex {44int family;45int socktype;46int protocol;47unsigned int addrlen;48union {49struct sockaddr sa;50struct Curl_sockaddr_storage buf;51} addr;52};53#define curl_sa_addr addr.sa54#define curl_sa_addrbuf addr.buf5556/*57* Parse interface option, and return the interface name and the host part.58*/59CURLcode Curl_parse_interface(const char *input,60char **dev, char **iface, char **host);6162/*63* Create a socket based on info from 'conn' and 'ai'.64*65* Fill in 'addr' and 'sockfd' accordingly if OK is returned. If the open66* socket callback is set, used that!67*68*/69CURLcode Curl_socket_open(struct Curl_easy *data,70const struct Curl_addrinfo *ai,71struct Curl_sockaddr_ex *addr,72uint8_t transport,73curl_socket_t *sockfd);7475int Curl_socket_close(struct Curl_easy *data, struct connectdata *conn,76curl_socket_t sock);7778#ifdef USE_WINSOCK79/* When you run a program that uses the Windows Sockets API, you may80experience slow performance when you copy data to a TCP server.8182https://learn.microsoft.com/troubleshoot/windows-server/networking/slow-performance-copy-data-tcp-server-sockets-api8384Work-around: Make the Socket Send Buffer Size Larger Than the Program Send85Buffer Size8687*/88void Curl_sndbuf_init(curl_socket_t sockfd);89#else90#define Curl_sndbuf_init(y) Curl_nop_stmt91#endif9293/**94* Creates a cfilter that opens a TCP socket to the given address95* when calling its `connect` implementation.96* The filter will not touch any connection/data flags and can be97* used in happy eyeballing. Once selected for use, its `_active()`98* method needs to be called.99*/100CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf,101struct Curl_easy *data,102struct connectdata *conn,103const struct Curl_addrinfo *ai,104uint8_t transport);105106/**107* Creates a cfilter that opens a UDP socket to the given address108* when calling its `connect` implementation.109* The filter will not touch any connection/data flags and can be110* used in happy eyeballing. Once selected for use, its `_active()`111* method needs to be called.112*/113CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf,114struct Curl_easy *data,115struct connectdata *conn,116const struct Curl_addrinfo *ai,117uint8_t transport);118119/**120* Creates a cfilter that opens a UNIX socket to the given address121* when calling its `connect` implementation.122* The filter will not touch any connection/data flags and can be123* used in happy eyeballing. Once selected for use, its `_active()`124* method needs to be called.125*/126CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf,127struct Curl_easy *data,128struct connectdata *conn,129const struct Curl_addrinfo *ai,130uint8_t transport);131132/**133* Creates a cfilter that keeps a listening socket.134*/135CURLcode Curl_conn_tcp_listen_set(struct Curl_easy *data,136struct connectdata *conn,137int sockindex,138curl_socket_t *s);139140/**141* Return TRUE iff the last filter at `sockindex` was set via142* Curl_conn_tcp_listen_set().143*/144bool Curl_conn_is_tcp_listen(struct Curl_easy *data,145int sockindex);146147/**148* Peek at the socket and remote ip/port the socket filter is using.149* The filter owns all returned values.150* @param psock pointer to hold socket descriptor or NULL151* @param paddr pointer to hold addr reference or NULL152* @param pip pointer to get IP quadruple or NULL153* Returns error if the filter is of invalid type.154*/155CURLcode Curl_cf_socket_peek(struct Curl_cfilter *cf,156struct Curl_easy *data,157curl_socket_t *psock,158const struct Curl_sockaddr_ex **paddr,159struct ip_quadruple *pip) WARN_UNUSED_RESULT;160161extern struct Curl_cftype Curl_cft_tcp;162extern struct Curl_cftype Curl_cft_udp;163extern struct Curl_cftype Curl_cft_unix;164extern struct Curl_cftype Curl_cft_tcp_accept;165166#endif /* HEADER_CURL_CF_SOCKET_H */167168169