Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
Cactus

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Glossary
MoreInfo
Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
FAQ
Copyright Info
Terms of Use
Privacy Info
Disclaimer
WorkBoard
Thanks
Donations
Advertising
Masthead / Impressum
Your Account

Communication
Feedback
Forums
Private Messages
Surveys

Features
HOWTOs
News Archive
Submit News
Topics
User Articles
Web Links

Google
Google


The Web
linux-tutorial.info

Who's Online
There are currently, 311 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

  

unix




SYNOPSIS

       #include <sys/socket.h>
       #include <sys/un.h>

       unix_socket = socket(PF_UNIX, type, 0);
       error = socketpair(PF_UNIX, type, 0, int *sv);


DESCRIPTION

       The PF_UNIX (also known as PF_LOCAL) socket family is used
       to communicate between processes on the same machine effi­
       ciently. Unix sockets can be either anonymous (created  by
       socketpair(2))  or  associated with a file of type socket.
       Linux also supports an abstract namespace which  is  inde­
       pendent of the file system.

       Valid  types  are SOCK_STREAM for a stream oriented socket
       and SOCK_DGRAM for a datagram oriented  socket  that  pre­
       serves  message  boundaries. Unix sockets are always reli­
       able and don't reorder datagrams.

       Unix sockets support passing file descriptors  or  process
       credentials to other processes using ancillary data.


ADDRESS FORMAT

       A  unix address is defined as a filename in the filesystem
       or as a unique string in the abstract  namespace.  Sockets
       created  by socketpair(2) are anonymous. For non-anonymous
       sockets the target address can be  set  using  connect(2).
       The local address can be set using bind(2).  When a socket
       is connected and it doesn't already have a local address a
       unique address in the abstract namespace will be generated
       automatically.

              #define UNIX_PATH_MAX    108

              struct sockaddr_un {
                  sa_family_t  sun_family;              /* AF_UNIX */
                  char         sun_path[UNIX_PATH_MAX]; /* pathname */
              };

       sun_family always contains AF_UNIX.  sun_path contains the
       zero-terminated pathname of the socket in the file system.
       If sun_path starts with a  zero  byte  it  refers  to  the
       abstract namespace maintained by the Unix protocol module.
       The socket's address in this namespace  is  given  by  the
       rest  of  the  bytes  in sun_path.  Note that names in the
       abstract namespace are not zero-terminated.



ANCILLARY MESSAGES

       Ancillary data is sent and received using  sendmsg(2)  and
       recvmsg(2).   For historical reasons the ancillary message
       types listed below are specified with  a  SOL_SOCKET  type
       even  though  they are PF_UNIX specific.  To send them set
       the cmsg_level field of the struct cmsghdr  to  SOL_SOCKET
       and  the cmsg_type field to the type. For more information
       see cmsg(3).

       SCM_RIGHTS
              Send or receive a set of open file descriptors from
              another  process.   The  data  portion  contains an
              integer array of the file descriptors.  The  passed
              file  descriptors  behave  as though they have been
              created with dup(2).

       SCM_CREDENTIALS
              Send or receive unix credentials.  This can be used
              for  authentication.  The credentials are passed as
              a struct ucred ancillary message.

              struct ucred {
                  pid_t  pid;  /* process id of the sending process */
                  uid_t  uid;  /* user id of the sending process */
                  gid_t  gid;  /* group id of the sending process */
              };

       The credentials which the sender specifies are checked  by
       the kernel.  A process with effective user ID 0 is allowed
       to specify values that do not match his own.   The  sender
       must  specify  its own process ID (unless it has the capa­
       bility CAP_SYS_ADMIN), its user ID, effective user  ID  or
       set  user ID (unless it has CAP_SETUID), and its group id,
       effective group ID or set group ID (unless it has CAP_SET­
       GID).   To  receive a struct ucred message the SO_PASSCRED
       option must be enabled on the socket.


VERSIONS

       SCM_CREDENTIALS and the abstract namespace were introduced
       with  Linux  2.2  and  should not be used in portable pro­
       grams.  (Some BSD-derived systems also support  credential
       passing, but the implementation details differ.)


NOTES

       In  the Linux implementation, sockets which are visible in
       the filesystem honour the  permissions  of  the  directory
       they  are in. Their owner, group and their permissions can

       To  pass  file  descriptors  or  credentials  you  need to
       send/read at least one byte of data.

       Unix domain stream sockets do not support  the  notion  of
       out-of-band data.


ERRORS

       ENOMEM Out of memory.

       ECONNREFUSED
              connect(2)  called  with a socket object that isn't
              listening. This can happen when the  remote  socket
              does not exist or the filename is not a socket.

       EINVAL Invalid  argument  passed.  A  common  cause is the
              missing setting of AF_UNIX in the sun_type field of
              passed  addresses or the socket being in an invalid
              state for the applied operation.

       EOPNOTSUPP
              Stream  operation  called  on  non-stream  oriented
              socket or tried to use the out-of-band data option.

       EPROTONOSUPPORT
              Passed protocol is not PF_UNIX.

       ESOCKTNOSUPPORT
              Unknown socket type.

       EPROTOTYPE
              Remote socket does not match the local socket  type
              (SOCK_DGRAM vs.  SOCK_STREAM)

       EADDRINUSE
              Selected local address is already taken or filesys­
              tem socket object already exists.

       EISCONN
              connect(2) called on an already connected socket or
              a  target  address  was  specified  on  a connected
              socket.

       ENOTCONN
              Socket operation needs a target  address,  but  the
              socket is not connected.

       ECONNRESET
              Remote socket was unexpectedly closed.

       EPIPE  Remote  socket  was  closed  on a stream socket. If
              enabled, a SIGPIPE is sent as  well.  This  can  be

       recvmsg(2), sendmsg(2), socket(2), socketpair(2), cmsg(3),
       capabilities(7), socket(7)

Linux Man Page              2002-12-02                    UNIX(7)
  




Login
Nickname

Password

Security Code
Security Code
Type Security Code


Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!


Amazon Wish List

Did You Know?
The Linux Tutorial welcomes your suggestions and ideas.


Friends



Tell a Friend About Us

Bookmark and Share



Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.04 Seconds