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

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

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