Changeset 5603

Show
Ignore:
Timestamp:
07/26/08 13:15:35 (3 months ago)
Author:
hdm
Message:

This fixes raw socket support for FreeBSD, NetBSD, BSDi, and Mac OS X. Thanks LibNET!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework3/trunk/lib/rex/compat.rb

    r5334 r5603  
    3030# Platform detection 
    3131# 
     32 
     33@@is_windows = @@is_macosx = @@is_linux = @@is_bsdi = @@is_freebsd = @@is_netbsd = @@is_openbsd = false 
     34 
    3235def self.is_windows 
    33         (RUBY_PLATFORM =~ /mswin32/) ? true : false 
     36        return @@is_windows if @@is_windows 
     37        @@is_windows = (RUBY_PLATFORM =~ /mswin32/) ? true : false 
    3438end 
    3539 
    3640def self.is_macosx 
    37         (RUBY_PLATFORM =~ /darwin/) ? true : false 
     41        return @@is_macosx if @@is_macosx 
     42        @@is_macosx = (RUBY_PLATFORM =~ /darwin/) ? true : false 
    3843end 
    3944 
    4045def self.is_linux 
    41         (RUBY_PLATFORM =~ /linux/) ? true : false 
    42 end 
    43  
     46        return @@is_linux if @@is_linux 
     47        @@is_linux = (RUBY_PLATFORM =~ /linux/) ? true : false 
     48end 
     49 
     50def self.is_bsdi 
     51        return @@is_bsdi if @@is_bsdi 
     52        @@is_bsdi = (RUBY_PLATFORM =~ /bsdi/i) ? true : false 
     53end 
     54 
     55def self.is_netbsd 
     56        return @@is_netbsd if @@is_netbsd 
     57        @@is_netbsd = (RUBY_PLATFORM =~ /netbsd/) ? true : false 
     58end 
    4459 
    4560def self.is_freebsd 
    46         (RUBY_PLATFORM =~ /freebsd/) ? true : false 
     61        return @@is_freebsd if @@is_freebsd 
     62        @@is_freebsd = (RUBY_PLATFORM =~ /freebsd/) ? true : false 
     63end 
     64 
     65def self.is_openbsd 
     66        return @@is_openbsd if @@is_openbsd 
     67        @@is_openbsd = (RUBY_PLATFORM =~ /openbsd/) ? true : false 
    4768end 
    4869 
  • framework3/trunk/lib/rex/socket/ip.rb

    r5596 r5603  
    8989        def sendto(gram, peerhost, flags = 0) 
    9090                dest = ::Socket.pack_sockaddr_in(0, peerhost) 
     91                 
     92                # Some BSDs require byteswap for len and offset 
     93                if( 
     94                        Rex::Compat.is_freebsd or 
     95                        Rex::Compat.is_netbsd or 
     96                        Rex::Compat.is_bsdi or 
     97                        Rex::Compat.is_macosx 
     98                  ) 
     99                        dgram=dgram.dup 
     100                        dgram[2,2]=dgram[2,2].unpack("n").pack("s") 
     101                        dgram[6,2]=dgram[6,2].unpack("n").pack("s") 
     102                end 
     103                 
    91104                send(gram, flags, dest) 
    92105        end