Ejemplo n.º 1
0
IPV6Host Socket::getIPV6Peer(in_port_t *port) const
{
    sockaddr_in6* from = getPeer();
    if (from == NULL) {
        if (port)
            *port = 0;
        return IPV6Host(in6addr_any);
    }

    if (port)
        *port = ntohs(from->sin6_port);
    return IPV6Host(from->sin6_addr);
}
Ejemplo n.º 2
0
IPV6Host Socket::getIPV6Sender(in_port_t *port) const
{
    ucommon::Socket::address addr = getSender();
    sockaddr_in6* from = addr;
    if (from == NULL) {
        if (port)
            *port = 0;
        return IPV6Host(in6addr_any);
    }

    if (port)
        *port = ntohs(from->sin6_port);
    return IPV6Host(from->sin6_addr);
}
Ejemplo n.º 3
0
IPV6Host UDPSocket::getIPV6Peer(tpport_t *port)
{
    ucommon::Socket::address addr = getPeer();
    if (addr) {
        if(port)
            *port = peer.getPort();
    } else {
        peer.setAny();
        if(port)
            *port = 0;
    }

    return IPV6Host(ucommon::Socket::address::ipv6(addr)->sin6_addr);
}
Ejemplo n.º 4
0
void TCPStream::connect(const char *target, unsigned mss)
{
    char namebuf[128];
    char *cp;
    struct servent *svc;
    tpport_t port;

    snprintf(namebuf, sizeof(namebuf), "%s", target);
    cp = strrchr(namebuf, '/');
    if(!cp)
        cp = strrchr(namebuf, ':');

    if(!cp) {
        endStream();
        connectError();
        return;
    }

    *(cp++) = 0;

    if(isdigit(*cp))
        port = atoi(cp);
    else {
        mutex.enter();
        svc = getservbyname(cp, "tcp");
        if(svc)
            port = ntohs(svc->s_port);
        mutex.leave();
        if(!svc) {
            endStream();
            connectError();
            return;
        }
    }

    switch(family) {
    case IPV4:
        connect(IPV4Host(namebuf), port, mss);
        break;
#ifdef  CCXX_IPV6
    case IPV6:
        connect(IPV6Host(namebuf), port, mss);
        break;
#endif
    default:
        endStream();
        connectError();
    }
}