* Unix Domain Sockets @ 2005-01-24 19:18 r_zaca 2005-01-24 19:32 ` Jan-Benedict Glaw 0 siblings, 1 reply; 3+ messages in thread From: r_zaca @ 2005-01-24 19:18 UTC (permalink / raw) To: linux-c-programming [-- Attachment #1: Mail message body --] [-- Type: text/plain, Size: 224 bytes --] Hello everybody, Does anyone know what a "unix domain socket" is, and how it differ from an "Internet domain socket"? If you know a nice site or documentation about this subject, please tell me. Thanks a lot. ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Unix Domain Sockets 2005-01-24 19:18 Unix Domain Sockets r_zaca @ 2005-01-24 19:32 ` Jan-Benedict Glaw 2005-01-30 11:35 ` Glynn Clements 0 siblings, 1 reply; 3+ messages in thread From: Jan-Benedict Glaw @ 2005-01-24 19:32 UTC (permalink / raw) To: linux-c-programming [-- Attachment #1: Type: text/plain, Size: 1455 bytes --] On Mon, 2005-01-24 17:18:03 -0200, r_zaca <r_zaca@ig.com.br> wrote in message <20050124_191803_058538.r_zaca@ig.com.br>: Content-Description: Mail message body > Hello everybody, > > Does anyone know what a "unix domain socket" is, and how it differ from an > "Internet domain socket"? Internet domain sockets work with IP addresses and port numbers. A unix socket merely is a special file on a local file system, a so calles "fifo". It's created with the "mkfifo" library call or userspace command. After you've created a fifo, which is displayed with a 'p' as the file-type at "ls -l" output, you can open/close/read/write it. > If you know a nice site or documentation about this subject, please tell > me. There's not much to tell about it. It's created once locally, then you can access it. Keep in mind that it's a purely local thing. You cannot export it by any means (I've seen people putting it on a shared NFS filesystem....). The data passed through the fifo is kept within the operating system's kernel; it's never ever written somewhere onto stable storage. MfG, JBG -- Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 _ O _ "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA)); [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Unix Domain Sockets 2005-01-24 19:32 ` Jan-Benedict Glaw @ 2005-01-30 11:35 ` Glynn Clements 0 siblings, 0 replies; 3+ messages in thread From: Glynn Clements @ 2005-01-30 11:35 UTC (permalink / raw) To: Jan-Benedict Glaw; +Cc: linux-c-programming, r_zaca Jan-Benedict Glaw wrote: > > Does anyone know what a "unix domain socket" is, and how it differ from an > > "Internet domain socket"? > > Internet domain sockets work with IP addresses and port numbers. A unix > socket merely is a special file on a local file system, a so calles > "fifo". It's created with the "mkfifo" library call or userspace > command. This is incorrect. A Unix-domain socket isn't quite the same thing as a pipe or FIFO. Differences include: 1. Unix-domain sockets are created and accessed using the BSD sockets API (socket(), bind(), accept(), connect() etc). You can't connect to one with open() (you can create one with mknod(), but there isn't much point, as there won't be a process listening on it). 2. Unix-domain sockets are bidirectional (i.e. you can use both read() and write() on a single descriptor), whereas pipes and FIFOs are uni-directional (i.e. one end is read-only and the other is write-only). To get back to the original question: a Unix-domain socket behaves similar to an internet-domain socket, but uses a different transport mechanism and different addressing scheme. Internet-domain sockets transfer data via TCP/IP-compatible network interfaces (e.g. ethernet, PPP etc). Unix-domain sockets are can only transfer data locally, i.e. between processes running on the same host; they cannot be used to transfer data between hosts. Internet-domain sockets are addressed using an IP address and a port number. Unix-domain sockets are addressed using a pathname. The most common example of a Unix-domain socket is connecting to a local X server via the sockets in the /tmp/.X11-unix directory. Each local display will normally have a corresponding socket in that directory; e.g. the display :0 can be accessed via the socket named "/tmp/.X11-unix/X0". From a programming perspective, the differences are: 1. You specify a value of PF_UNIX or PF_LOCAL (these two macros both have the same value) for the first argument (protocol) to the socket() function (rather than PF_INET for an internet-domain socket). 2. For functions which take a socket address (e.g. bind(), connect()) as an argument, the address is a "struct sockaddr_un" (rather than "struct sockaddr_in" for an internet-domain socket), and the sun_family field contains AF_UNIX or AF_LOCAL (rather than AF_INET for the sin_family field for an internet-domain socket). Other than that, you use the same functions as you would for internet-domain sockets. -- Glynn Clements <glynn@gclements.plus.com> ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-01-30 11:35 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2005-01-24 19:18 Unix Domain Sockets r_zaca 2005-01-24 19:32 ` Jan-Benedict Glaw 2005-01-30 11:35 ` Glynn Clements
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).