getsockname

basicsocket.getsockname => sockaddr Instance Public methods Returns the local address of the socket as a sockaddr string. TCPServer.open("127.0.0.1", 15120) {|serv| p serv.getsockname #=> "\x02\x00;\x10\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00" } If Addrinfo object is preferred over the binary string, use #local_address.

getpeername

basicsocket.getpeername => sockaddr Instance Public methods Returns the remote address of the socket as a sockaddr string. TCPServer.open("127.0.0.1", 1440) {|serv| c = TCPSocket.new("127.0.0.1", 1440) s = serv.accept p s.getpeername #=> "\x02\x00\x82u\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00" } If Addrinfo object is preferred over the binary string, use #remote_address.

getpeereid

basicsocket.getpeereid => [euid, egid] Instance Public methods Returns the user and group on the peer of the UNIX socket. The result is a two element array which contains the effective uid and the effective gid. Socket.unix_server_loop("/tmp/sock") {|s| begin euid, egid = s.getpeereid # Check the connected client is myself or not. next if euid != Process.uid # do something about my resource. ensure s.close end }

do_not_reverse_lookup= 2

basicsocket.do_not_reverse_lookup = bool Instance Public methods Sets the ::do_not_reverse_lookup flag of basicsocket. BasicSocket.do_not_reverse_lookup = false p TCPSocket.new("127.0.0.1", 80).do_not_reverse_lookup #=> false BasicSocket.do_not_reverse_lookup = true p TCPSocket.new("127.0.0.1", 80).do_not_reverse_lookup #=> true

do_not_reverse_lookup 2

basicsocket.do_not_reverse_lookup => true or false Instance Public methods Gets the ::do_not_reverse_lookup flag of basicsocket. TCPSocket.open("www.ruby-lang.org", 80) {|sock| p sock.do_not_reverse_lookup #=> false p sock.peeraddr #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"] sock.do_not_reverse_lookup = true p sock.peeraddr #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"] }

connect_address

connect_address() Instance Public methods Returns an address of the socket suitable for connect in the local machine. This method returns self.local_address, except following condition. IPv4 unspecified address (0.0.0.0) is replaced by IPv4 loopback address (127.0.0.1). IPv6 unspecified address (::) is replaced by IPv6 loopback address (::1). If the local address is not suitable for connect, SocketError is raised. IPv4 and IPv6 address which port is 0 is not suitable for conn

close_write

basicsocket.close_write => nil Instance Public methods Disallows further write using shutdown system call. UNIXSocket.pair {|s1, s2| s1.print "ping" s1.close_write p s2.read #=> "ping" s2.print "pong" s2.close p s1.read #=> "pong" }

close_read

basicsocket.close_read => nil Instance Public methods Disallows further read using shutdown system call. s1, s2 = UNIXSocket.pair s1.close_read s2.puts #=> Broken pipe (Errno::EPIPE)

for_fd

BasicSocket.for_fd(fd) => basicsocket Class Public methods Returns a socket object which contains the file descriptor, fd. # If invoked by inetd, STDIN/STDOUT/STDERR is a socket. STDIN_SOCK = Socket.for_fd(STDIN.fileno) p STDIN_SOCK.remote_address

do_not_reverse_lookup=

BasicSocket.do_not_reverse_lookup = bool Class Public methods Sets the global ::do_not_reverse_lookup flag. The flag is used for initial value of ::do_not_reverse_lookup for each socket. s1 = TCPSocket.new("localhost", 80) p s1.do_not_reverse_lookup #=> true BasicSocket.do_not_reverse_lookup = false s2 = TCPSocket.new("localhost", 80) p s2.do_not_reverse_lookup #=> false p s1.do_not_reverse_lookup #=> true