Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

58 linhas
1.1KB

  1. #if ARDUINO >= 100
  2. #include "Arduino.h"
  3. #include "IPAddress.h"
  4. IPAddress::IPAddress()
  5. {
  6. memset(_address, 0, sizeof(_address));
  7. }
  8. IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
  9. {
  10. _address[0] = first_octet;
  11. _address[1] = second_octet;
  12. _address[2] = third_octet;
  13. _address[3] = fourth_octet;
  14. }
  15. IPAddress::IPAddress(uint32_t address)
  16. {
  17. memcpy(_address, &address, sizeof(_address));
  18. }
  19. IPAddress::IPAddress(const uint8_t *address)
  20. {
  21. memcpy(_address, address, sizeof(_address));
  22. }
  23. IPAddress& IPAddress::operator=(const uint8_t *address)
  24. {
  25. memcpy(_address, address, sizeof(_address));
  26. return *this;
  27. }
  28. IPAddress& IPAddress::operator=(uint32_t address)
  29. {
  30. memcpy(_address, (const uint8_t *)&address, sizeof(_address));
  31. return *this;
  32. }
  33. bool IPAddress::operator==(const uint8_t* addr)
  34. {
  35. return memcmp(addr, _address, sizeof(_address)) == 0;
  36. }
  37. size_t IPAddress::printTo(Print& p) const
  38. {
  39. size_t n = 0;
  40. for (int i =0; i < 3; i++)
  41. {
  42. n += p.print(_address[i], DEC);
  43. n += p.print('.');
  44. }
  45. n += p.print(_address[3], DEC);
  46. return n;
  47. }
  48. #endif