1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_UNIX_SOCKET_PATH
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_ABSTRACT_UNIX_SOCKET (3)
9  - CURLOPT_OPENSOCKETFUNCTION (3)
10  - unix (7)
11---
12
13# NAME
14
15CURLOPT_UNIX_SOCKET_PATH - Unix domain socket
16
17# SYNOPSIS
18
19~~~c
20#include <curl/curl.h>
21
22CURLcode curl_easy_setopt(CURL *handle, CURLOPT_UNIX_SOCKET_PATH, char *path);
23~~~
24
25# DESCRIPTION
26
27Enables the use of Unix domain sockets as connection endpoint and sets the
28path to *path*. If *path* is NULL, then Unix domain sockets are
29disabled.
30
31When enabled, curl connects to the Unix domain socket instead of establishing
32a TCP connection to the host. Since no network connection is created, curl
33does not resolve the DNS hostname in the URL.
34
35The maximum path length on Cygwin, Linux and Solaris is 107. On other platforms
36it might be even less.
37
38Proxy and TCP options such as CURLOPT_TCP_NODELAY(3) are not
39supported. Proxy options such as CURLOPT_PROXY(3) have no effect either
40as these are TCP-oriented, and asking a proxy server to connect to a certain
41Unix domain socket is not possible.
42
43The application does not have to keep the string around after setting this
44option.
45
46# DEFAULT
47
48Default is NULL, meaning that no Unix domain sockets are used.
49
50# PROTOCOLS
51
52All protocols except for FILE and FTP are supported in theory. HTTP, IMAP,
53POP3 and SMTP should in particular work (including their SSL/TLS variants).
54
55# EXAMPLE
56
57~~~c
58int main(void)
59{
60  CURL *curl = curl_easy_init();
61  if(curl) {
62    curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, "/tmp/httpd.sock");
63    curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/");
64
65    curl_easy_perform(curl);
66  }
67}
68~~~
69
70If you are on Linux and somehow have a need for paths larger than 107 bytes,
71you can use the proc filesystem to bypass the limitation:
72
73~~~c
74  int dirfd = open(long_directory_path_to_socket, O_DIRECTORY | O_RDONLY);
75  char path[108];
76  snprintf(path, sizeof(path), "/proc/self/fd/%d/httpd.sock", dirfd);
77  curl_easy_setopt(curl_handle, CURLOPT_UNIX_SOCKET_PATH, path);
78  /* Be sure to keep dirfd valid until you discard the handle */
79~~~
80
81# AVAILABILITY
82
83Added in 7.40.0.
84
85# RETURN VALUE
86
87Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
88