Changeset 5600

Show
Ignore:
Timestamp:
06/05/10 20:15:52 (3 years ago)
Author:
kosma
Message:

Fixed L2 send (bpf) under OpenBSD.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • UMPA/branch/link-layer-integration/umit/umpa/_sockets.py

    r5599 r5600  
    3333import sys 
    3434import os 
     35from errno import EBUSY 
    3536 
    3637from umit.umpa.utils.exceptions import UMPAException, UMPANotPermittedException 
     
    132133            self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**20) 
    133134        elif _l2model == 'bpf': 
    134             try: 
    135                 self._sock = open("/dev/bpf", 'w') 
    136             except IOError, msg: 
    137                 raise UMPAException('cannot open /dev/bpf: ' + msg) 
     135            # Loop over /dev/bpf* devices, looking for a free one. 
     136            self._sock = None 
     137            suffix = 0 
     138            while self._sock is None: 
     139                try: 
     140                    self._sock = open('/dev/bpf'+str(suffix), 'wb') 
     141                except IOError, error: 
     142                    if error.errno == EBUSY: 
     143                        suffix = suffix + 1 
     144                    else: 
     145                        raise UMPAException(str(error)) 
    138146 
    139147            ioctl(self._sock, BIOCSETIF, iface)