add dump file option to snifftest, along with keyfile, optional server and port arguments

This commit is contained in:
toddouska
2012-05-20 12:46:50 -07:00
parent ba6d956d02
commit 2b6044c6ee

View File

@ -128,6 +128,9 @@ int main(int argc, char** argv)
#endif
ssl_Trace("./tracefile.txt", err);
if (argc == 1) {
/* normal case, user chooses device and port */
if (pcap_findalldevs(&alldevs, err) == -1)
err_sys("Error in pcap_findalldevs");
@ -140,8 +143,8 @@ int main(int argc, char** argv)
}
if (i == 0)
err_sys("No interfaces found! Make sure pcap or WinPcap is installed "
"correctly and you have sufficient permissions");
err_sys("No interfaces found! Make sure pcap or WinPcap is"
" installed correctly and you have sufficient permissions");
printf("Enter the interface number (1-%d): ", i);
scanf("%d", &inum);
@ -164,7 +167,8 @@ int main(int argc, char** argv)
switch(a->addr->sa_family)
{
case AF_INET:
server =iptos(((struct sockaddr_in *)a->addr)->sin_addr.s_addr);
server =
iptos(((struct sockaddr_in *)a->addr)->sin_addr.s_addr);
printf("server = %s\n", server);
break;
}
@ -202,6 +206,35 @@ int main(int argc, char** argv)
ret = ssl_SetPrivateKey(server, port, "../../certs/server-key.pem",
FILETYPE_PEM, NULL, err);
}
else if (argc >= 3) {
pcap = pcap_open_offline(argv[1], err);
if (pcap == NULL) {
printf("pcap_open_offline failed %s\n", err);
ret = -1;
}
else {
/* defaults for server and port */
port = 443;
server = "127.0.0.1";
if (argc >= 4)
server = argv[3];
if (argc >= 5)
port = atoi(argv[4]);
ret = ssl_SetPrivateKey(server, port, argv[2],
FILETYPE_PEM, NULL, err);
}
}
else {
/* usage error */
printf(
"usage: ./snifftest or ./snifftest dump pemKey [server] [port]\n");
exit(EXIT_FAILURE);
}
if (ret != 0)
err_sys(err);