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