| Index: net/udp/udp_socket_libevent.cc
|
| diff --git a/net/udp/udp_socket_libevent.cc b/net/udp/udp_socket_libevent.cc
|
| index 063da08c387963b60066b3d1459aa82b9703a970..1fc15ff793214c358fa3d556f23b2e10ca42765e 100644
|
| --- a/net/udp/udp_socket_libevent.cc
|
| +++ b/net/udp/udp_socket_libevent.cc
|
| @@ -363,7 +363,8 @@ void UDPSocketLibevent::LogRead(int result,
|
| }
|
|
|
| int UDPSocketLibevent::CreateSocket(const IPEndPoint& address) {
|
| - socket_ = socket(address.GetSockAddrFamily(), SOCK_DGRAM, 0);
|
| + sock_addr_family_ = address.GetSockAddrFamily();
|
| + socket_ = socket(sock_addr_family_, SOCK_DGRAM, 0);
|
| if (socket_ == kInvalidSocket)
|
| return MapSystemError(errno);
|
| if (SetNonBlocking(socket_)) {
|
| @@ -509,4 +510,95 @@ int UDPSocketLibevent::RandomBind(const IPEndPoint& address) {
|
| return DoBind(IPEndPoint(ip, 0));
|
| }
|
|
|
| +int UDPSocketLibevent::JoinGroup(
|
| + const net::IPAddressNumber& group_address) const {
|
| + DCHECK(CalledOnValidThread());
|
| + DCHECK(is_connected());
|
| +
|
| + int rv = -1;
|
| + switch(group_address.size()) {
|
| + case kIPv4AddressSize: {
|
| + if (sock_addr_family_ != AF_INET) {
|
| + return ERR_ADDRESS_INVALID;
|
| + }
|
| + ip_mreq mreq;
|
| + memset(&mreq, 0, sizeof(mreq));
|
| + memcpy(&mreq.imr_multiaddr, &group_address[0], kIPv4AddressSize);
|
| + rv = setsockopt(socket_, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
| + &mreq, sizeof(mreq));
|
| + break;
|
| + }
|
| + case kIPv6AddressSize: {
|
| + if (sock_addr_family_ != AF_INET6) {
|
| + return ERR_ADDRESS_INVALID;
|
| + }
|
| + ipv6_mreq mreq;
|
| + memset(&mreq, 0, sizeof(mreq));
|
| + memcpy(&mreq.ipv6mr_multiaddr, &group_address[0], kIPv6AddressSize);
|
| + rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
| + &mreq, sizeof(mreq));
|
| + break;
|
| + }
|
| + }
|
| +
|
| + return MapSystemError(rv);
|
| +}
|
| +
|
| +int UDPSocketLibevent::LeaveGroup(
|
| + const net::IPAddressNumber& group_address) const {
|
| + DCHECK(CalledOnValidThread());
|
| + DCHECK(is_connected());
|
| +
|
| + int rv = -1;
|
| + switch(group_address.size()) {
|
| + case kIPv4AddressSize: {
|
| + if (sock_addr_family_ != AF_INET) {
|
| + return ERR_ADDRESS_INVALID;
|
| + }
|
| + ip_mreq mreq;
|
| + memset(&mreq, 0, sizeof(mreq));
|
| + memcpy(&mreq.imr_multiaddr, &group_address[0], kIPv4AddressSize);
|
| + rv = setsockopt(socket_, IPPROTO_IP, IP_DROP_MEMBERSHIP,
|
| + &mreq, sizeof(mreq));
|
| + break;
|
| + }
|
| + case kIPv6AddressSize: {
|
| + if (sock_addr_family_ != AF_INET6) {
|
| + return ERR_ADDRESS_INVALID;
|
| + }
|
| + ipv6_mreq mreq;
|
| + memset(&mreq, 0, sizeof(mreq));
|
| + memcpy(&mreq.ipv6mr_multiaddr, &group_address[0], kIPv6AddressSize);
|
| + rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
|
| + &mreq, sizeof(mreq));
|
| + break;
|
| + }
|
| + }
|
| +
|
| + return MapSystemError(rv);
|
| +}
|
| +
|
| +int UDPSocketLibevent::SetMulticastTimeToLive(int timeToLive) {
|
| + DCHECK(CalledOnValidThread());
|
| + DCHECK(is_connected());
|
| +
|
| + uint8 ttl = timeToLive;
|
| + int ip_family = sock_addr_family_ == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
| + return MapSystemError(setsockopt(socket_,
|
| + ip_family,
|
| + IP_MULTICAST_TTL,
|
| + &ttl, sizeof(ttl)));
|
| +}
|
| +
|
| +int UDPSocketLibevent::SetMulticastLoopbackMode(bool loopback) {
|
| + DCHECK(CalledOnValidThread());
|
| + DCHECK(is_connected());
|
| +
|
| + uint8 loop = loopback;
|
| + int ip_family = sock_addr_family_ == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
| + return MapSystemError(setsockopt(socket_,
|
| + ip_family,
|
| + IP_MULTICAST_LOOP,
|
| + &loop, sizeof(loop)));
|
| +}
|
| } // namespace net
|
|
|