Changeset 3077
- Timestamp:
- 07/04/08 16:17:53 (5 years ago)
- Location:
- branch/UMPA
- Files:
-
- 4 modified
-
example.py (modified) (1 diff)
-
umpa/__init__.py (modified) (1 diff)
-
umpa/sockets.py (modified) (2 diffs)
-
umpa/utils.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branch/UMPA/example.py
r3070 r3077 38 38 tcp1.set_flags(syn=True) 39 39 40 # create a new packet 40 # create a new packet and include one protocol (ip1) 41 41 packet = umpa.Packet(ip1) 42 # packing those protocolsinto our packet42 # packing another protocol into our packet 43 43 packet.include(tcp1) 44 45 # XXX: other solutions would be46 # ip1.include(tcp1)47 # packet = umpa.Packet(ip1)48 44 49 45 # creating new socket connection -
branch/UMPA/umpa/__init__.py
r3068 r3077 20 20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 21 22 from packet import *22 from packets import * 23 23 from sockets import * -
branch/UMPA/umpa/sockets.py
r3072 r3077 36 36 Just use it in any doubts. 37 37 ''' 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() 39 41 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) 46 46 47 47 def send(self, *packets): … … 49 49 50 50 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 23 23 import pwd 24 24 25 def leave_priviliges():25 def drop_priviliges(): 26 26 '''Some functions require root-privilegies and after we done them, 27 27 we don't really need this privilegies. So, we can simple leave them.
