Beispiel #1
0
int Socket::getLocalAddr (InetAddr &sa)
{
  int len = sa.getSize ();
  sockaddr *addr = reinterpret_cast<sockaddr *> (sa.getAddr ());

  if (OS::getsockname (this->getHandle (), addr, &len) == -1)
    return -1;

  sa.setType (addr->sa_family);
  sa.setSize (len);
  return 0;
}
Beispiel #2
0
ssize_t
SocketDgram::recv (void *buf,
              size_t n,
              InetAddr &addr,
              int flags) const {
  sockaddr* saddr = (sockaddr*)addr.getAddr();
  int addrlen = addr.getSize();

  ssize_t const status = OS::recvfrom(this->getHandle(),
                                      (char*)buf,
                                      n,
                                      flags,
                                      (sockaddr*)saddr,
                                      &addrlen);
  addr.setSize(addrlen);
  addr.setType(saddr->sa_family);
  return status;
}