File:  [ELWIX - Embedded LightWeight unIX -] / ansh / src / ansh.c
Revision 1.1.1.1.2.2: download - view: text, annotated - select for diffs - revision graph
Mon Oct 10 07:50:18 2011 UTC (12 years, 9 months ago) by misho
Branches: ansh1_0
Diff to: branchpoint 1.1.1.1: preferred, unified
move changes

    1: /*************************************************************************
    2:  * (C) 2011 AITNET - Sofia/Bulgaria - <office@aitnet.org>
    3:  *  by Michael Pounov <misho@elwix.org>
    4:  *
    5:  * $Author: misho $
    6:  * $Id: ansh.c,v 1.1.1.1.2.2 2011/10/10 07:50:18 misho Exp $
    7:  *
    8:  *************************************************************************/
    9: #include "global.h"
   10: #include "ansh.h"
   11: 
   12: 
   13: int Timeout, Verbose, Kill;
   14: u_int Crypted;
   15: 
   16: extern char compiled[], compiledby[], compilehost[];
   17: 
   18: static void
   19: Usage()
   20: {
   21: 	printf(	" -= ansh =- ELWIX Layer2 remote management client\n"
   22: 		"=== %s === %s@%s ===\n\n"
   23: 		" Syntax: ansh [options] <connect2host>\n\n"
   24: 		"\t-d <dev>\tBind to host interface, like 'em0' (default is first host interface)\n"
   25: 		"\t-i <id>\tService ID (default is 42)\n"
   26: 		"\t-t <timeout>\tClient session timeout (default is 0 sec)\n"
   27: 		"\t-u\t\tSwitch to unencrypted traffic between hosts\n"
   28: 		"\t-v\t\tVerbose (more -v, more verbosity ...)\n"
   29: 		"\t-h\t\tThis help screen!\n"
   30: 		"\n", compiled, compiledby, compilehost);
   31: }
   32: 
   33: int
   34: main(int argc, char **argv)
   35: {
   36: 	char ch, szDev[STRSIZ] = { 0 };
   37: 	int h, len;
   38: 	u_short id = ANSH_ID;
   39: 	struct ether_addr ea;
   40: 
   41: 	srandomdev();
   42: 	do {
   43: 		Crypted = (u_int) random() % UINT_MAX;
   44: 	} while (!Crypted);
   45: 
   46: 	Get1stEth(szDev, STRSIZ);
   47: 
   48: 	while ((ch = getopt(argc, argv, "hvui:t:d:")) != -1)
   49: 		switch (ch) {
   50: 			case 't':
   51: 				Timeout = abs(strtol(optarg, NULL, 0));
   52: 				break;
   53: 			case 'd':
   54: 				strlcpy(szDev, optarg, sizeof szDev);
   55: 				break;
   56: 			case 'i':
   57: 				id = strtol(optarg, NULL, 0);
   58: 				break;
   59: 			case 'u':
   60: 				Crypted ^= Crypted;
   61: 				break;
   62: 			case 'v':
   63: 				Verbose++;
   64: 				break;
   65: 			case 'h':
   66: 			default:
   67: 				Usage();
   68: 				return 1;
   69: 		}
   70: 	argc -= optind;
   71: 	argv += optind;
   72: 	if (!argc) {
   73: 		printf("Error:: not specified mac for connect ...\n");
   74: 		return 1;
   75: 	}
   76: 	if (!ether_aton_r(argv[0], &ea)) {
   77: 		printf("Error:: invalid mac ...\n");
   78: 		return 1;
   79: 	}
   80: 
   81: 	h = PrepareL2(szDev, &len);
   82: 	if (h == -1) {
   83: 		printf("Error:: Descriptor not opened ... \n");
   84: 		return 1;
   85: 	}
   86: 
   87: 	ConnectL2(h, id, &ea, len);
   88: 
   89: 	VERB(1) printf("Finish client.\n");
   90: 	close(h);
   91: 	return 0;
   92: }

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