MCPcopy Create free account
hub / github.com/davidgiven/luje / isValidIPv4Address

Method isValidIPv4Address

lib/java/net/URI.java:638–666  ·  view source on GitHub ↗
(String host)

Source from the content-addressed store, hash-verified

636 }
637
638 private boolean isValidIPv4Address(String host) {
639 int index;
640 int index2;
641 try {
642 int num;
643 index = host.indexOf('.');
644 num = Integer.parseInt(host.substring(0, index));
645 if (num < 0 || num > 255) {
646 return false;
647 }
648 index2 = host.indexOf('.', index + 1);
649 num = Integer.parseInt(host.substring(index + 1, index2));
650 if (num < 0 || num > 255) {
651 return false;
652 }
653 index = host.indexOf('.', index2 + 1);
654 num = Integer.parseInt(host.substring(index2 + 1, index));
655 if (num < 0 || num > 255) {
656 return false;
657 }
658 num = Integer.parseInt(host.substring(index + 1));
659 if (num < 0 || num > 255) {
660 return false;
661 }
662 } catch (Exception e) {
663 return false;
664 }
665 return true;
666 }
667
668 private boolean isValidIP6Address(String ipAddress) {
669 int length = ipAddress.length();

Callers 1

isValidHostMethod · 0.95

Calls 3

parseIntMethod · 0.95
indexOfMethod · 0.65
substringMethod · 0.45

Tested by

no test coverage detected