connect_from

addrinfo.connect_from([local_addr_args], [opts]) {|socket| ... }addrinfo.connect_from([local_addr_args], [opts]) Instance Public methods creates a socket connected to the address of self. If one or more arguments given as local_addr_args, it is used as the local address of the socket. local_addr_args is given for #family_addrinfo to obtain actual address. If local_addr_args is not given, the local address of the socket is not bound. The optional last argument opts is options repre

connect

addrinfo.connect([opts]) {|socket| ... }addrinfo.connect([opts]) Instance Public methods creates a socket connected to the address of self. The optional argument opts is options represented by a hash. opts may have following options: :timeout specify the timeout in seconds. If a block is given, it is called with the socket and the value of the block is returned. The socket is returned otherwise. Addrinfo.tcp("www.ruby-lang.org", 80).connect {|s| s.print "GET / HTTP/1.0\r\nH

canonname

addrinfo.canonname => string or nil Instance Public methods returns the canonical name as an string. nil is returned if no canonical name. The canonical name is set by ::getaddrinfo when AI_CANONNAME is specified. list = Addrinfo.getaddrinfo("www.ruby-lang.org", 80, :INET, :STREAM, nil, Socket::AI_CANONNAME) p list[0] #=> #<Addrinfo: 221.186.184.68:80 TCP carbon.ruby-lang.org (www.ruby-lang.org)> p list[0].canonname #=> "carbon.ruby-lang.org"

bind

bind() Instance Public methods creates a socket bound to self. If a block is given, it is called with the socket and the value of the block is returned. The socket is returned otherwise. Addrinfo.udp("0.0.0.0", 9981).bind {|s| s.local_address.connect {|s| s.send "hello", 0 } p s.recv(10) #=> "hello" }

afamily

addrinfo.afamily => integer Instance Public methods returns the address family as an integer. Addrinfo.tcp("localhost", 80).afamily == Socket::AF_INET #=> true

unix

Addrinfo.unix(path [, socktype]) => addrinfo Class Public methods returns an addrinfo object for UNIX socket address. socktype specifies the socket type. If it is omitted, :STREAM is used. Addrinfo.unix("/tmp/sock") #=> #<Addrinfo: /tmp/sock SOCK_STREAM> Addrinfo.unix("/tmp/sock", :DGRAM) #=> #<Addrinfo: /tmp/sock SOCK_DGRAM>

udp

Addrinfo.udp(host, port) => addrinfo Class Public methods returns an addrinfo object for UDP address. Addrinfo.udp("localhost", "daytime") #=> #<Addrinfo: 127.0.0.1:13 UDP (localhost:daytime)>

tcp

Addrinfo.tcp(host, port) => addrinfo Class Public methods returns an addrinfo object for TCP address. Addrinfo.tcp("localhost", "smtp") #=> #<Addrinfo: 127.0.0.1:25 TCP (localhost:smtp)>

new

Addrinfo.new(sockaddr) => addrinfoAddrinfo.new(sockaddr, family) => addrinfoAddrinfo.new(sockaddr, family, socktype) => addrinfoAddrinfo.new(sockaddr, family, socktype, protocol) => addrinfo Class Public methods returns a new instance of Addrinfo. The instance contains sockaddr, family, socktype, protocol. sockaddr means struct sockaddr which can be used for connect(2), etc. family, socktype and protocol are int

ip

Addrinfo.ip(host) => addrinfo Class Public methods returns an addrinfo object for IP address. The port, socktype, protocol of the result is filled by zero. So, it is not appropriate to create a socket. Addrinfo.ip("localhost") #=> #<Addrinfo: 127.0.0.1 (localhost)>