1*63012Sbostic.\" Copyright (c) 1991, 1993 2*63012Sbostic.\" The Regents of the University of California. All rights reserved. 347273Smckusick.\" 447273Smckusick.\" %sccs.include.redist.man% 547273Smckusick.\" 6*63012Sbostic.\" @(#)unix.4 8.1 (Berkeley) 06/09/93 747273Smckusick.\" 847680Scael.Dd 947680Scael.Dt UNIX 4 1047680Scael.Os 1147680Scael.Sh NAME 1247680Scael.Nm unix 1347680Scael.Nd UNIX-domain protocol family 1447680Scael.Sh SYNOPSIS 1547680Scael.Fd #include <sys/types.h> 1647680Scael.Fd #include <sys/un.h> 1747680Scael.Sh DESCRIPTION 1847273SmckusickThe 1947680Scael.Tn UNIX Ns -domain 2047680Scaelprotocol family is a collection of protocols 2147273Smckusickthat provides local (on-machine) interprocess 2247273Smckusickcommunication through the normal 2347680Scael.Xr socket 2 2447273Smckusickmechanisms. 2547273SmckusickThe 2647680Scael.Tn UNIX Ns -domain 2747680Scaelfamily supports the 2847680Scael.Dv SOCK_STREAM 2947680Scaeland 3047680Scael.Dv SOCK_DGRAM 3147680Scaelsocket types and uses 3247273Smckusickfilesystem pathnames for addressing. 3347680Scael.Sh ADDRESSING 3447680Scael.Tn UNIX Ns -domain 3547680Scaeladdresses are variable-length filesystem pathnames of 3647273Smckusickat most 104 characters. 3747273SmckusickThe include file 3847680Scael.Aq Pa sys/un.h 3947273Smckusickdefines this address: 4047680Scael.Bd -literal -offset indent 4147273Smckusickstruct sockaddr_un { 4247680Scaelu_char sun_len; 4347680Scaelu_char sun_family; 4447680Scaelchar sun_path[104]; 4547273Smckusick}; 4647680Scael.Ed 4747680Scael.Pp 4847273SmckusickBinding a name to a 4947680Scael.Tn UNIX Ns -domain 5047680Scaelsocket with 5147680Scael.Xr bind 2 5247273Smckusickcauses a socket file to be created in the filesystem. 5347273SmckusickThis file is 5447680Scael.Em not 5547273Smckusickremoved when the socket is closed\(em\c 5647680Scael.Xr unlink 2 5747273Smckusickmust be used to remove the file. 5847680Scael.Pp 5947273SmckusickThe 6047680Scael.Tn UNIX Ns -domain 6147680Scaelprotocol family does not support broadcast addressing or any form 6247680Scaelof 6347680Scael.Dq wildcard 6447680Scaelmatching on incoming messages. 6547273SmckusickAll addresses are absolute- or relative-pathnames 6647273Smckusickof other 6747680Scael.Tn UNIX Ns -domain 6847680Scaelsockets. 6947273SmckusickNormal filesystem access-control mechanisms are also 7047273Smckusickapplied when referencing pathnames; e.g., the destination 7147273Smckusickof a 7247680Scael.Xr connect 2 7347273Smckusickor 7447680Scael.Xr sendto 2 7547273Smckusickmust be writable. 7647680Scael.Sh PROTOCOLS 7747273SmckusickThe 7847680Scael.Tn UNIX Ns -domain 7947680Scaelprotocol family is comprised of simple 8047273Smckusicktransport protocols that support the 8147680Scael.Dv SOCK_STREAM 8247273Smckusickand 8347680Scael.Dv SOCK_DGRAM 8447273Smckusickabstractions. 8547680Scael.Dv SOCK_STREAM 8647273Smckusicksockets also support the communication of 8747680Scael.Ux 8847273Smckusickfile descriptors through the use of the 8947680Scael.Ar msg_control 9047273Smckusickfield in the 9147680Scael.Ar msg 9247273Smckusickargument to 9347680Scael.Xr sendmsg 2 9447273Smckusickand 9547680Scael.Xr recvmsg 2 . 9647680Scael.Pp 9747273SmckusickAny valid descriptor may be sent in a message. 9847275SmckusickThe file descriptor(s) to be passed are described using a 9947680Scael.Ar struct cmsghdr 10047275Smckusickthat is defined in the include file 10147680Scael.Aq Pa sys/socket.h . 10247275SmckusickThe type of the message is 10347680Scael.Dv SCM_RIGHTS , 10447275Smckusickand the data portion of the messages is an array of integers 10547275Smckusickrepresenting the file descriptors to be passed. 10647275SmckusickThe number of descriptors being passed is defined 10747275Smckusickby the length field of the message; 10847275Smckusickthe length field is the sum of the size of the header 10947275Smckusickplus the size of the array of file descriptors. 11047680Scael.Pp 11147273SmckusickThe received descriptor is a 11247680Scael.Em duplicate 11347273Smckusickof the sender's descriptor, as if it were created with a call to 11447680Scael.Xr dup 2 . 11547273SmckusickPer-process descriptor flags, set with 11647680Scael.Xr fcntl 2 , 11747273Smckusickare 11847680Scael.Em not 11947273Smckusickpassed to a receiver. 12047273SmckusickDescriptors that are awaiting delivery, or that are 12147273Smckusickpurposely not received, are automatically closed by the system 12247273Smckusickwhen the destination socket is closed. 12347680Scael.Sh SEE ALSO 12447680Scael.Xr socket 2 , 12547680Scael.Xr intro 4 12647680Scael.Rs 12747680Scael.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial" 12847680Scael.%B PS1 12947680Scael.%N 7 13047680Scael.Re 13147680Scael.Rs 13247680Scael.%T "An Advanced 4.3 BSD Interprocess Communication Tutorial" 13347680Scael.%B PS1 13447680Scael.%N 8 13547680Scael.Re 136