Annotation of ansh/src/ansh.c, revision 1.1.1.1.2.4

1.1       misho       1: /*************************************************************************
                      2:  * (C) 2011 AITNET - Sofia/Bulgaria - <office@aitnet.org>
                      3:  *  by Michael Pounov <misho@elwix.org>
                      4:  *
                      5:  * $Author: misho $
1.1.1.1.2.4! misho       6:  * $Id: ansh.c,v 1.1.1.1.2.3 2011/10/10 13:56:30 misho Exp $
1.1       misho       7:  *
                      8:  *************************************************************************/
                      9: #include "global.h"
                     10: #include "ansh.h"
                     11: 
                     12: 
1.1.1.1.2.2  misho      13: int Timeout, Verbose, Kill;
1.1.1.1.2.1  misho      14: u_int Crypted;
1.1       misho      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"
1.1.1.1.2.2  misho      25:                "\t-t <timeout>\tClient session timeout (default is 0 sec)\n"
1.1       misho      26:                "\t-u\t\tSwitch to unencrypted traffic between hosts\n"
                     27:                "\t-v\t\tVerbose (more -v, more verbosity ...)\n"
                     28:                "\t-h\t\tThis help screen!\n"
                     29:                "\n", compiled, compiledby, compilehost);
                     30: }
                     31: 
                     32: int
                     33: main(int argc, char **argv)
                     34: {
                     35:        char ch, szDev[STRSIZ] = { 0 };
                     36:        int h, len;
                     37:        struct ether_addr ea;
                     38: 
1.1.1.1.2.2  misho      39:        srandomdev();
                     40:        do {
                     41:                Crypted = (u_int) random() % UINT_MAX;
                     42:        } while (!Crypted);
                     43: 
1.1       misho      44:        Get1stEth(szDev, STRSIZ);
                     45: 
1.1.1.1.2.3  misho      46:        while ((ch = getopt(argc, argv, "hvut:d:")) != -1)
1.1       misho      47:                switch (ch) {
1.1.1.1.2.2  misho      48:                        case 't':
                     49:                                Timeout = abs(strtol(optarg, NULL, 0));
                     50:                                break;
1.1       misho      51:                        case 'd':
                     52:                                strlcpy(szDev, optarg, sizeof szDev);
                     53:                                break;
                     54:                        case 'u':
                     55:                                Crypted ^= Crypted;
                     56:                                break;
                     57:                        case 'v':
                     58:                                Verbose++;
                     59:                                break;
                     60:                        case 'h':
                     61:                        default:
                     62:                                Usage();
                     63:                                return 1;
                     64:                }
                     65:        argc -= optind;
                     66:        argv += optind;
                     67:        if (!argc) {
                     68:                printf("Error:: not specified mac for connect ...\n");
                     69:                return 1;
                     70:        }
                     71:        if (!ether_aton_r(argv[0], &ea)) {
                     72:                printf("Error:: invalid mac ...\n");
                     73:                return 1;
                     74:        }
                     75: 
                     76:        h = PrepareL2(szDev, &len);
                     77:        if (h == -1) {
                     78:                printf("Error:: Descriptor not opened ... \n");
                     79:                return 1;
                     80:        }
                     81: 
1.1.1.1.2.3  misho      82:        ConnectL2(h, &ea, len);
1.1       misho      83: 
1.1.1.1.2.4! misho      84:        VERB(1) printf("\r\nFinish client.\r\n");
1.1       misho      85:        close(h);
                     86:        return 0;
                     87: }

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