Annotation of ansh/src/ansh3.c, revision 1.1.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 Timeout, Verbose, Kill, Crypted = 1;
                     14: 
                     15: extern char compiled[], compiledby[], compilehost[];
                     16: 
                     17: static void
                     18: Usage()
                     19: {
                     20:        printf( " -= ansh =- ELWIX Layer3 remote management client over ICMP\n"
                     21:                "=== %s === %s@%s ===\n\n"
                     22:                " Syntax: ansh [options] <connect2host>\n\n"
                     23:                "\t-i <id>\tService ID (default is 42)\n"
                     24:                "\t-t <timeout>\tClient session timeout (default is 0 sec)\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:        struct sockaddr sa = { 0 };
                     35:        struct sockaddr_in *sin4 = (struct sockaddr_in*) &sa;
                     36:        struct sockaddr_in6 *sin6 = (struct sockaddr_in6*) &sa;
                     37:        struct hostent *host;
                     38:        char ch;
                     39:        int h, len;
                     40:        u_short id = ANSH_ID;
                     41: 
                     42:        while ((ch = getopt(argc, argv, "hvui:t:")) != -1)
                     43:                switch (ch) {
                     44:                        case 't':
                     45:                                Timeout = abs(strtol(optarg, NULL, 0));
                     46:                                break;
                     47:                        case 'i':
                     48:                                id = strtol(optarg, NULL, 0);
                     49:                                break;
                     50:                        case 'u':
                     51:                                Crypted ^= Crypted;
                     52:                                break;
                     53:                        case 'v':
                     54:                                Verbose++;
                     55:                                break;
                     56:                        case 'h':
                     57:                        default:
                     58:                                Usage();
                     59:                                return 1;
                     60:                }
                     61:        argc -= optind;
                     62:        argv += optind;
                     63:        if (!argc) {
                     64:                printf("Error:: not specified address for connect ...\n");
                     65:                return 1;
                     66:        }
                     67: 
                     68:        host = gethostbyname(argv[0]);
                     69:        if (!host) {
                     70:                printf("Error:: in bind address '%s' #%d - %s\n",
                     71:                                argv[0], h_errno, hstrerror(h_errno));
                     72:                return 1;
                     73:        }
                     74:        switch (host->h_addrtype) {
                     75:                case AF_INET:
                     76:                        sin4->sin_len = sizeof(struct sockaddr_in);
                     77:                        sin4->sin_family = AF_INET;
                     78:                        memcpy(&sin4->sin_addr.s_addr, host->h_addr, host->h_length);
                     79:                        break;
                     80:                case AF_INET6:
                     81:                        sin6->sin6_len = sizeof(struct sockaddr_in6);
                     82:                        sin6->sin6_family = AF_INET6;
                     83:                        memcpy(&sin6->sin6_addr.s6_addr, host->h_addr, host->h_length);
                     84:                        break;
                     85:                default:
                     86:                        printf("Error:: Unknown address type %d !!!\n", host->h_addrtype);
                     87:                        return 1;
                     88:        }
                     89: 
                     90:        h = PrepareL3(&sa, &len);
                     91:        if (h == -1) {
                     92:                printf("Error:: Descriptor not opened ... \n");
                     93:                return 1;
                     94:        }
                     95: 
                     96:        ConnectL3(h, id, &sa, len);
                     97: 
                     98:        VERB(1) printf("Finish client.\n");
                     99:        close(h);
                    100:        return 0;
                    101: }

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