/************************************************************************* * (C) 2011 AITNET - Sofia/Bulgaria - * by Michael Pounov * * $Author: misho $ * $Id: ansh3.c,v 1.1 2011/10/04 22:37:46 misho Exp $ * *************************************************************************/ #include "global.h" #include "ansh.h" int Timeout, Verbose, Kill, Crypted = 1; extern char compiled[], compiledby[], compilehost[]; static void Usage() { printf( " -= ansh =- ELWIX Layer3 remote management client over ICMP\n" "=== %s === %s@%s ===\n\n" " Syntax: ansh [options] \n\n" "\t-i \tService ID (default is 42)\n" "\t-t \tClient session timeout (default is 0 sec)\n" "\t-u\t\tSwitch to unencrypted traffic between hosts\n" "\t-v\t\tVerbose (more -v, more verbosity ...)\n" "\t-h\t\tThis help screen!\n" "\n", compiled, compiledby, compilehost); } int main(int argc, char **argv) { struct sockaddr sa = { 0 }; struct sockaddr_in *sin4 = (struct sockaddr_in*) &sa; struct sockaddr_in6 *sin6 = (struct sockaddr_in6*) &sa; struct hostent *host; char ch; int h, len; u_short id = ANSH_ID; while ((ch = getopt(argc, argv, "hvui:t:")) != -1) switch (ch) { case 't': Timeout = abs(strtol(optarg, NULL, 0)); break; case 'i': id = strtol(optarg, NULL, 0); break; case 'u': Crypted ^= Crypted; break; case 'v': Verbose++; break; case 'h': default: Usage(); return 1; } argc -= optind; argv += optind; if (!argc) { printf("Error:: not specified address for connect ...\n"); return 1; } host = gethostbyname(argv[0]); if (!host) { printf("Error:: in bind address '%s' #%d - %s\n", argv[0], h_errno, hstrerror(h_errno)); return 1; } switch (host->h_addrtype) { case AF_INET: sin4->sin_len = sizeof(struct sockaddr_in); sin4->sin_family = AF_INET; memcpy(&sin4->sin_addr.s_addr, host->h_addr, host->h_length); break; case AF_INET6: sin6->sin6_len = sizeof(struct sockaddr_in6); sin6->sin6_family = AF_INET6; memcpy(&sin6->sin6_addr.s6_addr, host->h_addr, host->h_length); break; default: printf("Error:: Unknown address type %d !!!\n", host->h_addrtype); return 1; } h = PrepareL3(&sa, &len); if (h == -1) { printf("Error:: Descriptor not opened ... \n"); return 1; } ConnectL3(h, id, &sa, len); VERB(1) printf("Finish client.\n"); close(h); return 0; }