* [PATCH] Add parse_inetaddr and replace inet_addr by parse_inetaddr
@ 2005-11-06 20:39 Krzysztof Oledzki
2005-11-08 2:01 ` Pablo Neira
0 siblings, 1 reply; 2+ messages in thread
From: Krzysztof Oledzki @ 2005-11-06 20:39 UTC (permalink / raw)
To: Pablo Neira; +Cc: netfilter-devel
[-- Attachment #1: Type: TEXT/PLAIN, Size: 430 bytes --]
Hello,
Attached patch adds parse_inetaddr() function and replaces calls to
inet_addr() by parse_inetaddr(). It also fixes the nat_parse() function,
where wrong condition was used for validating addresses.
Conntrack-tool should always notify user about invalid address and
assuming INADDR_NONE, which usually is -1 (255.255.255.255) is not the
right way of handling typos.
Best regards,
Krzysztof Olędzki
[-- Attachment #2: Type: TEXT/PLAIN, Size: 2458 bytes --]
Index: src/conntrack.c
===================================================================
--- src/conntrack.c (revision 4488)
+++ src/conntrack.c (working copy)
@@ -477,6 +477,18 @@
return -1;
}
+in_addr_t parse_inetaddr(const char *cp)
+{
+ struct in_addr addr;
+
+ if (inet_aton(cp, &addr)) {
+ return addr.s_addr;
+ }
+
+ exit_error(PARAMETER_PROBLEM, "Invalid IP address `%s'.", cp);
+
+}
+
/* Shamelessly stolen from libipt_DNAT ;). Ranges expected in network order. */
static void
nat_parse(char *arg, int portok, struct nfct_nat *range)
@@ -536,16 +548,10 @@
if (dash)
*dash = '\0';
- ip = inet_addr(arg);
- if (!ip)
- exit_error(PARAMETER_PROBLEM, "Bad IP address `%s'\n",
- arg);
+ ip = parse_inetaddr(arg);
range->min_ip = ip;
if (dash) {
- ip = inet_addr(dash+1);
- if (!ip)
- exit_error(PARAMETER_PROBLEM, "Bad IP address `%s'\n",
- dash+1);
+ ip = parse_inetaddr(dash+1);
range->max_ip = ip;
} else
range->max_ip = range->min_ip;
@@ -699,22 +705,22 @@
case 's':
options |= CT_OPT_ORIG_SRC;
if (optarg)
- orig.src.v4 = inet_addr(optarg);
+ orig.src.v4 = parse_inetaddr(optarg);
break;
case 'd':
options |= CT_OPT_ORIG_DST;
if (optarg)
- orig.dst.v4 = inet_addr(optarg);
+ orig.dst.v4 = parse_inetaddr(optarg);
break;
case 'r':
options |= CT_OPT_REPL_SRC;
if (optarg)
- reply.src.v4 = inet_addr(optarg);
+ reply.src.v4 = parse_inetaddr(optarg);
break;
case 'q':
options |= CT_OPT_REPL_DST;
if (optarg)
- reply.dst.v4 = inet_addr(optarg);
+ reply.dst.v4 = parse_inetaddr(optarg);
break;
case 'p':
options |= CT_OPT_PROTO;
@@ -751,22 +757,22 @@
case '{':
options |= CT_OPT_MASK_SRC;
if (optarg)
- mask.src.v4 = inet_addr(optarg);
+ mask.src.v4 = parse_inetaddr(optarg);
break;
case '}':
options |= CT_OPT_MASK_DST;
if (optarg)
- mask.dst.v4 = inet_addr(optarg);
+ mask.dst.v4 = parse_inetaddr(optarg);
break;
case '[':
options |= CT_OPT_EXP_SRC;
if (optarg)
- exptuple.src.v4 = inet_addr(optarg);
+ exptuple.src.v4 = parse_inetaddr(optarg);
break;
case ']':
options |= CT_OPT_EXP_DST;
if (optarg)
- exptuple.dst.v4 = inet_addr(optarg);
+ exptuple.dst.v4 = parse_inetaddr(optarg);
break;
case 'a':
options |= CT_OPT_NATRANGE;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Add parse_inetaddr and replace inet_addr by parse_inetaddr
2005-11-06 20:39 [PATCH] Add parse_inetaddr and replace inet_addr by parse_inetaddr Krzysztof Oledzki
@ 2005-11-08 2:01 ` Pablo Neira
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira @ 2005-11-08 2:01 UTC (permalink / raw)
To: Krzysztof Oledzki; +Cc: netfilter-devel
Krzysztof Oledzki wrote:
> Conntrack-tool should always notify user about invalid address and
> assuming INADDR_NONE, which usually is -1 (255.255.255.255) is not the
> right way of handling typos.
Applied, thanks.
--
Pablo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-11-08 2:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-06 20:39 [PATCH] Add parse_inetaddr and replace inet_addr by parse_inetaddr Krzysztof Oledzki
2005-11-08 2:01 ` Pablo Neira
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.