Catch an exception thrown if no default route exists

git-svn-id: file:///home/svn/incoming/trunk@3480 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2006-01-30 21:57:24 +00:00
parent 7ee4d05bec
commit f4c07e8a54
1 changed files with 8 additions and 4 deletions

View File

@ -146,10 +146,14 @@ module Socket
##
def self.source_address(dest='1.2.3.4')
self.create_udp(
'PeerHost' => dest,
'PeerPort' => 31337
).getsockname[1]
begin
return self.create_udp(
'PeerHost' => dest,
'PeerPort' => 31337
).getsockname[1]
rescue ::Exception
return '127.0.0.1'
end
end