* argv[optind-1] == optarg
@ 2004-05-22 18:44 Ozgur Akan
2004-05-24 5:26 ` Ozgur Akan
2004-05-25 19:24 ` Henrik Nordstrom
0 siblings, 2 replies; 4+ messages in thread
From: Ozgur Akan @ 2004-05-22 18:44 UTC (permalink / raw)
To: netfilter-devel@lists.netfilter.org
[-- Attachment #1: Type: text/plain, Size: 656 bytes --]
Hi,
I think using optarg instead of argv[optind-1] will be better. In
iptables.c; while parsing iptables options with getopt_long,
argv[optind-1] is used in 8 places.
optarg (option argument) gives us the value of the option we are
parsing. So when we do something with the argument of (for example) A
option the easiest way to get the value of A`s argument is using optarg.
optarg is designed to be used with getopt_long.
Using optind (option index) is more tricky because optind starts from 1
and when we are parsing an option with an index of value n of argv array
it shows n+2. That`s why we substract 1 from optind.
best wishes,
Ozgur Akan
[-- Attachment #2: Type: text/html, Size: 1117 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: argv[optind-1] == optarg
2004-05-22 18:44 argv[optind-1] == optarg Ozgur Akan
@ 2004-05-24 5:26 ` Ozgur Akan
2004-05-25 19:24 ` Henrik Nordstrom
1 sibling, 0 replies; 4+ messages in thread
From: Ozgur Akan @ 2004-05-24 5:26 UTC (permalink / raw)
To: netfilter-devel@lists.netfilter.org, Harald Welte
[-- Attachment #1.1: Type: text/plain, Size: 823 bytes --]
Hi,
I attached the patch file for optarg. It includes patches for iptables.c
and ip6tables.c.
regards,
Ozgur Akan
Ozgur Akan wrote:
> Hi,
>
> I think using optarg instead of argv[optind-1] will be better. In
> iptables.c; while parsing iptables options with getopt_long,
> argv[optind-1] is used in 8 places.
>
> optarg (option argument) gives us the value of the option we are
> parsing. So when we do something with the argument of (for example) A
> option the easiest way to get the value of A`s argument is using
> optarg. optarg is designed to be used with getopt_long.
>
> Using optind (option index) is more tricky because optind starts from
> 1 and when we are parsing an option with an index of value n of argv
> array it shows n+2. That`s why we substract 1 from optind.
>
> best wishes,
> Ozgur Akan
[-- Attachment #1.2: Type: text/html, Size: 1440 bytes --]
[-- Attachment #2: optarg.PATCH --]
[-- Type: text/plain, Size: 4091 bytes --]
diff -Naur iptables/ip6tables.c iptables_dev/ip6tables.c
--- iptables/ip6tables.c 2004-05-24 08:07:59.782220912 +0300
+++ iptables_dev/ip6tables.c 2004-05-24 08:16:48.830793304 +0300
@@ -1853,10 +1853,10 @@
invert);
/* Canonicalize into lower case */
- for (protocol = argv[optind-1]; *protocol; protocol++)
+ for (protocol = optarg; *protocol; protocol++)
*protocol = tolower(*protocol);
- protocol = argv[optind-1];
+ protocol = optarg;
if ( strcmp(protocol,"ipv6-icmp") == 0)
protocol = icmp6p;
fw.ipv6.proto = parse_protocol(protocol);
@@ -1873,7 +1873,7 @@
check_inverse(optarg, &invert, &optind, argc);
set_option(&options, OPT_SOURCE, &fw.ipv6.invflags,
invert);
- shostnetworkmask = argv[optind-1];
+ shostnetworkmask = optarg;
fw.nfcache |= NFC_IP6_SRC;
break;
@@ -1881,7 +1881,7 @@
check_inverse(optarg, &invert, &optind, argc);
set_option(&options, OPT_DESTINATION, &fw.ipv6.invflags,
invert);
- dhostnetworkmask = argv[optind-1];
+ dhostnetworkmask = optarg;
fw.nfcache |= NFC_IP6_DST;
break;
@@ -1911,7 +1911,7 @@
check_inverse(optarg, &invert, &optind, argc);
set_option(&options, OPT_VIANAMEIN, &fw.ipv6.invflags,
invert);
- parse_interface(argv[optind-1],
+ parse_interface(optarg,
fw.ipv6.iniface,
fw.ipv6.iniface_mask);
fw.nfcache |= NFC_IP6_IF_IN;
@@ -1921,7 +1921,7 @@
check_inverse(optarg, &invert, &optind, argc);
set_option(&options, OPT_VIANAMEOUT, &fw.ipv6.invflags,
invert);
- parse_interface(argv[optind-1],
+ parse_interface(optarg,
fw.ipv6.outiface,
fw.ipv6.outiface_mask);
fw.nfcache |= NFC_IP6_IF_OUT;
@@ -1961,7 +1961,7 @@
if (invert)
exit_error(PARAMETER_PROBLEM,
"unexpected ! flag before --table");
- *table = argv[optind-1];
+ *table = optarg;
break;
case 'x':
@@ -2100,7 +2100,7 @@
if (!m)
exit_error(PARAMETER_PROBLEM,
"Unknown arg `%s'",
- argv[optind-1]);
+ optarg);
}
}
invert = FALSE;
diff -Naur iptables/iptables.c iptables_dev/iptables.c
--- iptables/iptables.c 2004-05-24 08:08:00.804065568 +0300
+++ iptables_dev/iptables.c 2004-05-24 08:11:02.797398376 +0300
@@ -1850,10 +1850,10 @@
invert);
/* Canonicalize into lower case */
- for (protocol = argv[optind-1]; *protocol; protocol++)
+ for (protocol = optard; *protocol; protocol++)
*protocol = tolower(*protocol);
- protocol = argv[optind-1];
+ protocol = optarg;
fw.ip.proto = parse_protocol(protocol);
if (fw.ip.proto == 0
@@ -1867,7 +1867,7 @@
check_inverse(optarg, &invert, &optind, argc);
set_option(&options, OPT_SOURCE, &fw.ip.invflags,
invert);
- shostnetworkmask = argv[optind-1];
+ shostnetworkmask = optarg;
fw.nfcache |= NFC_IP_SRC;
break;
@@ -1875,7 +1875,7 @@
check_inverse(optarg, &invert, &optind, argc);
set_option(&options, OPT_DESTINATION, &fw.ip.invflags,
invert);
- dhostnetworkmask = argv[optind-1];
+ dhostnetworkmask = optarg;
fw.nfcache |= NFC_IP_DST;
break;
@@ -1905,7 +1905,7 @@
check_inverse(optarg, &invert, &optind, argc);
set_option(&options, OPT_VIANAMEIN, &fw.ip.invflags,
invert);
- parse_interface(argv[optind-1],
+ parse_interface(optarg,
fw.ip.iniface,
fw.ip.iniface_mask);
fw.nfcache |= NFC_IP_IF_IN;
@@ -1915,7 +1915,7 @@
check_inverse(optarg, &invert, &optind, argc);
set_option(&options, OPT_VIANAMEOUT, &fw.ip.invflags,
invert);
- parse_interface(argv[optind-1],
+ parse_interface(optarg,
fw.ip.outiface,
fw.ip.outiface_mask);
fw.nfcache |= NFC_IP_IF_OUT;
@@ -1962,7 +1962,7 @@
if (invert)
exit_error(PARAMETER_PROBLEM,
"unexpected ! flag before --table");
- *table = argv[optind-1];
+ *table = optarg;
break;
case 'x':
@@ -2100,7 +2100,7 @@
if (!m)
exit_error(PARAMETER_PROBLEM,
"Unknown arg `%s'",
- argv[optind-1]);
+ optarg);
}
}
invert = FALSE;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: argv[optind-1] == optarg
2004-05-22 18:44 argv[optind-1] == optarg Ozgur Akan
2004-05-24 5:26 ` Ozgur Akan
@ 2004-05-25 19:24 ` Henrik Nordstrom
2004-05-26 13:00 ` Ozgur Akan
1 sibling, 1 reply; 4+ messages in thread
From: Henrik Nordstrom @ 2004-05-25 19:24 UTC (permalink / raw)
To: Ozgur Akan; +Cc: netfilter-devel@lists.netfilter.org
On Sat, 22 May 2004, Ozgur Akan wrote:
> I think using optarg instead of argv[optind-1] will be better. In
> iptables.c; while parsing iptables options with getopt_long,
> argv[optind-1] is used in 8 places.
If I recall correectly the reason why it is done the way it is is the
processing of ! (not).
! -d a.b.c.d
-d ! a.b.c.d
Regards
Henrik
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: argv[optind-1] == optarg
2004-05-25 19:24 ` Henrik Nordstrom
@ 2004-05-26 13:00 ` Ozgur Akan
0 siblings, 0 replies; 4+ messages in thread
From: Ozgur Akan @ 2004-05-26 13:00 UTC (permalink / raw)
To: Henrik Nordstrom; +Cc: netfilter-devel@lists.netfilter.org
> ! -d a.b.c.d
> -d ! a.b.c.d
>
>
...hmm, I am going to work on it.
thanks,
Ozgur Akan
--
Ozgur Akan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-05-26 13:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-22 18:44 argv[optind-1] == optarg Ozgur Akan
2004-05-24 5:26 ` Ozgur Akan
2004-05-25 19:24 ` Henrik Nordstrom
2004-05-26 13:00 ` Ozgur Akan
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.