/* $Id: cmd_opts.cc,v 1.1 2002/05/02 04:32:20 fygrave Exp $ */
/*
** Copyright (C) 2001 Fyodor Yarochkin <fygrave@tigerteam.net>,
**                    Ofir Arkin       <ofir@sys-security.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** All material for nonprofit, educational use only.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/


#include "xprobe.h"
#include "cmd_opts.h"
#include "interface.h"

extern Interface *ui;


int Cmd_Opts::is_verbose(void) {
    return verbose;
}

unsigned long Cmd_Opts::debug(void) {
    return debuglevel;
}
int Cmd_Opts::get_timeout(void) {
    return receive_timeout;
}
char *Cmd_Opts::get_target(void) {
    return target;
}

char *Cmd_Opts::get_configfile(void) {
    if (config_file)
        return config_file;
   else
       return default_config_file;
}

int Cmd_Opts::parse(int argc, char *argv[]) {
    int c;

    while((c = getopt(argc, argv, "vi:p:ho:t:d:c:")) !=EOF) 
        switch(c) {
            case 'd':
                debuglevel = atol(optarg);
                break;
            case 'v':
                verbose++;
                break;
            case 'o':
                logfile = optarg;    
                break;
            case 'i':
                iname = optarg; 
                break;
            case 'c':
                config_file = optarg; 
                break;
            case 't':
                receive_timeout = atoi(optarg);    
                if (receive_timeout <1) {
                    ui->error("Incorrect receive timeout %s\n", optarg);
                    usage(argv[0]);
                }
                break;
            case 'h':
            default:
                usage(argv[0]);
        }
    
    if (argc < optind + 1)
        usage(argv[0]);
    target = argv[optind];    

return 1;
}

void Cmd_Opts::usage(char *progname) {

    ui->error("usage: %s [-v] [-i int] [-h] [-o fname] [-t timeout] "
                   "[-d debuglv] target\n", progname);
    exit(1);
}

Cmd_Opts::Cmd_Opts(void) {

    receive_timeout = DEF_TIMEOUT;
    verbose = 0;
    flags = 0;
    logfile = NULL;
    config_file = NULL;
    default_config_file = DEFAULT_CONFIG;
    iname = NULL;
    debuglevel = DEFAULT_DEBUG_LEVEL;
    target = NULL;
}
