Added shortening of listening interface in util-runmodes

Added function LiveSafeDeviceName in util-device that shortens an
NIC device name if the name is over a given length and turns
it in to Ex: longi...eeth1
pull/2050/head
maxtors 11 years ago committed by Victor Julien
parent 63937cd903
commit 10d1450e49

@ -19,6 +19,9 @@
#include "conf.h"
#include "util-device.h"
#define MAX_DEVNAME 12
#define DEVNAME_CHUNCK 5
/**
* \file
*
@ -105,6 +108,28 @@ char *LiveGetDeviceName(int number)
return NULL;
}
/**
* \brief Shorten a device name that is to long
*
* \param device name from config and destination for modified
*
* \retval None, is added to destination char *newdevname
*/
void LiveSafeDeviceName(const char *devname, char *newdevname)
{
size_t devnamelen = strlen(devname);
if (devnamelen > MAX_DEVNAME) {
strncpy(newdevname, devname, DEVNAME_CHUNCK);
strncpy(newdevname+DEVNAME_CHUNCK, "...", 3);
strncpy(newdevname+8, devname+(devnamelen-DEVNAME_CHUNCK), DEVNAME_CHUNCK);
strncpy(newdevname+13, "\0", 1);
SCLogInfo("Shortening device name to: %s", newdevname);
} else {
strcpy(newdevname, devname);
}
}
/**
* \brief Get a pointer to the device at idx
*

@ -35,6 +35,7 @@ typedef struct LiveDevice_ {
int LiveRegisterDevice(const char *dev);
int LiveGetDeviceCount(void);
char *LiveGetDeviceName(int number);
void LiveSafeDeviceName(const char *devname, char *newdevname);
LiveDevice *LiveGetDevice(const char *dev);
int LiveBuildDeviceList(const char *base);
void LiveDeviceHasNoStats(void);

@ -186,6 +186,7 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
for (lthread = 0; lthread < nlive; lthread++) {
char *live_dev = LiveGetDeviceName(lthread);
char visual_devname[14] = "";
void *aconf;
int threads_count;
@ -204,6 +205,7 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
threads_count = ModThreadsCount(aconf);
for (thread = 0; thread < threads_count; thread++) {
LiveSafeDeviceName(live_dev, visual_devname);
snprintf(tname, sizeof(tname), "%s%s%d", thread_name,
live_dev, thread+1);
ThreadVars *tv_receive =
@ -314,12 +316,16 @@ static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc Mod
/* create the threads */
for (thread = 0; thread < threads_count; thread++) {
char tname[TM_THREAD_NAME_MAX];
char *n_thread_name = NULL;
char visual_devname[13] = "";
ThreadVars *tv = NULL;
TmModule *tm_module = NULL;
if (single_mode) {
snprintf(tname, sizeof(tname), "%s", thread_name);
} else {
LiveSafeDeviceName(live_dev, visual_devname);
SCLogInfo("New dev name %s", visual_devname);
snprintf(tname, sizeof(tname), "%s%s%d",
thread_name, live_dev, thread+1);
}

Loading…
Cancel
Save