File:  [ELWIX - Embedded LightWeight unIX -] / ansh / src / ansh.c
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Tue Oct 4 22:37:46 2011 UTC (12 years, 8 months ago) by misho
Branches: MAIN
CVS tags: HEAD
Initial revision

/*************************************************************************
 * (C) 2011 AITNET - Sofia/Bulgaria - <office@aitnet.org>
 *  by Michael Pounov <misho@elwix.org>
 *
 * $Author: misho $
 * $Id: ansh.c,v 1.1 2011/10/04 22:37:46 misho Exp $
 *
 *************************************************************************/
#include "global.h"
#include "ansh.h"


int Verbose, Kill, Crypted = 1;

extern char compiled[], compiledby[], compilehost[];

static void
Usage()
{
	printf(	" -= ansh =- ELWIX Layer2 remote management client\n"
		"=== %s === %s@%s ===\n\n"
		" Syntax: ansh [options] <connect2host>\n\n"
		"\t-d <dev>\tBind to host interface, like 'em0' (default is first host interface)\n"
		"\t-i <id>\tService ID (default is 42)\n"
		"\t-u\t\tSwitch to unencrypted traffic between hosts\n"
		"\t-v\t\tVerbose (more -v, more verbosity ...)\n"
		"\t-h\t\tThis help screen!\n"
		"\n", compiled, compiledby, compilehost);
}

int
main(int argc, char **argv)
{
	char ch, szDev[STRSIZ] = { 0 };
	int h, len;
	u_short id = ANSH_ID;
	struct ether_addr ea;

	Get1stEth(szDev, STRSIZ);

	while ((ch = getopt(argc, argv, "hvui:d:")) != -1)
		switch (ch) {
			case 'd':
				strlcpy(szDev, optarg, sizeof szDev);
				break;
			case 'i':
				id = strtol(optarg, NULL, 0);
				break;
			case 'u':
				Crypted ^= Crypted;
				break;
			case 'v':
				Verbose++;
				break;
			case 'h':
			default:
				Usage();
				return 1;
		}
	argc -= optind;
	argv += optind;
	if (!argc) {
		printf("Error:: not specified mac for connect ...\n");
		return 1;
	}
	if (!ether_aton_r(argv[0], &ea)) {
		printf("Error:: invalid mac ...\n");
		return 1;
	}

	h = PrepareL2(szDev, &len);
	if (h == -1) {
		printf("Error:: Descriptor not opened ... \n");
		return 1;
	}

	ConnectL2(h, id, &ea, len);

	VERB(1) printf("Finish client.\n");
	close(h);
	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>