1CURLOPT_UNIX_SOCKET_PATH(3)curl_easy_setopt optionsCURLOPT_UNIX_SOCKET_PATH(3)
2
3
4
6 CURLOPT_UNIX_SOCKET_PATH - set Unix domain socket
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_UNIX_SOCKET_PATH, char
12 *path);
13
15 Enables the use of Unix domain sockets as connection endpoint and sets
16 the path to path. If path is NULL, then Unix domain sockets are dis‐
17 abled. An empty string will result in an error at some point, it will
18 not disable use of Unix domain sockets.
19
20 When enabled, curl will connect to the Unix domain socket instead of
21 establishing a TCP connection to a host. Since no TCP connection is
22 created, curl does not need to resolve the DNS hostname in the URL.
23
24 The maximum path length on Cygwin, Linux and Solaris is 107. On other
25 platforms it might be even less.
26
27 Proxy and TCP options such as CURLOPT_TCP_NODELAY(3) are not supported.
28 Proxy options such as CURLOPT_PROXY(3) have no effect either as these
29 are TCP-oriented, and asking a proxy server to connect to a certain
30 Unix domain socket is not possible.
31
32 The application does not have to keep the string around after setting
33 this option.
34
36 Default is NULL, meaning that no Unix domain sockets are used.
37
39 All protocols except for file:// and FTP are supported in theory. HTTP,
40 IMAP, POP3 and SMTP should in particular work (including their SSL/TLS
41 variants).
42
44 Given that you have an nginx server running, listening on
45 /tmp/nginx.sock, you can request an HTTP resource with:
46
47 curl_easy_setopt(curl_handle, CURLOPT_UNIX_SOCKET_PATH, "/tmp/nginx.sock");
48 curl_easy_setopt(curl_handle, CURLOPT_URL, "http://localhost/");
49
50 If you are on Linux and somehow have a need for paths larger than 107
51 bytes, you could use the proc filesystem to bypass the limitation:
52
53 int dirfd = open(long_directory_path_to_socket, O_DIRECTORY | O_RDONLY);
54 char path[108];
55 snprintf(path, sizeof(path), "/proc/self/fd/%d/nginx.sock", dirfd);
56 curl_easy_setopt(curl_handle, CURLOPT_UNIX_SOCKET_PATH, path);
57 /* Be sure to keep dirfd valid until you discard the handle */
58
60 Since 7.40.0.
61
63 Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION
64 if not.
65
67 CURLOPT_OPENSOCKETFUNCTION(3), unix(7),
68
69
70
71libcurl 7.69.1 April 17, 2018 CURLOPT_UNIX_SOCKET_PATH(3)