MythTV  master
mbroadcastsocketdevice.h
Go to the documentation of this file.
1 // Program Name: broadcast.h
3 // Created : Oct. 1, 2005
4 //
5 // Purpose : Broadcast QSocketDevice Implmenetation
6 //
7 // Copyright (c) 2005 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see LICENSE for details
10 //
12 
13 #ifndef MBROADCAST_SOCKET_DEVICE_H
14 #define MBROADCAST_SOCKET_DEVICE_H
15 
16 #include <QString>
17 
19 
20 #include "msocketdevice.h"
21 
23 // Broadcast Socket is used for XBox (original) since Multicast is not supported
25 
26 class MBroadcastSocketDevice : public MSocketDevice
27 {
28  public:
29  MBroadcastSocketDevice(const QString& sAddress, quint16 nPort) :
30  MSocketDevice(MSocketDevice::Datagram),
31  m_address(sAddress), m_port(nPort)
32  {
33  m_address.setAddress( sAddress );
34  m_port = nPort;
35 
36  setProtocol(IPv4);
37  setSocket(createNewSocket(), MSocketDevice::Datagram);
38 
39  int one = 1;
40  if (setsockopt(socket(), SOL_SOCKET, SO_BROADCAST,
41  (const char *)&one, sizeof(one)) < 0)
42  {
43  LOG(VB_GENERAL, LOG_ERR, "setsockopt - SO_BROADCAST Error" + ENO);
44  }
45 
46  setAddressReusable(true);
47 
48  bind(m_address, m_port);
49  }
50 
52  {
53  int zero = 0;
54  if (setsockopt(socket(), SOL_SOCKET, SO_BROADCAST, (const char *)&zero,
55  sizeof(zero)) < 0)
56  {
57  LOG(VB_GENERAL, LOG_ERR, "setsockopt - SO_BROADCAST Error" + ENO);
58  }
59  }
60 
61  QHostAddress address() const override // MSocketDevice
62  { return m_address; }
63  quint16 port() const override // MSocketDevice
64  { return m_port; }
65 
66  private:
67  QHostAddress m_address;
68  quint16 m_port;
69 };
70 
71 #endif // MBROADCAST_SOCKET_DEVICE_H
ENO
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:73
MBroadcastSocketDevice::m_port
quint16 m_port
Definition: mbroadcastsocketdevice.h:68
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MBroadcastSocketDevice::address
QHostAddress address() const override
Definition: mbroadcastsocketdevice.h:61
mythlogging.h
MBroadcastSocketDevice::m_address
QHostAddress m_address
Definition: mbroadcastsocketdevice.h:67
MBroadcastSocketDevice::port
quint16 port() const override
Definition: mbroadcastsocketdevice.h:63
MBroadcastSocketDevice::MBroadcastSocketDevice
MBroadcastSocketDevice(const QString &sAddress, quint16 nPort)
Definition: mbroadcastsocketdevice.h:29
MBroadcastSocketDevice::~MBroadcastSocketDevice
~MBroadcastSocketDevice() override
Definition: mbroadcastsocketdevice.h:51
MBroadcastSocketDevice
Definition: mbroadcastsocketdevice.h:26