MCPcopy Create free account
hub / github.com/F-Stack/f-stack / dn_parse_optarg_ipv4

Function dn_parse_optarg_ipv4

freebsd/net/debugnet.c:880–924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

878};
879
880static int
881dn_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
926int
927debugnet_parse_ddb_cmd(const char *cmd, struct debugnet_ddb_config *result)

Callers 1

debugnet_parse_ddb_cmdFunction · 0.85

Calls 2

db_read_token_flagsFunction · 0.85
db_printfFunction · 0.85

Tested by

no test coverage detected