From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ozgur Akan Subject: argv[optind-1] == optarg Date: Sat, 22 May 2004 21:44:41 +0300 Sender: netfilter-devel-admin@lists.netfilter.org Message-ID: <40AF9F99.7070305@aiqa.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------090101060805010602070006" Return-path: To: "netfilter-devel@lists.netfilter.org" Errors-To: netfilter-devel-admin@lists.netfilter.org List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: List-Id: netfilter-devel.vger.kernel.org This is a multi-part message in MIME format. --------------090101060805010602070006 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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 --------------090101060805010602070006 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit 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
--------------090101060805010602070006--