You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

1 year ago
  1. //
  2. // Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015.
  3. // Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
  4. // Copyright © 2020 Thomas A. Early, N7TAE
  5. //
  6. // ----------------------------------------------------------------------------
  7. // This file is part of m17ref.
  8. //
  9. // m17ref is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // m17ref is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // with this software. If not, see <http://www.gnu.org/licenses/>.
  21. // ----------------------------------------------------------------------------
  22. #pragma once
  23. #include <cstdint>
  24. #include <sys/types.h>
  25. #include <unistd.h>
  26. #include <fcntl.h>
  27. #include <sys/socket.h>
  28. #include <sys/ioctl.h>
  29. #include <arpa/inet.h>
  30. #include "ip.h"
  31. ////////////////////////////////////////////////////////////////////////////////////////
  32. // define
  33. #define UDP_BUFFER_LENMAX 1024
  34. ////////////////////////////////////////////////////////////////////////////////////////
  35. // class
  36. class CUdpSocket
  37. {
  38. public:
  39. // constructor
  40. CUdpSocket();
  41. // destructor
  42. ~CUdpSocket();
  43. // open & close
  44. bool Open(const CIp &Ip);
  45. void Close(void);
  46. int GetSocket(void)
  47. {
  48. return m_fd;
  49. }
  50. // read
  51. ssize_t Receive (uint8_t *, CIp &, int);
  52. ssize_t ReceiveFrom(uint8_t *, CIp &);
  53. // write
  54. void Send(const char *, const CIp &) const;
  55. void Send(const uint8_t *, size_t, const CIp &) const;
  56. void Send(const char *, const CIp &, uint16_t) const;
  57. void Send(const uint8_t *, size_t, const CIp &, uint16_t) const;
  58. protected:
  59. // data
  60. int m_fd;
  61. CIp m_addr;
  62. };