version 1.1, 2011/10/04 22:37:46
|
version 1.3, 2012/01/23 10:34:12
|
Line 5
|
Line 5
|
* $Author$ |
* $Author$ |
* $Id$ |
* $Id$ |
* |
* |
*************************************************************************/ | ************************************************************************* |
| The ELWIX and AITNET software is distributed under the following |
| terms: |
| |
| All of the documentation and software included in the ELWIX and AITNET |
| Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
| |
| Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
| by Michael Pounov <misho@elwix.org>. All rights reserved. |
| |
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted provided that the following conditions |
| are met: |
| 1. Redistributions of source code must retain the above copyright |
| notice, this list of conditions and the following disclaimer. |
| 2. Redistributions in binary form must reproduce the above copyright |
| notice, this list of conditions and the following disclaimer in the |
| documentation and/or other materials provided with the distribution. |
| 3. All advertising materials mentioning features or use of this software |
| must display the following acknowledgement: |
| This product includes software developed by Michael Pounov <misho@elwix.org> |
| ELWIX - Embedded LightWeight unIX and its contributors. |
| 4. Neither the name of AITNET nor the names of its contributors |
| may be used to endorse or promote products derived from this software |
| without specific prior written permission. |
| |
| THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND |
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| SUCH DAMAGE. |
| */ |
#include "global.h" |
#include "global.h" |
#include "ansh.h" |
#include "ansh.h" |
|
|
|
|
int Timeout, Verbose, Kill, Crypted = 1; | intptr_t Kill; |
| int Timeout, Verbose; |
| u_int Crypted; |
| char Key[STRSIZ]; |
|
|
extern char compiled[], compiledby[], compilehost[]; |
extern char compiled[], compiledby[], compilehost[]; |
|
|
static void |
static void |
Usage() |
Usage() |
{ |
{ |
printf( " -= ansh =- ELWIX Layer3 remote management client over ICMP\n" | printf( " -= ansh3 =- ELWIX Layer3 remote management client over ICMP\n" |
"=== %s === %s@%s ===\n\n" |
"=== %s === %s@%s ===\n\n" |
" Syntax: ansh [options] <connect2host>\n\n" |
" Syntax: ansh [options] <connect2host>\n\n" |
|
"\t-a <address>\tBind to address\n" |
"\t-i <id>\tService ID (default is 42)\n" |
"\t-i <id>\tService ID (default is 42)\n" |
"\t-t <timeout>\tClient session timeout (default is 0 sec)\n" |
"\t-t <timeout>\tClient session timeout (default is 0 sec)\n" |
|
"\t-k <key>\tService cipher key\n" |
"\t-u\t\tSwitch to unencrypted traffic between hosts\n" |
"\t-u\t\tSwitch to unencrypted traffic between hosts\n" |
"\t-v\t\tVerbose (more -v, more verbosity ...)\n" |
"\t-v\t\tVerbose (more -v, more verbosity ...)\n" |
"\t-h\t\tThis help screen!\n" |
"\t-h\t\tThis help screen!\n" |
Line 31 Usage()
|
Line 73 Usage()
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
struct sockaddr sa = { 0 }; | io_sockaddr_t sa, ba; |
struct sockaddr_in *sin4 = (struct sockaddr_in*) &sa; | |
struct sockaddr_in6 *sin6 = (struct sockaddr_in6*) &sa; | |
struct hostent *host; |
struct hostent *host; |
char ch; |
char ch; |
int h, len; |
int h, len; |
u_short id = ANSH_ID; |
u_short id = ANSH_ID; |
|
|
while ((ch = getopt(argc, argv, "hvui:t:")) != -1) | memset(&sa, 0, sizeof sa); |
| memset(&ba, 0, sizeof ba); |
| |
| srandomdev(); |
| do { |
| Crypted = (u_int) random() % UINT_MAX; |
| } while (!Crypted); |
| |
| strlcpy(Key, DEFAULT_KEY, sizeof Key); |
| |
| while ((ch = getopt(argc, argv, "hvui:t:k:a:")) != -1) |
switch (ch) { |
switch (ch) { |
|
case 'a': |
|
host = gethostbyname(optarg); |
|
if (!host) { |
|
printf("Error:: in bind address '%s' #%d - %s\n", |
|
optarg, h_errno, hstrerror(h_errno)); |
|
return 1; |
|
} |
|
switch (host->h_addrtype) { |
|
case AF_INET: |
|
ba.sin.sin_len = sizeof(struct sockaddr_in); |
|
ba.sin.sin_family = AF_INET; |
|
memcpy(&ba.sin.sin_addr.s_addr, host->h_addr, host->h_length); |
|
break; |
|
case AF_INET6: |
|
ba.sin6.sin6_len = sizeof(struct sockaddr_in6); |
|
ba.sin6.sin6_family = AF_INET6; |
|
memcpy(&ba.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; |
|
} |
|
break; |
case 't': |
case 't': |
Timeout = abs(strtol(optarg, NULL, 0)); |
Timeout = abs(strtol(optarg, NULL, 0)); |
break; |
break; |
case 'i': |
case 'i': |
id = strtol(optarg, NULL, 0); |
id = strtol(optarg, NULL, 0); |
break; |
break; |
|
case 'k': |
|
strlcpy(Key, optarg, sizeof Key); |
|
break; |
case 'u': |
case 'u': |
Crypted ^= Crypted; |
Crypted ^= Crypted; |
break; |
break; |
Line 73 main(int argc, char **argv)
|
Line 149 main(int argc, char **argv)
|
} |
} |
switch (host->h_addrtype) { |
switch (host->h_addrtype) { |
case AF_INET: |
case AF_INET: |
sin4->sin_len = sizeof(struct sockaddr_in); | sa.sin.sin_len = sizeof(struct sockaddr_in); |
sin4->sin_family = AF_INET; | sa.sin.sin_family = AF_INET; |
memcpy(&sin4->sin_addr.s_addr, host->h_addr, host->h_length); | memcpy(&sa.sin.sin_addr.s_addr, host->h_addr, host->h_length); |
break; |
break; |
case AF_INET6: |
case AF_INET6: |
sin6->sin6_len = sizeof(struct sockaddr_in6); | sa.sin6.sin6_len = sizeof(struct sockaddr_in6); |
sin6->sin6_family = AF_INET6; | sa.sin6.sin6_family = AF_INET6; |
memcpy(&sin6->sin6_addr.s6_addr, host->h_addr, host->h_length); | memcpy(&sa.sin6.sin6_addr.s6_addr, host->h_addr, host->h_length); |
break; |
break; |
default: |
default: |
printf("Error:: Unknown address type %d !!!\n", host->h_addrtype); |
printf("Error:: Unknown address type %d !!!\n", host->h_addrtype); |
return 1; |
return 1; |
} |
} |
|
|
h = PrepareL3(&sa, &len); | h = PrepareL3(&ba, &len); |
if (h == -1) { |
if (h == -1) { |
printf("Error:: Descriptor not opened ... \n"); |
printf("Error:: Descriptor not opened ... \n"); |
return 1; |
return 1; |
Line 95 main(int argc, char **argv)
|
Line 171 main(int argc, char **argv)
|
|
|
ConnectL3(h, id, &sa, len); |
ConnectL3(h, id, &sa, len); |
|
|
VERB(1) printf("Finish client.\n"); | VERB(1) printf("\r\nFinish client.\r\n"); |
close(h); |
close(h); |
return 0; |
return 0; |
} |
} |