module SSLScan::Socket::Ip

This class provides methods for interacting with a IP socket.

Public Class Methods

create(hash = {}) click to toggle source

Creates the client using the supplied hash.

# File lib/ssl_scan/socket/ip.rb, line 20
def self.create(hash = {})
  hash['Proto'] = 'ip'
  self.create_param(SSLScan::Socket::Parameters.from_hash(hash))
end
create_param(param) click to toggle source

Wrapper around the base socket class' creation method that automatically sets the parameter's protocol to IP.

# File lib/ssl_scan/socket/ip.rb, line 29
def self.create_param(param)
  param.proto = 'ip'
  SSLScan::Socket.create_param(param)
end

Public Instance Methods

def_read_timeout() click to toggle source

The default number of seconds to wait for a read operation to timeout.

# File lib/ssl_scan/socket/ip.rb, line 120
def def_read_timeout
  10
end
get(timeout=nil) click to toggle source

Calls recvfrom and only returns the data

# File lib/ssl_scan/socket/ip.rb, line 112
def get(timeout=nil)
  data, saddr = recvfrom(65535, timeout)
  return data
end
put(gram)
Alias for: write
read(length = 65535) click to toggle source

Read a datagram from the IP socket.

# File lib/ssl_scan/socket/ip.rb, line 52
def read(length = 65535)
  raise RuntimeError, "IP sockets must use recvfrom(), not read()"
end
recvfrom(length = 65535, timeout=def_read_timeout) click to toggle source

Receives a datagram and returns the data and host of the requestor as [ data, host ].

Calls superclass method
# File lib/ssl_scan/socket/ip.rb, line 92
def recvfrom(length = 65535, timeout=def_read_timeout)
  begin
    if ((rv = ::IO.select([ fd ], nil, nil, timeout)) and
        (rv[0]) and (rv[0][0] == fd)
       )
        data, saddr    = super(length)
        af, host       = SSLScan::Socket.from_sockaddr(saddr)

        return [ data, host ]
    else
      return [ '', nil ]
    end
  rescue Exception
    return [ '', nil ]
  end
end
sendto(gram, peerhost, flags = 0) click to toggle source

Sends a datagram to the supplied host:port with optional flags.

# File lib/ssl_scan/socket/ip.rb, line 65
def sendto(gram, peerhost, flags = 0)
  dest = ::Socket.pack_sockaddr_in(0, peerhost)

  # Some BSDs require byteswap for len and offset
  if(
    SSLScan::Compat.is_freebsd or
    SSLScan::Compat.is_netbsd or
    SSLScan::Compat.is_bsdi or
    SSLScan::Compat.is_macosx
    )
    gram=gram.dup
    gram[2,2]=gram[2,2].unpack("n").pack("s")
    gram[6,2]=gram[6,2].unpack("n").pack("s")
  end

  begin
    send(gram, flags, dest)
  rescue  ::Errno::EHOSTUNREACH,::Errno::ENETDOWN,::Errno::ENETUNREACH,::Errno::ENETRESET,::Errno::EHOSTDOWN,::Errno::EACCES,::Errno::EINVAL,::Errno::EADDRNOTAVAIL
    return nil
  end

end
type?() click to toggle source
# File lib/ssl_scan/socket/ip.rb, line 124
def type?
  return 'ip'
end
write(gram) click to toggle source

Write the supplied datagram to the connected IP socket.

# File lib/ssl_scan/socket/ip.rb, line 43
def write(gram)
  raise RuntimeError, "IP sockets must use sendto(), not write()"
end
Also aliased as: put