chg: [pibs] added -y option to specify redis database
parent
5c5f88f02d
commit
4bebe74365
19
bin/pibs.c
19
bin/pibs.c
|
@ -107,6 +107,7 @@ typedef struct pibs_s {
|
||||||
char outputfile[FILENAME_MAX];
|
char outputfile[FILENAME_MAX];
|
||||||
pcap_dumper_t* dumper;
|
pcap_dumper_t* dumper;
|
||||||
pcap_t* outcap;
|
pcap_t* outcap;
|
||||||
|
uint32_t redisdb;
|
||||||
} pibs_t;
|
} pibs_t;
|
||||||
|
|
||||||
int load_shmid_file(pibs_t* pibs)
|
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);
|
snprintf(pibs->key, SZKEY, "analyzer:1:%s",pibs->uuid);
|
||||||
pibs->ctx = redisConnect(pibs->server, pibs->port);
|
pibs->ctx = redisConnect(pibs->server, pibs->port);
|
||||||
if (pibs->ctx != NULL) {
|
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 {
|
do {
|
||||||
reply = redisCommand(pibs->ctx,"LPOP %s", pibs->key);
|
reply = redisCommand(pibs->ctx,"LPOP %s", pibs->key);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
|
@ -464,7 +478,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
fprintf(stderr, "[INFO] pid = %d\n",(int)getpid());
|
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) {
|
switch (opt) {
|
||||||
case 'r':
|
case 'r':
|
||||||
strncpy(pibs->filename, optarg, FILENAME_MAX);
|
strncpy(pibs->filename, optarg, FILENAME_MAX);
|
||||||
|
@ -500,6 +514,9 @@ int main(int argc, char* argv[])
|
||||||
strncpy(pibs->outputfile,optarg, FILENAME_MAX);
|
strncpy(pibs->outputfile,optarg, FILENAME_MAX);
|
||||||
pibs->should_writepcap = 1;
|
pibs->should_writepcap = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'y':
|
||||||
|
pibs->redisdb = atoi(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
default: /* '?' */
|
default: /* '?' */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue