broadcast.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef __BROADCAST_H
  2. #define __BROADCAST_H
  3. #include <winsock.h>
  4. //
  5. // This class handles opening of UDP port to send
  6. // or receive broadcasts with cross router jumps.
  7. //
  8. class UdpSocket
  9. {
  10. protected:
  11. SOCKET m_sock;
  12. public:
  13. UdpSocket();
  14. ~UdpSocket();
  15. int Bind( unsigned short port, unsigned long addr = INADDR_ANY );
  16. int BindExcludePort( unsigned short port, unsigned long addr = INADDR_ANY );
  17. int Close();
  18. int EnableBroadcast();
  19. int SendTo(void* pBuffer, int size, unsigned short port, unsigned long addr = INADDR_BROADCAST );
  20. int Recv(void* pBuffer,int size);
  21. };
  22. #if 0
  23. class Broadcast {
  24. public:
  25. Broadcast();
  26. ~Broadcast();
  27. //Semantics are 0 or if SOCKET_ERROR use
  28. //WSAGetLastError
  29. int Bind(unsigned short port);
  30. int Close();
  31. //You shouldn't send over 512 bytes
  32. //This call uses blocking version of sendto call
  33. int Send(void* pBuffer,int size);
  34. protected:
  35. SOCKET m_sock;
  36. SOCKADDR_IN m_addr;
  37. };
  38. class Listen: public Broadcast {
  39. public:
  40. Listen() {;};
  41. //Semantics are 0 or if SOCKET_ERROR use
  42. //WSAGetLastError
  43. // use INADDR_ANY to receive on all NICs
  44. int Bind(unsigned long addr, unsigned short port);
  45. int Recv(void* pBuffer,int size);
  46. };
  47. #endif
  48. #endif //__BROADCAST_H