# 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
# File mrbgems/mruby-socket/mrblib/socket.rb, line 31 def self.ip(host) Addrinfo.new(Socket.sockaddr_in(0, host)) end
# 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
# 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
# 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
# File mrbgems/mruby-socket/mrblib/socket.rb, line 47 def afamily @family end
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
# 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
# File mrbgems/mruby-socket/mrblib/socket.rb, line 93 def ip? ipv4? or ipv6? end
# File mrbgems/mruby-socket/mrblib/socket.rb, line 97 def ip_address ip_unpack[0] end
# File mrbgems/mruby-socket/mrblib/socket.rb, line 101 def ip_port ip_unpack[1] end
# 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
# File mrbgems/mruby-socket/mrblib/socket.rb, line 110 def ipv4? @family == Socket::AF_INET end
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
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
# File mrbgems/mruby-socket/mrblib/socket.rb, line 157 def to_sockaddr @sockaddr end