147273Smckusick.\" Copyright (c) 1991 The Regents of the University of California. 247273Smckusick.\" All rights reserved. 347273Smckusick.\" 447273Smckusick.\" %sccs.include.redist.man% 547273Smckusick.\" 6*47680Scael.\" @(#)unix.4 6.3 (Berkeley) 03/28/91 747273Smckusick.\" 8*47680Scael.Dd 9*47680Scael.Dt UNIX 4 10*47680Scael.Os 11*47680Scael.Sh NAME 12*47680Scael.Nm unix 13*47680Scael.Nd UNIX-domain protocol family 14*47680Scael.Sh SYNOPSIS 15*47680Scael.Fd #include <sys/types.h> 16*47680Scael.Fd #include <sys/un.h> 17*47680Scael.Sh DESCRIPTION 1847273SmckusickThe 19*47680Scael.Tn UNIX Ns -domain 20*47680Scaelprotocol family is a collection of protocols 2147273Smckusickthat provides local (on-machine) interprocess 2247273Smckusickcommunication through the normal 23*47680Scael.Xr socket 2 2447273Smckusickmechanisms. 2547273SmckusickThe 26*47680Scael.Tn UNIX Ns -domain 27*47680Scaelfamily supports the 28*47680Scael.Dv SOCK_STREAM 29*47680Scaeland 30*47680Scael.Dv SOCK_DGRAM 31*47680Scaelsocket types and uses 3247273Smckusickfilesystem pathnames for addressing. 33*47680Scael.Sh ADDRESSING 34*47680Scael.Tn UNIX Ns -domain 35*47680Scaeladdresses are variable-length filesystem pathnames of 3647273Smckusickat most 104 characters. 3747273SmckusickThe include file 38*47680Scael.Aq Pa sys/un.h 3947273Smckusickdefines this address: 40*47680Scael.Bd -literal -offset indent 4147273Smckusickstruct sockaddr_un { 42*47680Scaelu_char sun_len; 43*47680Scaelu_char sun_family; 44*47680Scaelchar sun_path[104]; 4547273Smckusick}; 46*47680Scael.Ed 47*47680Scael.Pp 4847273SmckusickBinding a name to a 49*47680Scael.Tn UNIX Ns -domain 50*47680Scaelsocket with 51*47680Scael.Xr bind 2 5247273Smckusickcauses a socket file to be created in the filesystem. 5347273SmckusickThis file is 54*47680Scael.Em not 5547273Smckusickremoved when the socket is closed\(em\c 56*47680Scael.Xr unlink 2 5747273Smckusickmust be used to remove the file. 58*47680Scael.Pp 5947273SmckusickThe 60*47680Scael.Tn UNIX Ns -domain 61*47680Scaelprotocol family does not support broadcast addressing or any form 62*47680Scaelof 63*47680Scael.Dq wildcard 64*47680Scaelmatching on incoming messages. 6547273SmckusickAll addresses are absolute- or relative-pathnames 6647273Smckusickof other 67*47680Scael.Tn UNIX Ns -domain 68*47680Scaelsockets. 6947273SmckusickNormal filesystem access-control mechanisms are also 7047273Smckusickapplied when referencing pathnames; e.g., the destination 7147273Smckusickof a 72*47680Scael.Xr connect 2 7347273Smckusickor 74*47680Scael.Xr sendto 2 7547273Smckusickmust be writable. 76*47680Scael.Sh PROTOCOLS 7747273SmckusickThe 78*47680Scael.Tn UNIX Ns -domain 79*47680Scaelprotocol family is comprised of simple 8047273Smckusicktransport protocols that support the 81*47680Scael.Dv SOCK_STREAM 8247273Smckusickand 83*47680Scael.Dv SOCK_DGRAM 8447273Smckusickabstractions. 85*47680Scael.Dv SOCK_STREAM 8647273Smckusicksockets also support the communication of 87*47680Scael.Ux 8847273Smckusickfile descriptors through the use of the 89*47680Scael.Ar msg_control 9047273Smckusickfield in the 91*47680Scael.Ar msg 9247273Smckusickargument to 93*47680Scael.Xr sendmsg 2 9447273Smckusickand 95*47680Scael.Xr recvmsg 2 . 96*47680Scael.Pp 9747273SmckusickAny valid descriptor may be sent in a message. 9847275SmckusickThe file descriptor(s) to be passed are described using a 99*47680Scael.Ar struct cmsghdr 10047275Smckusickthat is defined in the include file 101*47680Scael.Aq Pa sys/socket.h . 10247275SmckusickThe type of the message is 103*47680Scael.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. 110*47680Scael.Pp 11147273SmckusickThe received descriptor is a 112*47680Scael.Em duplicate 11347273Smckusickof the sender's descriptor, as if it were created with a call to 114*47680Scael.Xr dup 2 . 11547273SmckusickPer-process descriptor flags, set with 116*47680Scael.Xr fcntl 2 , 11747273Smckusickare 118*47680Scael.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. 123*47680Scael.Sh SEE ALSO 124*47680Scael.Xr socket 2 , 125*47680Scael.Xr intro 4 126*47680Scael.Rs 127*47680Scael.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial" 128*47680Scael.%B PS1 129*47680Scael.%N 7 130*47680Scael.Re 131*47680Scael.Rs 132*47680Scael.%T "An Advanced 4.3 BSD Interprocess Communication Tutorial" 133*47680Scael.%B PS1 134*47680Scael.%N 8 135*47680Scael.Re 136*47680Scael.Sh HISTORY 137*47680ScaelThe 138*47680Scael.Tn UNIX Ns -domain 139*47680Scaelprotocol manual 140*47680Scael.Ud 141