Method: Rex::Socket::Udp#sendto

Defined in:
lib/rex/socket/udp.rb

#sendto(gram, peerhost, peerport, flags = 0) ⇒ Object

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rex/socket/udp.rb', line 100

def sendto(gram, peerhost, peerport, flags = 0)

  # Catch unconnected IPv6 sockets talking to IPv4 addresses
  peer = Rex::Socket.resolv_nbo(peerhost)
  if (peer.length == 4 and self.ipv == 6)
    peerhost = Rex::Socket.getaddress(peerhost, true)
    if peerhost[0,7].downcase != '::ffff:'
      peerhost = '::ffff:' + peerhost
    end
  end

  begin
    send(gram, flags, Rex::Socket.to_sockaddr(peerhost, peerport))
  rescue  ::Errno::EHOSTUNREACH,::Errno::ENETDOWN,::Errno::ENETUNREACH,::Errno::ENETRESET,::Errno::EHOSTDOWN,::Errno::EACCES,::Errno::EINVAL,::Errno::EADDRNOTAVAIL
    return nil
  end

end