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