Provided by: manpages-zh_1.5.2-1_all bug

NAME

       socket - Linux

       #include <sys/socket.h>
       mysocket = socket(int socket_family, int socket_type, int protocol);

         Linux  .   BSD  ,    ,  PF_INET,  PF_IPX,  PF_PACKET    , SOCK_STREAM
       SOCK_DGRAM.  socket(2).

       , .  .

       socket(2)

       connect(2)

       bind(2)

       listen(2)

       accept(2)

       socketpair(2) , PF_UNIX

       send(2),

       sendto(2), sendmsg(2) recv(2), recvfrom(2), recvmsg(2) .  poll(2)

       select(2) . ,  I/O write(2), writev(2), sendfile(2), read(2),  readv(2)
       .

       getsockname(2)

       getpeername(2) .  getsockopt(2) setsockopt(2) .  ioctl(2) .

       close(2) .  shutdown(2) .

        pread(2) pwrite(2)  0 .  fcntl(2).  O_NONBLOCK  I/O O_NONBLOCK  accept
       EAGAIN.  connect(2) EINPROGRESS .  poll(2) select(2) .

       +----------------------------+
       |           I/O              |
       +--+---------+---------------+
       |  |         |               |
       +--+---------+---------------+
       |  | POLLIN  | .             |
       +--+---------+---------------+
       |  | POLLIN  | ()            |
       +--+---------+---------------+
       |  | POLLHUP | .             |
       +--+---------+---------------+
       |  | POLLHUP | ().  SIGPIPE. |
       +--+---------+---------------+
       |  | POLLOUT | .             |
       +--+---------+---------------+
       |/ | POLLIN| |  connect(2) . |
       |  | POLLOUT |               |
       +--+---------+---------------+
       |/ | POLLERR | .             |
       +--+---------+---------------+
       |/ | POLLHUP | .             |
       +--+---------+---------------+
       |  | POLLPRI | .  SIGURG.    |
       +--+---------+---------------+

        poll/select SIGIO .  fcntl(2) FASYNC sigaction(2).  SIGIO .  SIGNALS .

        setsockopt(2) getsockopt(2) SOL_SOCKET :

       SO_KEEPALIVE
               keep-alive ..

       SO_OOBINLINE
              Out-of-Band MSG_OOB , .

       SO_RCVLOWAT  SO_SNDLOWAT
               (SO_SNDLOWAT) (SO_RCVLOWAT).  .  Linux ,   1  .   getsockopt  ;
              setsockopt ENOPROTOOPT.

       SO_RCVTIMEO  SO_SNDTIMEO
              , .  Linux , .  alarm(2) setitimer(2).  .

       SO_BSDCOMPAT
                BSD   bug-to-bug  .   UDP  .  ,  UDP   ICMP  .  Linux 2.0  BSD
              bug-to-bug ,, Linux 2.2 . .

       SO_PASSCRED
               SCM_CREDENTIALS .  unix(7).

       SO_PEERCRED
              .  PF_UNIX .  unix(7).  ucred .  getsockopt.  .

       SO_BINDTODEVICE
              , "eth0", .  0, .  , IFNAMSIZ.  , .

       SO_DEBUG
              .  CAP_NET_ADMIN  0 .

       SO_REUSEADDR
               bind(2) .  PF_INET , , .  INADDR_ANY , .

       SO_TYPE
               SOCK_STREAM getsockopt .

       SO_DONTROUTE
              , .  send(2) MSG_DONTROUTE . .

       SO_BROADCAST
              . , , .  .

       SO_SNDBUF
              .  wmem_default sysctl , wmem_max sysctl .

       SO_RCVBUF
               rmem_default sysctl, rmem_max sysctl .

       SO_LINGER
               SO_LINGER .  linger .

              struct linger {
                  int   l_onoff;    /* / */
                  int   l_linger;   /*  */
              };

              , close(2) shutdown(2) . , .  closing .  exit(2), , .

       SO_PRIORITY
              .  Linux : , .  ip(7),  IP TOS.

       SO_ERROR
              .  getsockopt.  . .

SIGNALS

       , SIGPIPE EPIPE MSG_NOSIGNAL , .

        FIOCSETOWN fcntl  SIOCSPGRP  ioctl   I/O  SIGIO  poll(2)  select(2)  .
       Linux 2.2 F_SETSIG fcntl : siginfo_t si_fd .  fcntl(2)

       :, SIGIO .  , ,  Linux .

SYSCTLS

        /proc/sys/net/core/* sysctl(2) sysctl.

       rmem_default
              .

       rmem_max
              , SO_RCVBUF .

       wmem_default
              .

       wmem_max
               SO_SNDBUF .

       message_cost  message_burst
              , .

       netdev_max_backlog
              .

       optmem_max
               iovecs .

IOCTLS

        IO ioctl(2) :

              error = ioctl(ip_socket, ioctl_type, &value_result);

       SIOCGSTAMP
               timeval  RTT round trip time .  struct timeval.  setitimer(2)

       SIOCSPGRP
               IO SIGIO SIGURG , pid_t.   id CAP_KILL  UID  0, .

       FIOASYNC
               O_ASYNC  IO IO  I/O SIGIO F_SETSIG .

              .

       SIOCGPGRP
               SIGIO SIGURG , ,  0.

        fcntl:

       FIOCGETOWN
               IO  SIOCGPGRP .

       FIOCSETOWN
               IO  SIOCSPGRP .

       Linux /, , .

       CONFIG_FILTER SO_ATTACH_FILTER SO_DETACH_FILTER .  libpcap

VERSIONS

       SO_BINDTODEVICE   Linux  2.0.30  .   SO_PASSCRED   Linux  2.2 .  sysctl
       Linux 2.2.

        Andi Kleen .

       socket(2), ip(7), setsockopt(2), getsockopt(2), packet(7), ddp(7)

[]

       liguoping <liguoping_11@sina.com>

[]

       2000/11/06

linuxman:

       http://cmpp.linuxforum.net