mirror of https://github.com/OISF/suricata
factorize pcap live device function
They are not specific to pcap and could thus be used in other module.remotes/origin/master-1.1.x
parent
c45d898572
commit
871b21892a
@ -0,0 +1,85 @@
|
||||
/* Copyright (C) 2011 Open Information Security Foundation
|
||||
*
|
||||
* You can copy, redistribute or modify this Program under the terms of
|
||||
* the GNU General Public License version 2 as published by the Free
|
||||
* Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "suricata-common.h"
|
||||
#include "conf.h"
|
||||
#include "util-device.h"
|
||||
|
||||
/** private device list */
|
||||
static TAILQ_HEAD(, LiveDevice_) live_devices =
|
||||
TAILQ_HEAD_INITIALIZER(live_devices);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Add a pcap device for monitoring
|
||||
*
|
||||
* \param dev string with the device name
|
||||
*
|
||||
* \retval 0 on success.
|
||||
* \retval -1 on failure.
|
||||
*/
|
||||
int LiveRegisterDevice(char *dev)
|
||||
{
|
||||
LiveDevice *pd = SCMalloc(sizeof(LiveDevice));
|
||||
if (pd == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pd->dev = SCStrdup(dev);
|
||||
TAILQ_INSERT_TAIL(&live_devices, pd, next);
|
||||
|
||||
SCLogDebug("Pcap device \"%s\" registered.", dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get the number of registered devices
|
||||
*
|
||||
* \retval cnt the number of registered devices
|
||||
*/
|
||||
int LiveGetDeviceCount(void) {
|
||||
int i = 0;
|
||||
LiveDevice *pd;
|
||||
|
||||
TAILQ_FOREACH(pd, &live_devices, next) {
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get a pointer to the device at idx
|
||||
*
|
||||
* \param number idx of the device in our list
|
||||
*
|
||||
* \retval ptr pointer to the string containing the device
|
||||
* \retval NULL on error
|
||||
*/
|
||||
char *LiveGetDevice(int number) {
|
||||
int i = 0;
|
||||
LiveDevice *pd;
|
||||
|
||||
TAILQ_FOREACH(pd, &live_devices, next) {
|
||||
if (i == number) {
|
||||
return pd->dev;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/* Copyright (C) 2011 Open Information Security Foundation
|
||||
*
|
||||
* You can copy, redistribute or modify this Program under the terms of
|
||||
* the GNU General Public License version 2 as published by the Free
|
||||
* Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _UTIL_DEVICE_H
|
||||
#define _UTIL_DEVICE_H 1
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
/** storage for live device names */
|
||||
typedef struct LiveDevice_ {
|
||||
char *dev; /**< the device (e.g. "eth0") */
|
||||
TAILQ_ENTRY(LiveDevice_) next;
|
||||
} LiveDevice;
|
||||
|
||||
|
||||
int LiveRegisterDevice(char *dev);
|
||||
int LiveGetDeviceCount(void);
|
||||
char *LiveGetDevice(int number);
|
||||
|
||||
#endif /* _UTIL_DEVICE_H */
|
Loading…
Reference in New Issue