In Files

  • mrbgems/mruby-socket/mrblib/socket.rb

Addrinfo

Attributes

canonname[R]

def bind

protocol[R]
socktype[R]

Public Class Methods

foreach(nodename, service, family=nil, socktype=nil, protocol=nil, flags=0, &block) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 25
def self.foreach(nodename, service, family=nil, socktype=nil, protocol=nil, flags=0, &block)
  a = self.getaddrinfo(nodename, service, family, socktype, protocol, flags)
  a.each { |ai| block.call(ai) }
  a
end
            
ip(host) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 31
def self.ip(host)
  Addrinfo.new(Socket.sockaddr_in(0, host))
end
            
new(sockaddr, family=Socket::PF_UNSPEC, socktype=0, protocol=0) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 2
def initialize(sockaddr, family=Socket::PF_UNSPEC, socktype=0, protocol=0)
  @hostname = nil
  if sockaddr.is_a? Array
    sary = sockaddr
    if sary[0] == 'AF_INET' || sary[0] == 'AF_INET6'
      @sockaddr = Socket.sockaddr_in(sary[1], sary[3])
      @hostname = sary[2]
    elsif sary[0] == 'AF_UNIX'
      @sockaddr = Socket.sockaddr_un(sary[1])
    end
  else
    @sockaddr = sockaddr.dup
  end
  if family == Socket::PF_UNSPEC or family == nil
    @family = Socket._sockaddr_family(@sockaddr)
  else
    @family = family
  end
  @socktype = socktype
  @protocol = protocol
  @canonname = nil
end
            
tcp(host, port) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 35
def self.tcp(host, port)
  Addrinfo.getaddrinfo(host, port, nil, Socket::SOCK_STREAM, Socket::IPPROTO_TCP)[0]
end
            
udp(host, port) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 39
def self.udp(host, port)
  Addrinfo.getaddrinfo(host, port, nil, Socket::SOCK_DGRAM, Socket::IPPROTO_UDP)[0]
end
            
unix(path, socktype=Socket::SOCK_STREAM) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 43
def self.unix(path, socktype=Socket::SOCK_STREAM)
  Addrinfo.new(Socket.sockaddr_un(path), Socket::AF_UNIX, socktype)
end
            

Public Instance Methods

_to_array() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 142
def _to_array
  case @family
  when Socket::AF_INET
    s = "AF_INET"
  when Socket::AF_INET6
    s = "AF_INET6"
  when Socket::AF_UNIX
    s = "AF_UNIX"
  else
    s = "(unknown AF)"
  end
  addr, port = self.getnameinfo(Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)
  [ s, port.to_i, addr, addr ]
end
            
afamily() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 47
def afamily
  @family
end
            
inspect() click to toggle source

def family_addrinfo(host, port=nil) def getnameinfo(flags=0)

Socket.getnameinfo

end

 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 64
def inspect
  if ipv4? or ipv6?
    if @protocol == Socket::IPPROTO_TCP or (@socktype == Socket::SOCK_STREAM and @protocol == 0)
      proto = 'TCP'
    elsif @protocol == Socket::IPPROTO_UDP or (@socktype == Socket::SOCK_DGRAM and @protocol == 0)
      proto = 'UDP'
    else
      proto = '???'
    end
    "#<Addrinfo: #{inspect_sockaddr} #{proto}>"
  else
    "#<Addrinfo: #{self.unix_path} SOCK_STREAM>"
  end
end
            
inspect_sockaddr() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 79
def inspect_sockaddr
  if ipv4?
    a, p = ip_unpack
    "#{a}:#{p}"
  elsif ipv6?
    a, p = ip_unpack
    "[#{a}]:#{p}"
  elsif unix?
    unix_path
  else
    '???'
  end
end
            
ip?() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 93
def ip?
  ipv4? or ipv6?
end
            
ip_address() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 97
def ip_address
  ip_unpack[0]
end
            
ip_port() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 101
def ip_port
  ip_unpack[1]
end
            
ip_unpack() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 105
def ip_unpack
  h, p = getnameinfo(Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)
  [ h, p.to_i ]
end
            
ipv4?() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 110
def ipv4?
  @family == Socket::AF_INET
end
            
ipv6?() click to toggle source

def ipv4_loopback? def ipv4_multicast? def ipv4_private?

 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 118
def ipv6?
  @family == Socket::AF_INET6
end
            
pfamily() click to toggle source

def ipv6_loopback? def ipv6_mc_global? def ipv6_mc_linklocal? def ipv6_mc_nodelocal? def ipv6_mc_orilocal? def ipv6_mc_sitelocal? def ipv6_multicast? def ipv6_to_ipv4 def ipv6_unspecified def ipv6_v4compat? def ipv6_v4mapped? def listen(backlog=5)

 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 135
def pfamily
  @family
end
            
to_s() click to toggle source
Alias for: to_sockaddr
to_sockaddr() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 157
def to_sockaddr
  @sockaddr
end
            
Also aliased as: to_s
unix?() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 163
def unix?
  @family == Socket::AF_UNIX
end