2323#include "tcpkit.h"
2424#include "server.h"
2525
26+
2627struct server * srv ;
2728
29+ const char * VERSION = "1.1.0" ;
30+
2831void signal_handler (int sig ) {
2932 if (sig == SIGINT || sig == SIGTERM ) {
3033 server_terminate (srv );
@@ -34,6 +37,7 @@ void signal_handler(int sig) {
3437void usage () {
3538 const char * usage_literal = ""
3639 "the tcpkit was designed to make network packets programable with LUA by @git-hulk\n"
40+ " version: %s\n"
3741 " -h, Print the tcpkit version strings, print a usage message, and exit\n"
3842 " -i interface, Listen on network card interface\n"
3943 " -A Print each packet (minus its link level header) in ASCII. Handy for capturing web pages.\n"
@@ -50,7 +54,7 @@ void usage() {
5054 " `tcpkit -i eth0 tcp port 6379 -p redis` was used to monitor the redis reqeust latency\n\n"
5155 " `tcpkit -i eth0 tcp port 6379 -p redis -w 6379.pcap` would also dump the packets to `6379.pcap`\n\n"
5256 " `tcpkit -i eth0 tcp port 6379 -p redis -t 10` would only print the request latency slower than 10ms\n" ;
53- color_printf (GREEN , "%s\n" , usage_literal );
57+ color_printf (GREEN , usage_literal , VERSION );
5458 exit (0 );
5559}
5660
@@ -178,6 +182,10 @@ int main(int argc, char **argv) {
178182 free_options (opts );
179183 usage ();
180184 }
185+ if (opts -> print_version ) {
186+ printf ("tcpkit %s\n" , VERSION );
187+ exit (0 );
188+ }
181189 if (getuid () != 0 && !opts -> offline_file ) {
182190 free_options (opts );
183191 log_message (FATAL , "You don't have permission to capture on the network card interface" );
0 commit comments