Java IP Address Mash checkIpMaskPart(String part)

Here you can find the source of checkIpMaskPart(String part)

Description

check Ip Mask Part

License

Open Source License

Declaration

private static String checkIpMaskPart(String part) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static String checkIpMaskPart(String part) {
        int dash;
        if ("*".equals(part))
            return null;
        dash = part.indexOf('-');
        if (dash == -1) {
            int value = Integer.parseInt(part);
            if (value < 0 || value > 255)
                return (new StringBuilder()).append("Value out of range in '").append(part).append("'").toString();
            //break MISSING_BLOCK_LABEL_219;
        }/*from  w  w  w. j  ava2 s  .c  o  m*/
        int from;
        from = Integer.parseInt(part.substring(0, dash));
        if (from < 0 || from > 255)
            return (new StringBuilder()).append("'From' value out of range in '").append(part).append("'")
                    .toString();
        int to;
        try {
            to = Integer.parseInt(part.substring(dash + 1));
            if (to < 0 || to > 255)
                return (new StringBuilder()).append("'To' value out of range in '").append(part).append("'")
                        .toString();
        } catch (NumberFormatException e) {
            return (new StringBuilder()).append("Integer parsing error in '").append(part).append("'").toString();
        }
        if (from > to)
            return (new StringBuilder()).append("'From' value is greater than 'To' value in '").append(part)
                    .append("'").toString();
        return null;
    }
}

Related

  1. checkIpMask(String ip)
  2. checkIpMaskPart(String part)