Back to index

glibc  2.9
getpeername.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.


int __getpeername (int fd, __SOCKADDR_ARG addrarg, socklen_t *len)

Function Documentation

int __getpeername ( int  fd,
__SOCKADDR_ARG  addrarg,
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));
       addr->sa_family = family;

  return 0;

Here is the call graph for this function:

Here is the caller graph for this function: