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

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.2! misho       6:  * $Id: ansh.c,v 1.1.1.1.2.1 2011/10/07 13:41:26 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"
                     25:                "\t-i <id>\tService ID (default is 42)\n"
1.1.1.1.2.2! misho      26:                "\t-t <timeout>\tClient session timeout (default is 0 sec)\n"
1.1       misho      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: 
1.1.1.1.2.2! misho      41:        srandomdev();
        !            42:        do {
        !            43:                Crypted = (u_int) random() % UINT_MAX;
        !            44:        } while (!Crypted);
        !            45: 
1.1       misho      46:        Get1stEth(szDev, STRSIZ);
                     47: 
1.1.1.1.2.2! misho      48:        while ((ch = getopt(argc, argv, "hvui:t:d:")) != -1)
1.1       misho      49:                switch (ch) {
1.1.1.1.2.2! misho      50:                        case 't':
        !            51:                                Timeout = abs(strtol(optarg, NULL, 0));
        !            52:                                break;
1.1       misho      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>