| 878 | }; |
| 879 | |
| 880 | static int |
| 881 | dn_parse_optarg_ipv4(struct my_inet_opt *opt) |
| 882 | { |
| 883 | in_addr_t tmp; |
| 884 | unsigned octet; |
| 885 | int t; |
| 886 | |
| 887 | tmp = 0; |
| 888 | for (octet = 0; octet < 4; octet++) { |
| 889 | t = db_read_token_flags(DRT_WSPACE | DRT_DECIMAL); |
| 890 | if (t != tNUMBER) { |
| 891 | db_printf("%s:%s: octet %u expected number; found %d\n", |
| 892 | __func__, opt->printname, octet, t); |
| 893 | return (EINVAL); |
| 894 | } |
| 895 | /* |
| 896 | * db_lex lexes '-' distinctly from the number itself, but |
| 897 | * let's document that invariant. |
| 898 | */ |
| 899 | MPASS(db_tok_number >= 0); |
| 900 | |
| 901 | if (db_tok_number > UINT8_MAX) { |
| 902 | db_printf("%s:%s: octet %u out of range: %jd\n", __func__, |
| 903 | opt->printname, octet, (intmax_t)db_tok_number); |
| 904 | return (EDOM); |
| 905 | } |
| 906 | |
| 907 | /* Constructed host-endian and converted to network later. */ |
| 908 | tmp = (tmp << 8) | db_tok_number; |
| 909 | |
| 910 | if (octet < 3) { |
| 911 | t = db_read_token_flags(DRT_WSPACE); |
| 912 | if (t != tDOT) { |
| 913 | db_printf("%s:%s: octet %u expected '.'; found" |
| 914 | " %d\n", __func__, opt->printname, octet, |
| 915 | t); |
| 916 | return (EINVAL); |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | *opt->result = htonl(tmp); |
| 922 | opt->has_opt = true; |
| 923 | return (0); |
| 924 | } |
| 925 | |
| 926 | int |
| 927 | debugnet_parse_ddb_cmd(const char *cmd, struct debugnet_ddb_config *result) |
no test coverage detected