#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 "curlx/nonblock.h" /* for curlx_nonblock() */28#include "sockaddr.h"2930struct Curl_addrinfo;31struct Curl_cfilter;32struct Curl_easy;33struct connectdata;34struct Curl_sockaddr_ex;35struct ip_quadruple;3637/*38* The Curl_sockaddr_ex structure is basically libcurl's external API39* curl_sockaddr structure with enough space available to directly hold any40* protocol-specific address structures. The variable declared here will be41* used to pass / receive data to/from the fopensocket callback if this has42* been set, before that, it is initialized from parameters.43*/44struct Curl_sockaddr_ex {45int family;46int socktype;47int protocol;48unsigned int addrlen;49union {50struct sockaddr addr;51struct Curl_sockaddr_storage buff;52} _sa_ex_u;53};54#define curl_sa_addr _sa_ex_u.addr5556/*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,72int 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://support.microsoft.com/kb/8237648384Work-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* Assign the address `ai` to the Curl_sockaddr_ex `dest` and95* set the transport used.96*/97CURLcode Curl_sock_assign_addr(struct Curl_sockaddr_ex *dest,98const struct Curl_addrinfo *ai,99int transport);100101/**102* Creates a cfilter that opens a TCP socket to the given address103* when calling its `connect` implementation.104* The filter will not touch any connection/data flags and can be105* used in happy eyeballing. Once selected for use, its `_active()`106* method needs to be called.107*/108CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf,109struct Curl_easy *data,110struct connectdata *conn,111const struct Curl_addrinfo *ai,112int transport);113114/**115* Creates a cfilter that opens a UDP socket to the given address116* when calling its `connect` implementation.117* The filter will not touch any connection/data flags and can be118* used in happy eyeballing. Once selected for use, its `_active()`119* method needs to be called.120*/121CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf,122struct Curl_easy *data,123struct connectdata *conn,124const struct Curl_addrinfo *ai,125int transport);126127/**128* Creates a cfilter that opens a UNIX socket to the given address129* when calling its `connect` implementation.130* The filter will not touch any connection/data flags and can be131* used in happy eyeballing. Once selected for use, its `_active()`132* method needs to be called.133*/134CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf,135struct Curl_easy *data,136struct connectdata *conn,137const struct Curl_addrinfo *ai,138int transport);139140/**141* Creates a cfilter that keeps a listening socket.142*/143CURLcode Curl_conn_tcp_listen_set(struct Curl_easy *data,144struct connectdata *conn,145int sockindex,146curl_socket_t *s);147148/**149* Return TRUE iff the last filter at `sockindex` was set via150* Curl_conn_tcp_listen_set().151*/152bool Curl_conn_is_tcp_listen(struct Curl_easy *data,153int sockindex);154155/**156* Peek at the socket and remote ip/port the socket filter is using.157* The filter owns all returned values.158* @param psock pointer to hold socket descriptor or NULL159* @param paddr pointer to hold addr reference or NULL160* @param pip pointer to get IP quadruple or NULL161* Returns error if the filter is of invalid type.162*/163CURLcode Curl_cf_socket_peek(struct Curl_cfilter *cf,164struct Curl_easy *data,165curl_socket_t *psock,166const struct Curl_sockaddr_ex **paddr,167struct ip_quadruple *pip);168169extern struct Curl_cftype Curl_cft_tcp;170extern struct Curl_cftype Curl_cft_udp;171extern struct Curl_cftype Curl_cft_unix;172extern struct Curl_cftype Curl_cft_tcp_accept;173174#endif /* HEADER_CURL_CF_SOCKET_H */175176177