Esempio n. 1
0
void Bayonne::addTrap6(const char *addr)
{
	char abuf[128];
	char *tok;
	socklen_t alen = sizeof(sockaddr_in6);
	IPV6Address ia;
	int on = 1;

	setString(abuf, sizeof(abuf), addr);
	addr = strtok_r(abuf, " ;,\r\n\t", &tok);
	if(trap_so6 == INVALID_SOCKET)
	{
		trap_so6 = socket(AF_INET6, SOCK_DGRAM, 0);
		setsockopt(trap_so6, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
	}

	while(addr && trap_count6 < 8)
	{
		ia = addr;
		memset(&trap_addr6[trap_count6], 0, alen);
		trap_addr6[trap_count6].sin6_family = AF_INET6;
		trap_addr6[trap_count6].sin6_port = htons(162);
		trap_addr6[trap_count6].sin6_addr = ia.getAddress();	
		++trap_count6;
		addr = strtok_r(NULL, " ;,\r\n\t", &tok);
	}
}
Esempio n. 2
0
UDPSocket::UDPSocket(const IPV6Address &ia, tpport_t port) :
Socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP), family(IPV6), 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_in6))) {
        endSocket();
        error(errBindingFailed,(char *)"Could not bind socket",socket_errno);
        return;
    }
    state = BOUND;
}
Esempio n. 3
0
Socket::Error UDPTransmit::connect(const IPV6Address &ia, tpport_t port)
{
    int len = sizeof(peer.ipv6);

    peer.ipv6.sin6_family = AF_INET6;
    peer.ipv6.sin6_addr = ia.getAddress();
    peer.ipv6.sin6_port = htons(port);
    // Win32 will crash if you try to connect to INADDR_ANY.
    if(!memcmp(&peer.ipv6.sin6_addr, &in6addr_any, sizeof(in6addr_any)))
        memcpy(&peer.ipv6.sin6_addr, &in6addr_loopback,
            sizeof(in6addr_loopback));
    if(::connect(so, (struct sockaddr *)&peer.ipv6, len))
        return connectError();
    return errSuccess;
}
Esempio n. 4
0
UDPSocket::UDPSocket(const IPV6Address &ia, tpport_t port) :
Socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)
{
    family = IPV6;
    memset(&peer.ipv6, 0, sizeof(peer));
    peer.ipv6.sin6_family = AF_INET6;
    peer.ipv6.sin6_addr = ia.getAddress();
    peer.ipv6.sin6_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.ipv6, sizeof(peer.ipv6))) {
        endSocket();
        error(errBindingFailed,(char *)"Could not bind socket",socket_errno);
        return;
    }
    state = BOUND;
}
Esempio n. 5
0
Socket::Error UDPTransmit::connect(const IPV6Address &ia, tpport_t port)
{
    return connect(ucommon::Socket::address(ia.getAddress(), port));
}