Adds the Broadcast parameter to the Rex::Socket class, allows udp/ip sockets to send to broadcast addresses

git-svn-id: file:///home/svn/framework3/trunk@6778 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2009-07-13 13:19:31 +00:00
parent 3e072dd66e
commit 9068b9a133
2 changed files with 24 additions and 0 deletions

View File

@ -44,6 +44,11 @@ class Rex::Socket::Comm::Local
sock = ::Socket.open(::Socket::PF_INET, ::Socket::SOCK_RAW, ::Socket::IPPROTO_RAW)
sock.setsockopt(::Socket::IPPROTO_IP, ::Socket::IP_HDRINCL, 1)
# Configure broadcast support if the parameter is requested
if(param.broadcast)
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true)
end
if (param.bare? == false)
sock.extend(::Rex::Socket::Ip)
sock.initsock(param)
@ -142,6 +147,11 @@ class Rex::Socket::Comm::Local
raise Rex::AddressInUse.new(param.localhost, param.localport), caller
end
end
# Configure broadcast support if the parameter is requested
if(param.broadcast)
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true)
end
# If a server TCP instance is being created...
if (param.server?)

View File

@ -89,6 +89,11 @@ class Rex::Socket::Parameters
#
# The number of seconds before a connection should time out
#
# Broadcast
#
# Specify this as true to send traffic to broadcast addresses
#
def initialize(hash)
if (hash['PeerHost'])
self.peerhost = hash['PeerHost']
@ -173,6 +178,11 @@ class Rex::Socket::Parameters
self.timeout = 5
end
# Enable sends to broadcast addresses
if hash['Broadcast']
self.broadcast = true
else
# Whether to force IPv6 addressing
self.v6 = hash['IPv6'] || false
end
@ -291,6 +301,10 @@ class Rex::Socket::Parameters
#
attr_accessor :timeout
#
# Whether or not to enable broadcast sends on this socket
#
attr_accessor :broadcast
#
# Whether or not this is a bare (non-extended) socket instance that should
# be created.
#