Exemple #1
0
Socket::Error UDPTransmit::cConnect(const IPV4Address &ia, tpport_t port)
{
    int len = sizeof(peer.ipv4);

    peer.ipv4.sin_family = AF_INET;
    peer.ipv4.sin_addr = ia.getAddress();
    peer.ipv4.sin_port = htons(port);
    // Win32 will crash if you try to connect to INADDR_ANY.
    if ( INADDR_ANY == peer.ipv4.sin_addr.s_addr )
        peer.ipv4.sin_addr.s_addr = INADDR_LOOPBACK;
    if(::connect(so, (sockaddr *)&peer.ipv4, len))
        return connectError();
    return errSuccess;
}
Exemple #2
0
UDPSocket::UDPSocket(const IPV4Address &ia, tpport_t port) :
Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP), family(IPV4), peer(ia.getAddress(), port)
{
#if defined(SO_REUSEADDR)
    int opt = 1;
    setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, (socklen_t)sizeof(opt));
#endif
    if(bind(so, peer, sizeof(sockaddr_in))) {
        endSocket();
        error(errBindingFailed,(char *)"Could not bind socket",socket_errno);
        return;
    }
    state = BOUND;
}
Exemple #3
0
UDPSocket::UDPSocket(const IPV4Address &ia, tpport_t port) :
Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
{
    family = IPV4;
    memset(&peer.ipv4, 0, sizeof(peer));
    peer.ipv4.sin_family = AF_INET;
    peer.ipv4.sin_addr = ia.getAddress();
    peer.ipv4.sin_port = htons(port);
#if defined(SO_REUSEADDR)
    int opt = 1;
    setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, (socklen_t)sizeof(opt));
#endif
    if(bind(so, (struct sockaddr *)&peer.ipv4, sizeof(peer.ipv4))) {
        endSocket();
        error(errBindingFailed,(char *)"Could not bind socket",socket_errno);
        return;
    }
    state = BOUND;
}
Exemple #4
0
Socket::Error UDPTransmit::cConnect(const IPV4Address &ia, tpport_t port)
{
    return connect(ucommon::Socket::address(ia.getAddress(), port));
}