I think the fix is as simple as setting "optind = 1;" before the getopt loop. Does that work for you?