Teensy 4.1 core updated for C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

IPAddress.cpp 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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