Skip to content

Commit

Permalink
fix(src): send messages using correct socket, closes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
christgau committed Dec 28, 2020
1 parent 800f224 commit 1ed74fe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixed

- Messages are sent via the correct socket to comply with the intended/specified message flow. This also eases the firewall configuration (#72).

## [0.6.2] - 2020-10-18

### Changed
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -106,7 +106,8 @@ actual distribution/installation where they are to be used.

Both incoming and outgoing multicast traffic on port 3702 must be allowed. For
IPv4, the multicast address is `239.255.255.250`, for IPv6 the link local SSDP
multicast address (`ff02::c`) is used.
multicast address (`ff02::c`) is used. Outgoing unicast UDP traffic from port
3702 must be allowed too.

Incoming TCP traffic (and related outgoing traffic) on port 5357 must be
allowed.
Expand Down
3 changes: 2 additions & 1 deletion man/wsdd.1
Expand Up @@ -136,7 +136,8 @@ domain socket to which a client can connect to.
.PP
Both incoming and outgoing multicast traffic on port 3702 must be allowed. For
IPv4, the multicast address is `239.255.255.250`, for IPv6 the link local SSDP
multicast address (`fe02::c`) is used.
multicast address (`fe02::c`) is used. Outgoing unicast UDP traffic from port
3702 must be allowed too.
.PP
Incoming TCP traffic (and related outgoing traffic) on port 5357 must be
allowed.
Expand Down
11 changes: 10 additions & 1 deletion src/wsdd.py
Expand Up @@ -183,6 +183,15 @@ def handle_request(self, key):
for handler in self.message_handlers[s]:
handler.handle_request(msg, address)

def send(self, msg, addr):
# Request from a client must be answered from a socket that is bound
# to the WSD port, i.e. the recv_socket. Messages to multicast
# addresses are sent over the dedicated send socket.
if addr == self.multicast_address:
self.send_socket.sendto(msg, addr)
else:
self.recv_socket.sendto(msg, addr)


# constants for WSD XML/SOAP parsing
WSA_URI = 'http://schemas.xmlsoap.org/ws/2004/08/addressing'
Expand Down Expand Up @@ -1536,7 +1545,7 @@ def send_outstanding_messages(block=False):
addr = send_queue[-1][2]
msg = send_queue[-1][3]
try:
mch.send_socket.sendto(msg, addr)
mch.send(msg, addr)
except Exception as e:
logger.error('error while sending packet on {}: {}'.format(
mch.interface.name, e))
Expand Down

0 comments on commit 1ed74fe

Please sign in to comment.