/* Parses ports */ static void parse_ports(const char *arg, struct nf_nat_range *range) { char *end = ""; unsigned int port, maxport; range->flags |= NF_NAT_RANGE_PROTO_SPECIFIED; if (!xtables_strtoui(arg, &end, &port, 0, UINT16_MAX) && (port = xtables_service_to_port(arg, NULL)) == (unsigned)-1) xtables_param_act(XTF_BAD_VALUE, "REDIRECT", "--to-ports", arg); switch (*end) { case '\0': range->min_proto.tcp.port = range->max_proto.tcp.port = htons(port); return; case '-': if (!xtables_strtoui(end + 1, NULL, &maxport, 0, UINT16_MAX) && (maxport = xtables_service_to_port(end + 1, NULL)) == (unsigned)-1) break; if (maxport < port) break; range->min_proto.tcp.port = htons(port); range->max_proto.tcp.port = htons(maxport); return; default: break; } xtables_param_act(XTF_BAD_VALUE, "REDIRECT", "--to-ports", arg); }
uint16_t xtables_parse_port(const char *port, const char *proto) { unsigned int portnum; if (xtables_strtoui(port, NULL, &portnum, 0, UINT16_MAX) || (portnum = xtables_service_to_port(port, proto)) != (unsigned)-1) return portnum; xt_params->exit_err(PARAMETER_PROBLEM, "invalid port/service `%s' specified", port); }
/* Parses ports */ static void parse_ports(const char *arg, struct nf_nat_multi_range *mr) { const char *dash; int port; mr->range[0].flags |= IP_NAT_RANGE_PROTO_SPECIFIED; if (strchr(arg, '.')) xtables_error(PARAMETER_PROBLEM, "IP address not permitted\n"); port = atoi(arg); if (port == 0) port = xtables_service_to_port(arg, NULL); if (port == 0 || port > 65535) xtables_error(PARAMETER_PROBLEM, "Port \"%s\" not valid\n", arg); dash = strchr(arg, '-'); if (!dash) { mr->range[0].min.tcp.port = mr->range[0].max.tcp.port = htons(port); } else { int maxport; maxport = atoi(dash + 1); if (maxport == 0 || maxport > 65535) xtables_error(PARAMETER_PROBLEM, "Port `%s' not valid\n", dash+1); if (maxport < port) /* People are stupid. */ xtables_error(PARAMETER_PROBLEM, "Port range `%s' funky\n", arg); mr->range[0].min.tcp.port = htons(port); mr->range[0].max.tcp.port = htons(maxport); } }