2 * Worldvisions IPSec Software:
3 * Copyright (C) 1997-2003 Net Integration Technologies, Inc.
5 * Main routine for WvIPSec.
10 #include "wvconfemu.h"
14 #include "wvistreamlist.h"
24 #define MAX_PACKET_SIZE 65516
26 #define min(a, b) ((a) < (b) ? (a) : (b))
28 static volatile bool want_to_die
= false;
30 const char *argp_program_version
= "wvisakmp -0.5";
31 const char *argp_program_bug_address
= "bugs@nit.ca";
33 "WvIsaKmpTest is a program that does IKE(ISAKMP) negociations.";
35 static struct argp_option options
[] = {
36 {"connection", 'c', "NUM", 0, "Connection to [WvIpSec]Connection NUM"},
37 {"public", 'p', "IPADDR", 0, "Use IPADDR as local IP address"},
38 {"remote", 'r', "HOST", 0, "Connection to remote host" },
39 {"start", 's', 0, 0, "Initiate connection"},
40 {"nostart", 'n', 0, 0, "Do not initiate connection"},
44 void signal_handler(int signum
)
46 fprintf(stderr
, "\nCaught signal %d; cleaning up and terminating.\n",
49 signal(signum
, SIG_DFL
);
52 static error_t
parse_opt (int key
, char *arg
, struct argp_state
*state
)
54 WvConf
*cfg
= static_cast<WvConf
*>(state
->input
);
59 cfg
->set("WvIpSec", "connection", arg
);
62 cfg
->setint("WvIpSec", "start", 1);
65 cfg
->setint("WvIpSec", "start", 0);
69 WvString
connection("connection %s", arg
);
70 cfg
->set("WvIpSec", "connection",
71 cfg
->get("WvIpSec", connection
, NULL
));
75 cfg
->set("WvIpSec", "ipaddr", arg
);
78 wvcon
->print("Unknown option %s\n", arg
);
86 static struct argp argp
= { options
, parse_opt
, 0, doc
};
88 void callback(int spi
, WvCryptoEncoder
*enc
, WvCryptoEncoder
*dec
, WvIsaKmp::actions action
)
90 fprintf(stdout
,"Ready to start ESP Stream stuff...\n");
96 int main(int argc
, char *argv
[])
99 wvcrash_setup(argv
[0]);
101 // make sure electric fence works
104 // set up the signal handlers
105 signal(SIGPIPE
, SIG_IGN
);
106 signal(SIGINT
, signal_handler
);
107 signal(SIGTERM
, signal_handler
);
109 WvConf
cfg("ipsec.ini", 0600);
112 argp_parse(&argp
, argc
, argv
, 0, 0, &cfg
);
116 wverr
->print("WvIsaKmpTest ERROR: This won't work, you're not root!\n");
120 // Set up the bits that we need for WvIsaKmp to do sane things...
121 WvString remote
= cfg
.get("WvIpSec", "connection", "10.1.0.10");
122 WvString local
= cfg
.get("WvIpSec", "ipaddr", "10.2.0.10");
123 bool initiate
= cfg
.getint("WvIpSec", "start", false);
124 WvString shared_secret
= cfg
.get("WvIpSec", "Preshared key", NULL
);
126 WvIsaKmp
conn1(cfg
, initiate
, shared_secret
, local
, remote
);
127 conn1
.set_espcallback(WvIsaKmp::EspCallback(callback
));
128 l
.append(&conn1
, false);
130 // The WvStreamList, l, can't go !isok() unless we force it to, which we
131 // aren't doing so this check is mostly useless, but is good for style.
132 while (conn1
.isok() && l
.isok() && !want_to_die
)
140 wverr
->print("WvIsaKmpTest ERROR: %s", conn1
.errstr().edit());