Unix ___domain socket: Difference between revisions

Content deleted Content added
m MOS:AKA, MOS:BOLDLINKAVOID, MOS:BOLDSYN, delete incorrect commas
 
(124 intermediate revisions by 84 users not shown)
Line 1:
{{Short description|Communications endpoint for exchanging data between processes}}
A '''Unix ___domain socket''' or('''UDS'''), '''IPClocal socket''', ([[or '''inter-process communication]]''' socket('''IPC''') '''socket''' is a data communications[[communication endpoint]] for [[inter-process communication|exchanging data between processes]] executing withinin the same host[[Unix]] or [[Unix-like]] operating system. While similar in functionality to
[[named pipe]]s, Unix ___domain sockets may be created as [[byte stream]]s or as [[datagram]] sequences, while pipes are byte streams only. Processes using Unix ___domain sockets do not need to share a common ancestry. The programmer's application interface (API) for Unix ___domain sockets is similar to that of an [[Internet socket]], but does not use an underlying network protocol for communication. The Unix ___domain socket facility is a standard component of [[POSIX]] [[operating system]]s.
 
The name ''Unix ___domain socket'' refers to the <code>___domain</code> argument value <code>AF_UNIX</code> that is passed to the function that creates a socket [[system resource]]. The same communication ___domain is also selected by <code>AF_LOCAL</code>. <ref name="man-unix-sockets"></ref>
UNIX ___domain sockets use the file system as address [[Namespace (computer science)|name space]]. They are referenced by processes as [[inodes]] in the file system. This allows two processes to open the same socket in order to communicate. However, communication occurs entirely within the operating system kernel.
 
Valid <code>type</code> argument values for a UDS are:<ref name="man-unix-sockets">{{cite web
In addition to sending data, processes may send [[file descriptor]]s across a Unix ___domain socket connection using the sendmsg() and recvmsg() system calls.
| url = http://man7.org/linux/man-pages/man7/unix.7.html
| date = 30 April 2018
| title = Linux Programmer's Manual (unix - sockets for local interprocess communication)
| access-date = 22 February 2019
| df = dmy-all}}</ref>
* <code>SOCK_STREAM</code> (compare to [[Transmission Control Protocol|TCP]]) – for a stream-oriented socket
* <code>SOCK_DGRAM</code> (compare to [[User Datagram Protocol|UDP]]) – for a datagram-oriented socket that preserves message boundaries (as on most UNIX implementations, UNIX ___domain datagram sockets are always reliable and don't reorder datagrams)
* <code>SOCK_SEQPACKET</code> (compare to [[SCTP]]) – for a sequenced-packet socket that is connection-oriented, preserves message boundaries, and delivers messages in the order that they were sent
 
The UDS facility is a standard component of a [[POSIX]] [[operating system]].
 
The [[API]] for a UDS is similar to that of an [[Internet socket]], but rather than using an underlying network protocol, all communication occurs entirely within the operating system [[kernel (operating system)|kernel]]. A UDS may use the file system as its address [[name space]]. Some operating systems, like [[Linux]], offer additional namespaces. Processes reference a UDS as a file system [[inode]], so two processes can communicate by opening the same socket.
 
In addition to sending data, processes may send [[file descriptor]]s across a UDS connection using the <code>sendmsg()</code> and <code>recvmsg()</code> system calls. This allows the sending processes to grant the receiving process access to a file descriptor for which the receiving process otherwise does not have access.<ref name="neohapsis">{{cite web |url=http://archives.neohapsis.com/archives/postfix/2000-09/1476.html |date=30 September 2000 |title=Archive of the "Postfix Discussions" mailing list |access-date=29 September 2014 |archive-url=https://web.archive.org/web/20130518084034/http://archives.neohapsis.com/archives/postfix/2000-09/1476.html |archive-date=18 May 2013 |url-status=dead |df=dmy-all}}</ref><ref name="linux-cmsg-man-page">{{cite web |url=https://linux.die.net/man/3/cmsg |title=Linux man page - cmsg(3): access ancillary data |access-date=9 October 2018 |df=dmy-all}}</ref> This can be used to implement a rudimentary form of [[capability-based security]].<ref name="wheeler-secure-linux-howto">{{cite web |url=https://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/sockets.html |title="Secure Programming for Linux and Unix HOWTO", Section 3.4 "Sockets and Network Connections" |date=22 August 2004 |website=dwheeler.com |publisher=David A. Wheeler |access-date=29 September 2014}}</ref>
 
==See also==
* {{Annotated link|Network socket}}
*[[Berkeley sockets]]
* {{Annotated link|Berkeley sockets}}
*[[ {{Annotated link|Pipeline (Unix)]]}}
* {{Annotated link|Netlink}}
 
==References==
{{Reflist}}
 
==External links==
* {{man|2sh|socketpairsocket|LinuxSUS||create a pair of connected socketssocket}}
* {{man|2sh|sendmsgsocketpair|LinuxSUS||sendcreate a messagepair onof aconnected socketsockets}}
* {{man|2sh|recvmsgsendmsg|LinuxSUS||receivesend a message fromon a socket}}
* {{man|sh|recvmsg|SUS||receive a message from a socket}}
* {{man|3|cmsg|Linux||socket ancillary data, including sending/receiving [[file descriptor]]s}}
* [httphttps://untroubled.org/ucspi-unix/ ucspi-unix], UNIX-___domain socket client-server command-line tools
* [httphttps://lists.freebsd.org/pipermail/freebsd-performance/2005-February/001143.html Unix sockets vs Internet sockets]
*[http://beej.us/guide/bgipc/output/html/multipage/unixsock.html unix ___domain sockets guide]
* [https://beej.us/guide/bgipc/html/multi/index.html Unix Sockets - Beej's Guide to Unix IPC]
*[http://www.thomasstover.com/uds.html another unix ___domain sockets guide]
*[http://lists.freebsd.org/pipermail/freebsd-performance/2005-February/001143.html Unix sockets vs Internet sockets]
*[http://code.google.com/p/junixsocket/ Unix Domain Sockets for Java]
 
[[Category:{{Inter-process communication]]}}
{{IPC}}
{{Use dmy dates|date=January 2019}}
 
[[Category:Network socket]]
[[Category:Unix]]
[[Category:Inter-process communication]]
 
 
{{compsci-stub}}
 
*[[fr:Berkeley sockets#Socket unix]]
[[de:POSIX local inter-process communication socket]]
[[es:Socket UNIX]]
[[it:Socket di dominio locale]]
[[ru:Unix ___domain socket]]
[[uk:Локальні сокети]]