Back to index

glibc  2.9
Defines | Functions | Variables
socket.h File Reference
#include <socket/sys/socket.h>

Go to the source code of this file.

Defines

#define SA_LEN(_x)   INTUSE(__libc_sa_len)((_x)->sa_family)
#define __connect(fd, addr, len)   INTUSE(__connect) (fd, addr, len)

Functions

int __socket (int __domain, int __type, int __protocol) attribute_hidden
int __socketpair (int __domain, int __type, int __protocol, int __fds[2]) attribute_hidden
int __opensock (void) internal_function attribute_hidden
int __getpeername (int __fd, __SOCKADDR_ARG __addr, socklen_t *__len) attribute_hidden
ssize_t __libc_send (int __fd, __const void *__buf, size_t __n, int __flags)
ssize_t __send (int __fd, __const void *__buf, size_t __n, int __flags)
 libc_hidden_proto (__send) extern ssize_t __libc_recv(int __fd
ssize_t __libc_sendto (int __fd, __const void *__buf, size_t __n, int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len)
ssize_t __libc_recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags, __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len)
int __libc_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
int __connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
int __connect_internal (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len) attribute_hidden
ssize_t __recv (int __fd, void *__buf, size_t __n, int __flags) attribute_hidden
ssize_t __sendto (int __fd, __const void *__buf, size_t __n, int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len) attribute_hidden
ssize_t __recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags, __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len) attribute_hidden
ssize_t __libc_sendmsg (int __fd, __const struct msghdr *__message, int __flags)
ssize_t __sendmsg (int __fd, __const struct msghdr *__message, int __flags) attribute_hidden
ssize_t __libc_recvmsg (int __fd, struct msghdr *__message, int __flags)
ssize_t __recvmsg (int __fd, struct msghdr *__message, int __flags) attribute_hidden
int __setsockopt (int __fd, int __level, int __optname, __const void *__optval, socklen_t __optlen) attribute_hidden
int __getsockopt (int __fd, int __level, int __optname, void *__restrict __optval, socklen_t *__restrict __optlen) attribute_hidden
int __getsockname (int __fd, __SOCKADDR_ARG __addr, socklen_t *__restrict __len) attribute_hidden
int __bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len) attribute_hidden
int __listen (int __fd, int __n) attribute_hidden
int __libc_accept (int __fd, __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len) __THROW
 libc_hidden_proto (accept) extern int __libc_sa_len(sa_family_t __af)
int __libc_sa_len_internal (sa_family_t __af) attribute_hidden

Variables

void * __buf
void size_t __n
void size_t int __flags

Define Documentation

#define __connect (   fd,
  addr,
  len 
)    INTUSE(__connect) (fd, addr, len)

Definition at line 153 of file socket.h.

#define SA_LEN (   _x)    INTUSE(__libc_sa_len)((_x)->sa_family)

Definition at line 145 of file socket.h.


Function Documentation

int __bind ( int  __fd,
__CONST_SOCKADDR_ARG  __addr,
socklen_t  __len 
)

Definition at line 24 of file bind.c.

{
  __set_errno (ENOSYS);
  return -1;
}

Here is the call graph for this function:

int __connect ( int  __fd,
__CONST_SOCKADDR_ARG  __addr,
socklen_t  __len 
)

Definition at line 7 of file connect.c.

{
  return connect (fd, addr, len);
}

Here is the call graph for this function:

int __connect_internal ( int  __fd,
__CONST_SOCKADDR_ARG  __addr,
socklen_t  __len 
)
int __getpeername ( int  __fd,
__SOCKADDR_ARG  __addr,
socklen_t __len 
)

Definition at line 30 of file getpeername.c.

{
  error_t err;
  mach_msg_type_number_t buflen = *len;
  int type;
  struct sockaddr *addr = addrarg.__sockaddr__;
  char *buf = (char *) addr;
  addr_port_t aport;

  if (err = HURD_DPORT_USE (fd, __socket_peername (port, &aport)))
    return __hurd_dfail (fd, err);

  err = __socket_whatis_address (aport, &type, &buf, &buflen);
  __mach_port_deallocate (__mach_task_self (), aport);

  if (err)
    return __hurd_dfail (fd, err);

  if (*len > buflen)
    *len = buflen;

  if (buf != (char *) addr)
    {
      memcpy (addr, buf, *len);
      __vm_deallocate (__mach_task_self (), (vm_address_t) buf, buflen);
    }

  const sa_family_t family = type;
  if (*len > offsetof (struct sockaddr, sa_family))
    {
      if (*len < (char *) (&addr->sa_family + 1) - (char *) addr)
       memcpy (&addr->sa_family, &family,
              *len - offsetof (struct sockaddr, sa_family));
      else
       addr->sa_family = family;
    }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __getsockname ( int  __fd,
__SOCKADDR_ARG  __addr,
socklen_t *__restrict  __len 
)
int __getsockopt ( int  __fd,
int  __level,
int  __optname,
void *__restrict  __optval,
socklen_t *__restrict  __optlen 
)

Here is the caller graph for this function:

int __libc_accept ( int  __fd,
__SOCKADDR_ARG  __addr,
socklen_t *__restrict  __addr_len 
)
int __libc_connect ( int  __fd,
__CONST_SOCKADDR_ARG  __addr,
socklen_t  __len 
)
ssize_t __libc_recvfrom ( int  __fd,
void *__restrict  __buf,
size_t  __n,
int  __flags,
__SOCKADDR_ARG  __addr,
socklen_t *__restrict  __addr_len 
)
ssize_t __libc_recvmsg ( int  __fd,
struct msghdr __message,
int  __flags 
)

Definition at line 30 of file recvmsg.c.

{
  error_t err;
  addr_port_t aport;
  char *data = NULL;
  mach_msg_type_number_t len = 0;
  mach_port_t *ports;
  mach_msg_type_number_t nports = 0;
  char *cdata = NULL;
  mach_msg_type_number_t clen = 0;
  size_t amount;
  char *buf;
  int i;

  /* Find the total number of bytes to be read.  */
  amount = 0;
  for (i = 0; i < message->msg_iovlen; i++)
    {
      amount += message->msg_iov[i].iov_len;

      /* As an optimization, we set the initial values of DATA and LEN
         from the first non-empty iovec.  This kicks-in in the case
         where the whole packet fits into that iovec buffer.  */
      if (data == NULL && message->msg_iov[i].iov_len > 0)
       {
         data = message->msg_iov[i].iov_base;
         len = message->msg_iov[i].iov_len;
       }
    }

  buf = data;
  if (err = HURD_DPORT_USE (fd, __socket_recv (port, &aport,
                                          flags, &data, &len,
                                          &ports, &nports,
                                          &cdata, &clen,
                                          &message->msg_flags, amount)))
    return __hurd_sockfail (fd, flags, err);

  if (message->msg_name != NULL)
    {
      char *buf = message->msg_name;
      mach_msg_type_number_t buflen = message->msg_namelen;
      int type;

      err = __socket_whatis_address (aport, &type, &buf, &buflen);
      if (err == EOPNOTSUPP)
       /* If the protocol server can't tell us the address, just return a
          zero-length one.  */
       {
         buf = message->msg_name;
         buflen = 0;
         err = 0;
       }

      if (err)
       {
         __mach_port_deallocate (__mach_task_self (), aport);
         return __hurd_sockfail (fd, flags, err);
       }

      if (message->msg_namelen > buflen)
       message->msg_namelen = buflen;

      if (buf != message->msg_name)
       {
         memcpy (message->msg_name, buf, message->msg_namelen);
         __vm_deallocate (__mach_task_self (), (vm_address_t) buf, buflen);
       }

      if (buflen > 0)
       ((struct sockaddr *) message->msg_name)->sa_family = type;
    }

  __mach_port_deallocate (__mach_task_self (), aport);

  if (buf == data)
    buf += len;
  else
    {
      /* Copy the data into MSG.  */
      if (len > amount)
       message->msg_flags |= MSG_TRUNC;
      else
       amount = len;

      buf = data;
      for (i = 0; i < message->msg_iovlen; i++)
       {
#define min(a, b)    ((a) > (b) ? (b) : (a))
         size_t copy = min (message->msg_iov[i].iov_len, amount);

         memcpy (message->msg_iov[i].iov_base, buf, copy);

         buf += copy;
         amount -= copy;
         if (len == 0)
           break;
       }

      __vm_deallocate (__mach_task_self (), (vm_address_t) data, len);
    }

  /* Copy the control message into MSG.  */
  if (clen > message->msg_controllen)
    message->msg_flags |= MSG_CTRUNC;
  else
    message->msg_controllen = clen;
  memcpy (message->msg_control, cdata, message->msg_controllen);

  __vm_deallocate (__mach_task_self (), (vm_address_t) cdata, clen);

  return (buf - data);
}

Here is the call graph for this function:

ssize_t __libc_send ( int  __fd,
__const void *  __buf,
size_t  __n,
int  __flags 
)
ssize_t __libc_sendmsg ( int  __fd,
__const struct msghdr __message,
int  __flags 
)
ssize_t __libc_sendto ( int  __fd,
__const void *  __buf,
size_t  __n,
int  __flags,
__CONST_SOCKADDR_ARG  __addr,
socklen_t  __addr_len 
)
int __listen ( int  __fd,
int  __n 
)

Definition at line 26 of file listen.c.

{
  __set_errno (ENOSYS);
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __opensock ( void  )

Definition at line 26 of file opensock.c.

{
  /* Cache the last AF that worked, to avoid many redundant calls to
     socket().  */
  static int sock_af = -1;
  int fd = -1;
  __libc_lock_define_initialized (static, lock);

  if (sock_af != -1)
    {
      fd = __socket (sock_af, SOCK_DGRAM, 0);
      if (fd != -1)
        return fd;
    }

  __libc_lock_lock (lock);

  if (sock_af != -1)
    fd = __socket (sock_af, SOCK_DGRAM, 0);

  if (fd == -1)
    {
#ifdef AF_INET
      fd = __socket (sock_af = AF_INET, SOCK_DGRAM, 0);
#endif
#ifdef AF_INET6
      if (fd < 0)
       fd = __socket (sock_af = AF_INET6, SOCK_DGRAM, 0);
#endif
#ifdef AF_IPX
      if (fd < 0)
       fd = __socket (sock_af = AF_IPX, SOCK_DGRAM, 0);
#endif
#ifdef AF_AX25
      if (fd < 0)
       fd = __socket (sock_af = AF_AX25, SOCK_DGRAM, 0);
#endif
#ifdef AF_APPLETALK
      if (fd < 0)
       fd = __socket (sock_af = AF_APPLETALK, SOCK_DGRAM, 0);
#endif
    }

  __libc_lock_unlock (lock);
  return fd;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t __recv ( int  __fd,
void *  __buf,
size_t  __n,
int  __flags 
)

Definition at line 25 of file recv.c.

{
  return recv (fd, buf, n, flags);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t __recvfrom ( int  __fd,
void *__restrict  __buf,
size_t  __n,
int  __flags,
__SOCKADDR_ARG  __addr,
socklen_t *__restrict  __addr_len 
)

Here is the caller graph for this function:

ssize_t __recvmsg ( int  __fd,
struct msghdr __message,
int  __flags 
)

Definition at line 24 of file recvmsg.c.

{
  return nrecvmsg (fd, message, flags);
}

Here is the call graph for this function:

ssize_t __send ( int  __fd,
__const void *  __buf,
size_t  __n,
int  __flags 
)

Here is the caller graph for this function:

ssize_t __sendmsg ( int  __fd,
__const struct msghdr __message,
int  __flags 
)

Here is the caller graph for this function:

ssize_t __sendto ( int  __fd,
__const void *  __buf,
size_t  __n,
int  __flags,
__CONST_SOCKADDR_ARG  __addr,
socklen_t  __addr_len 
)
int __setsockopt ( int  __fd,
int  __level,
int  __optname,
__const void *  __optval,
socklen_t  __optlen 
)

Here is the caller graph for this function:

int __socket ( int  __domain,
int  __type,
int  __protocol 
)

Definition at line 22 of file socket.c.

{
  return socket (domain, type, protocol);
}

Here is the call graph for this function:

int __socketpair ( int  __domain,
int  __type,
int  __protocol,
int  __fds[2] 
)

Definition at line 22 of file socketpair.c.

{
  return socketpair (domain, type, protocol, fds);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

void* __buf

Definition at line 36 of file socket.h.

Definition at line 36 of file socket.h.

Definition at line 36 of file socket.h.