/*
 * Copyright (c) 1996-2007, OpenFWTK Development Group
 * All rights reserved. See LICENSE.
 */

#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "firewall2.h"

char* xstrdup(const char*);
int auth_console(char host_addr[], char user_name[]);
int auth_login(char hostaddr[]);
static char* hostaddr = NULL;
static char* Prog;
static struct sockaddr_in from;
char* ip2name(struct in_addr);
void ShowUsage()
{
  printf("Usage: %s -h <client's hostaddr>\n", Prog);
} 

int
main(int argc, char **argv)
{
	int c;
	const char *args = ":a:n:h:";

	Prog = xstrdup(argv[0]);
	
	while ((c = getopt(argc, argv, args)) != -1)
	{
		switch (c)
		{
		  case ':':
		    fprintf(stderr, "Illegal parameter\n");
		    ShowUsage();
		    exit(1);
		    break;
		  case '?':
		    fprintf(stderr, "Unknown parameter.\n");
		    ShowUsage();
		    exit(1);
		    break;
		  case 'h':
			if (optarg == NULL || *optarg == '\0')
			{
				fprintf(stderr, "Illegal hostaddr parameter.\n");
		                ShowUsage();
				exit(1);
			}
			hostaddr = optarg;
			break;
		}
	}

	if(hostaddr == NULL)
	{
	  ShowUsage();
	  exit(1);
	}
 from.sin_addr.s_addr = inet_addr(hostaddr);
 strlcpy(proxy_stats.riaddr, hostaddr, sizeof(proxy_stats.riaddr));
 strlcpy(proxy_stats.rladdr, ip2name(from.sin_addr), sizeof(proxy_stats.rladdr));
 
 auth_login(hostaddr);
 return 0;
}

