From 4bebe743658a2583c7feb3e3e837fb1acd8dc495 Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Tue, 19 Mar 2019 11:14:18 +0100 Subject: [PATCH] chg: [pibs] added -y option to specify redis database --- bin/pibs.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bin/pibs.c b/bin/pibs.c index 84f22f0..cf5632b 100644 --- a/bin/pibs.c +++ b/bin/pibs.c @@ -107,6 +107,7 @@ typedef struct pibs_s { char outputfile[FILENAME_MAX]; pcap_dumper_t* dumper; pcap_t* outcap; + uint32_t redisdb; } pibs_t; int load_shmid_file(pibs_t* pibs) @@ -434,6 +435,19 @@ void process_redis_list(pibs_t* pibs) snprintf(pibs->key, SZKEY, "analyzer:1:%s",pibs->uuid); pibs->ctx = redisConnect(pibs->server, pibs->port); if (pibs->ctx != NULL) { + if (pibs->redisdb >0) { + printf("[INFO] Select redis database %d\n", pibs->redisdb); + reply = redisCommand(pibs->ctx, "SELECT %d", pibs->redisdb); + if (reply) { + rtype = reply->type; + freeReplyObject(reply); + if (rtype != REDIS_REPLY_STATUS) { + printf("[ERROR] Cannot switch to database %d. Abort.", + pibs->redisdb); + return; + } + } + } do { reply = redisCommand(pibs->ctx,"LPOP %s", pibs->key); if (reply) { @@ -464,7 +478,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "[INFO] pid = %d\n",(int)getpid()); - while ((opt = getopt(argc, argv, "r:dbsni:au:z:p:w:")) != -1) { + while ((opt = getopt(argc, argv, "r:dbsni:au:z:p:w:y:")) != -1) { switch (opt) { case 'r': strncpy(pibs->filename, optarg, FILENAME_MAX); @@ -500,6 +514,9 @@ int main(int argc, char* argv[]) strncpy(pibs->outputfile,optarg, FILENAME_MAX); pibs->should_writepcap = 1; break; + case 'y': + pibs->redisdb = atoi(optarg); + break; default: /* '?' */