Sha256: de5982090d963732b6e2ff7a4df7c97b69397372c70d9c86747a7ec2e5039ac6

Contents?: true

Size: 851 Bytes

Versions: 3

Compression:

Stored size: 851 Bytes

Contents

# Copyright (C) 2009-2010 Brian Candler <http://www.deploy2.net/>
# Licensed under the same terms as ruby. See LICENCE.txt and COPYING.txt

require 'socket'

class IP
  # Return the address family, Socket::AF_INET or Socket::AF_INET6
  def af
    self.class::AF
  end

  # Convert to a packed sockaddr structure  
  def to_sockaddr(port=0)
    Socket.pack_sockaddr_in(port, to_addr)
  end
  
  class V4
    AF = Socket::AF_INET
    PROTO_TO_CLASS[AF] = self

    # Avoid the string conversion when building sockaddr. Unfortunately this
    # fails 32-bit machines with 1.8.6 for addrs >= 0x80000000. There is
    # also no corresponding Socket.pack_sockaddr_in6 we could use for V6.

    #def to_sockaddr(port=0)
    #  Socket.pack_sockaddr_in(port, to_i)
    #end
  end
  
  class V6
    AF = Socket::AF_INET6
    PROTO_TO_CLASS[AF] = self
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-ip-0.9.3 lib/ip/socket.rb
ruby-ip-0.9.1 lib/ip/socket.rb
ruby-ip-0.9.0 lib/ip/socket.rb