Browse Source

[2272] Check for HAVE_OPTRESET in the perfdhcp command options.

Marcin Siodelski 12 years ago
parent
commit
3dc84c3cc2
1 changed files with 9 additions and 0 deletions
  1. 9 0
      tests/tools/perfdhcp/command_options.cc

+ 9 - 0
tests/tools/perfdhcp/command_options.cc

@@ -113,6 +113,15 @@ CommandOptions::parse(int argc, char** const argv) {
     optind = 1;
 #endif
 
+    // optreset is declared on BSD systems and is used to reset internal
+    // state of getopt(). When parsing command line arguments multiple
+    // times with getopt() the optreset must be set to 1 every time before
+    // parsing starts. Failing to do so will result in random behavior of
+    // getopt().
+#ifdef HAVE_OPTRESET
+    optreset = 1;
+#endif
+
     opterr = 0;
 
     // Reset values of class members