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

Function fill_newports

tools/ipfw/ipfw2.c:1005–1049  ·  view source on GitHub ↗

* Fill the body of the command with the list of port ranges. */

Source from the content-addressed store, hash-verified

1003 * Fill the body of the command with the list of port ranges.
1004 */
1005static int
1006fill_newports(ipfw_insn_u16 *cmd, char *av, int proto, int cblen)
1007{
1008 uint16_t a, b, *p = cmd->ports;
1009 int i = 0;
1010 char *s = av;
1011
1012 while (*s) {
1013 a = strtoport(av, &s, 0, proto);
1014 if (s == av) /* empty or invalid argument */
1015 return (0);
1016
1017 CHECK_LENGTH(cblen, i + 2);
1018
1019 switch (*s) {
1020 case '-': /* a range */
1021 av = s + 1;
1022 b = strtoport(av, &s, 0, proto);
1023 /* Reject expressions like '1-abc' or '1-2-3'. */
1024 if (s == av || (*s != ',' && *s != '\0'))
1025 return (0);
1026 p[0] = a;
1027 p[1] = b;
1028 break;
1029 case ',': /* comma separated list */
1030 case '\0':
1031 p[0] = p[1] = a;
1032 break;
1033 default:
1034 warnx("port list: invalid separator <%c> in <%s>",
1035 *s, av);
1036 return (0);
1037 }
1038
1039 i++;
1040 p += 2;
1041 av = s + 1;
1042 }
1043 if (i > 0) {
1044 if (i + 1 > F_LEN_MASK)
1045 errx(EX_DATAERR, "too many ports/ranges\n");
1046 cmd->o.len |= i + 1; /* leave F_NOT and F_OR untouched */
1047 }
1048 return (i);
1049}
1050
1051/*
1052 * Fill the body of the command with the list of DiffServ codepoints.

Callers 2

add_mactypeFunction · 0.85
add_portsFunction · 0.85

Calls 1

strtoportFunction · 0.85

Tested by

no test coverage detected