Skip to content

Commit

Permalink
handle no broadcast available in interface (loopback)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBender committed Mar 10, 2017
1 parent ec01d22 commit 54d0f44
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
15 changes: 13 additions & 2 deletions py25/bacpypes/bvllservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ def __init__(self, addr=None, noBroadcast=False):
else:
self.address = Address(addr)

# check for a special broadcast address
# promote the normal and broadcast tuples
self.addrTuple = self.address.addrTuple
self.addrBroadcastTuple = self.address.addrBroadcastTuple
if (self.addrTuple == self.addrBroadcastTuple):

# check for no broadcasting (loopback interface)
if not self.addrBroadcastTuple:
noBroadcast = True
elif (self.addrTuple == self.addrBroadcastTuple):
# old school broadcast address
self.addrBroadcastTuple = ('255.255.255.255', self.addrTuple[1])
else:
specialBroadcast = True
Expand Down Expand Up @@ -117,9 +122,15 @@ def indication(self, server, pdu):
if pdu.pduDestination.addrType == Address.localBroadcastAddr:
dest = self.addrBroadcastTuple
if _debug: UDPMultiplexer._debug(" - requesting local broadcast: %r", dest)

# interface might not support broadcasts
if not dest:
return

elif pdu.pduDestination.addrType == Address.localStationAddr:
dest = unpack_ip_addr(pdu.pduDestination.addrAddr)
if _debug: UDPMultiplexer._debug(" - requesting local station: %r", dest)

else:
raise RuntimeError("invalid destination address type")

Expand Down
15 changes: 13 additions & 2 deletions py27/bacpypes/bvllservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ def __init__(self, addr=None, noBroadcast=False):
else:
self.address = Address(addr)

# check for a special broadcast address
# promote the normal and broadcast tuples
self.addrTuple = self.address.addrTuple
self.addrBroadcastTuple = self.address.addrBroadcastTuple
if (self.addrTuple == self.addrBroadcastTuple):

# check for no broadcasting (loopback interface)
if not self.addrBroadcastTuple:
noBroadcast = True
elif (self.addrTuple == self.addrBroadcastTuple):
# old school broadcast address
self.addrBroadcastTuple = ('255.255.255.255', self.addrTuple[1])
else:
specialBroadcast = True
Expand Down Expand Up @@ -118,9 +123,15 @@ def indication(self, server, pdu):
if pdu.pduDestination.addrType == Address.localBroadcastAddr:
dest = self.addrBroadcastTuple
if _debug: UDPMultiplexer._debug(" - requesting local broadcast: %r", dest)

# interface might not support broadcasts
if not dest:
return

elif pdu.pduDestination.addrType == Address.localStationAddr:
dest = unpack_ip_addr(pdu.pduDestination.addrAddr)
if _debug: UDPMultiplexer._debug(" - requesting local station: %r", dest)

else:
raise RuntimeError("invalid destination address type")

Expand Down
16 changes: 14 additions & 2 deletions py34/bacpypes/bvllservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ def __init__(self, addr=None, noBroadcast=False):
else:
self.address = Address(addr)

# check for a special broadcast address
# promote the normal and broadcast tuples
self.addrTuple = self.address.addrTuple
self.addrBroadcastTuple = self.address.addrBroadcastTuple
if (self.addrTuple == self.addrBroadcastTuple):

# check for no broadcasting (loopback interface)
if not self.addrBroadcastTuple:
noBroadcast = True
elif (self.addrTuple == self.addrBroadcastTuple):
# old school broadcast address
self.addrBroadcastTuple = ('255.255.255.255', self.addrTuple[1])
else:
specialBroadcast = True
Expand All @@ -98,6 +103,7 @@ def __init__(self, addr=None, noBroadcast=False):
bind(self.direct, self.broadcastPort)
else:
self.broadcast = None

# create and bind the Annex H and J servers
self.annexH = _MultiplexServer(self)
self.annexJ = _MultiplexServer(self)
Expand All @@ -117,9 +123,15 @@ def indication(self, server, pdu):
if pdu.pduDestination.addrType == Address.localBroadcastAddr:
dest = self.addrBroadcastTuple
if _debug: UDPMultiplexer._debug(" - requesting local broadcast: %r", dest)

# interface might not support broadcasts
if not dest:
return

elif pdu.pduDestination.addrType == Address.localStationAddr:
dest = pdu.pduDestination.addrTuple
if _debug: UDPMultiplexer._debug(" - requesting local station: %r", dest)

else:
raise RuntimeError("invalid destination address type")

Expand Down

0 comments on commit 54d0f44

Please sign in to comment.