Changeset 3077

Show
Ignore:
Timestamp:
07/04/08 16:17:53 (5 years ago)
Author:
getxsick
Message:

Updated class Socket. Added description of ARP issue.
Updated some names of modules to the pattern.

Location:
branch/UMPA
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branch/UMPA/example.py

    r3070 r3077  
    3838tcp1.set_flags(syn=True) 
    3939 
    40 # create a new packet 
     40# create a new packet and include one protocol (ip1) 
    4141packet = umpa.Packet(ip1) 
    42 # packing those protocols into our packet 
     42# packing another protocol into our packet 
    4343packet.include(tcp1) 
    44  
    45 # XXX: other solutions would be 
    46 # ip1.include(tcp1) 
    47 # packet = umpa.Packet(ip1) 
    4844 
    4945# creating new socket connection 
  • branch/UMPA/umpa/__init__.py

    r3068 r3077  
    2020# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
    2121 
    22 from packet import * 
     22from packets import * 
    2323from sockets import * 
  • branch/UMPA/umpa/sockets.py

    r3072 r3077  
    3636        Just use it in any doubts. 
    3737        ''' 
    38         #try: 
     38        # XXX: if non-root EUID, then Python will exit the application 
     39        # and report the error 
     40        # TODO: try/except section + trying to switch EUID into root and recall socket() 
    3941        self._sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW) 
    40         utils.leave_priviliges()    # dropping root-priviliges 
    41         #except error, msg: 
    42         #    sys.stderr.write('Error while opening new socket:\n') 
    43         #    sys.stderr.write(str(msg) + '\n') 
    44         #    sys.stderr.write('Leaving...') 
    45         #    sys.exit(1) 
     42        # dropping root-priviliges 
     43        utils.drop_priviliges()     
     44        # to build own headers of IP 
     45        self._sock.setsockopt(IPPROTO_IP, IP_HDRINCL, 1) 
    4646 
    4747    def send(self, *packets): 
     
    4949 
    5050        for packet in packets: 
    51             self._sock.send(packet.get_raw()) 
     51            # XXX: this connects to a remote socket, so destination address has to be known. 
     52            # the better solution would be to use ARP (the lowest software layer from OSI). 
     53            # it will be implemented when ARP protocol will be implemented ;) 
     54            # so now we have to parse the packet for destination address 
     55            dst_addr = self._get_address(packet) 
     56            self._sock.sendto(packet.get_raw(), (dst_addr,0) ) 
     57 
     58    def _get_address(self, packet): 
     59        '''Because of ARP issue (described in send() method, 
     60        we have to parse packets for destination addresses. 
     61        ''' 
     62        print "Not implemented yet." 
     63        return False 
  • branch/UMPA/umpa/utils.py

    r3066 r3077  
    2323import pwd 
    2424 
    25 def leave_priviliges(): 
     25def drop_priviliges(): 
    2626    '''Some functions require root-privilegies and after we done them, 
    2727    we don't really need this privilegies. So, we can simple leave them.