Back to index

glibc  2.9
recvfrom.c File Reference
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <hurd.h>
#include <hurd/fd.h>
#include <hurd/socket.h>

Go to the source code of this file.


ssize_t __recvfrom (int fd, void *buf, size_t n, int flags, __SOCKADDR_ARG addrarg, socklen_t *addr_len)

Function Documentation

ssize_t __recvfrom ( int  fd,
void *  buf,
size_t  n,
int  flags,
__SOCKADDR_ARG  addrarg,
socklen_t addr_len 

Definition at line 31 of file recvfrom.c.

  error_t err;
  mach_port_t addrport;
  char *bufp = buf;
  mach_msg_type_number_t nread = n;
  mach_port_t *ports;
  mach_msg_type_number_t nports = 0;
  char *cdata = NULL;
  mach_msg_type_number_t clen = 0;
  struct sockaddr *addr = addrarg.__sockaddr__;

  if (err = HURD_DPORT_USE (fd, __socket_recv (port, &addrport,
                                          flags, &bufp, &nread,
                                          &ports, &nports,
                                          &cdata, &clen,
    return __hurd_sockfail (fd, flags, err);

  /* Get address data for the returned address port if requested.  */
  if (addr != NULL)
      char *buf = (char *) addr;
      mach_msg_type_number_t buflen = *addr_len;
      int type;

      err = __socket_whatis_address (addrport, &type, &buf, &buflen);
      if (err == EOPNOTSUPP)
       /* If the protocol server can't tell us the address, just return a
          zero-length one.  */
         buf = (char *)addr;
         buflen = 0;
         err = 0;

      if (err)
         __mach_port_deallocate (__mach_task_self (), addrport);
         return __hurd_sockfail (fd, flags, err);
      if (*addr_len > buflen)
       *addr_len = buflen;

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

      if (buflen > 0)
       addr->sa_family = type;

  __mach_port_deallocate (__mach_task_self (), addrport);

  /* Toss control data; we don't care.  */
  __vm_deallocate (__mach_task_self (), (vm_address_t) cdata, clen);

  if (bufp != buf)
      memcpy (buf, bufp, nread);
      __vm_deallocate (__mach_task_self (), (vm_address_t) bufp, nread);

  return nread;

Here is the call graph for this function: