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

47 行
822B

  1. #include "Arduino.h"
  2. #include "IPAddress.h"
  3. size_t IPAddress::printTo(Print& p) const
  4. {
  5. int i=0;
  6. while (1) {
  7. p.print(_address.bytes[i], DEC);
  8. if (++i >= 4) return 4;
  9. p.write('.');
  10. }
  11. }
  12. bool IPAddress::fromString(const char *address)
  13. {
  14. unsigned int acc = 0; // Accumulator
  15. unsigned int dots = 0;
  16. while (*address) {
  17. char c = *address++;
  18. if (c >= '0' && c <= '9') {
  19. acc = acc * 10 + (c - '0');
  20. if (acc > 255) {
  21. // Value out of [0..255] range
  22. return false;
  23. }
  24. } else if (c == '.') {
  25. if (dots == 3) {
  26. // Too much dots (there must be 3 dots)
  27. return false;
  28. }
  29. _address.bytes[dots++] = acc;
  30. acc = 0;
  31. } else {
  32. // Invalid char
  33. return false;
  34. }
  35. }
  36. if (dots != 3) {
  37. // Too few dots (there must be 3 dots)
  38. return false;
  39. }
  40. _address.bytes[3] = acc;
  41. return true;
  42. }