U
ich verwende eigentlich immer getop_long in einer whileschleife.
struct option param_options[] =
{
{"host", required_argument, NULL, 'h'},
{"user", required_argument, NULL, 'u'},
{"password", optional_argument, NULL, 'p'},
{"port", required_argument, NULL, 'P'},
{"socket", required_argument, NULL, 'S'},
{0,0,0,0}
};
char *hostname = NULL;
char *username = NULL;
char *password = NULL;
unsigned int port = 0;
char *socketname = NULL;
int c, i = 0,optionindex = 0;
while((c = getopt_long(argc,argv, "h:p::u:P:S:",
param_options, &optionindex)) != EOF)
{
switch(c)
{
case 'h':
hostname = optarg;
break;
case 'u':
username = optarg;
break;
case 'p':
if (!optarg)
{
password = get_tty_password(NULL);
}
else
{
password = optarg;
}
break;
case 'P':
port = (unsigned int) atoi(optarg);
break;
case 'S':
socketname = optarg;
break;
}
}