aboutsummaryrefslogtreecommitdiff
path: root/pcap-sita.c
diff options
context:
space:
mode:
Diffstat (limited to 'pcap-sita.c')
-rw-r--r--pcap-sita.c61
1 files changed, 28 insertions, 33 deletions
diff --git a/pcap-sita.c b/pcap-sita.c
index b9dda9c55b48..2e5d4426adb7 100644
--- a/pcap-sita.c
+++ b/pcap-sita.c
@@ -72,6 +72,14 @@ typedef struct unit {
int len; /* the current size of the inbound message */
} unit_t;
+/*
+ * Private data.
+ * Currently contains nothing.
+ */
+struct pcap_sita {
+ int dummy;
+};
+
static unit_t units[MAX_CHASSIS+1][MAX_GEOSLOT+1]; /* we use indexes of 1 through 8, but we reserve/waste index 0 */
static fd_set readfds; /* a place to store the file descriptors for the connections to the IOPs */
static int max_fs;
@@ -266,7 +274,7 @@ int acn_parse_hosts_file(char *errbuf) { /* returns: -1 = error, 0 = OK */
empty_unit_table();
if ((fp = fopen("/etc/hosts", "r")) == NULL) { /* try to open the hosts file and if it fails */
- pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Cannot open '/etc/hosts' for reading."); /* return the nohostsfile error response */
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "Cannot open '/etc/hosts' for reading."); /* return the nohostsfile error response */
return -1;
}
while (fgets(buf, MAX_LINE_SIZE-1, fp)) { /* while looping over the file */
@@ -289,15 +297,15 @@ int acn_parse_hosts_file(char *errbuf) { /* returns: -1 = error, 0 = OK */
geoslot = *(ptr2 + 5) - '0'; /* and geo-slot number */
if (chassis < 1 || chassis > MAX_CHASSIS ||
geoslot < 1 || geoslot > MAX_GEOSLOT) { /* if the chassis and/or slot numbers appear to be bad... */
- pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Invalid ACN name in '/etc/hosts'."); /* warn the user */
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "Invalid ACN name in '/etc/hosts'."); /* warn the user */
continue; /* and ignore the entry */
}
- if ((ptr2 = (char *)malloc(strlen(ptr) + 1)) == NULL) {
+ ptr2 = strdup(ptr); /* copy the IP address into our malloc'ed memory */
+ if (ptr2 == NULL) {
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
errno, "malloc");
continue;
}
- strcpy(ptr2, ptr); /* copy the IP address into our malloc'ed memory */
u = &units[chassis][geoslot];
u->ip = ptr2; /* and remember the whole shebang */
u->chassis = chassis;
@@ -407,19 +415,18 @@ static void acn_freealldevs(void) {
static void nonUnified_IOP_port_name(char *buf, size_t bufsize, const char *proto, unit_t *u) {
- pcap_snprintf(buf, bufsize, "%s_%d_%d", proto, u->chassis, u->geoslot);
+ snprintf(buf, bufsize, "%s_%d_%d", proto, u->chassis, u->geoslot);
}
static void unified_IOP_port_name(char *buf, size_t bufsize, const char *proto, unit_t *u, int IOPportnum) {
int portnum;
portnum = ((u->chassis - 1) * 64) + ((u->geoslot - 1) * 8) + IOPportnum + 1;
- pcap_snprintf(buf, bufsize, "%s_%d", proto, portnum);
+ snprintf(buf, bufsize, "%s_%d", proto, portnum);
}
static char *translate_IOP_to_pcap_name(unit_t *u, char *IOPname, bpf_u_int32 iftype) {
iface_t *iface_ptr, *iface;
- char *name;
char buf[32];
char *proto;
char *port;
@@ -434,15 +441,12 @@ static char *translate_IOP_to_pcap_name(unit_t *u, char *IOPname, bpf_u_int32 if
iface->iftype = iftype; /* remember the interface type of this interface */
- name = malloc(strlen(IOPname) + 1); /* get memory for the IOP's name */
- if (name == NULL) { /* oops, we didn't get the memory requested */
+ iface->IOPname = strdup(IOPname); /* copy it and stick it into the structure */
+ if (iface->IOPname == NULL) { /* oops, we didn't get the memory requested */
fprintf(stderr, "Error...couldn't allocate memory for IOPname...value of errno is: %d\n", errno);
return NULL;
}
- strcpy(name, IOPname); /* and copy it in */
- iface->IOPname = name; /* and stick it into the structure */
-
if (strncmp(IOPname, "lo", 2) == 0) {
IOPportnum = atoi(&IOPname[2]);
switch (iftype) {
@@ -478,20 +482,17 @@ static char *translate_IOP_to_pcap_name(unit_t *u, char *IOPname, bpf_u_int32 if
return NULL;
}
- name = malloc(strlen(buf) + 1); /* get memory for that name */
- if (name == NULL) { /* oops, we didn't get the memory requested */
+ iface->name = strdup(buf); /* make a copy and stick it into the structure */
+ if (iface->name == NULL) { /* oops, we didn't get the memory requested */
fprintf(stderr, "Error...couldn't allocate memory for IOP port name...value of errno is: %d\n", errno);
return NULL;
}
- strcpy(name, buf); /* and copy it in */
- iface->name = name; /* and stick it into the structure */
-
if (u->iface == 0) { /* if this is the first name */
u->iface = iface; /* stick this entry at the head of the list */
} else {
iface_ptr = u->iface;
- while (iface_ptr->next) { /* othewise scan the list */
+ while (iface_ptr->next) { /* otherwise scan the list */
iface_ptr = iface_ptr->next; /* till we're at the last entry */
}
iface_ptr->next = iface; /* then tack this entry on the end of the list */
@@ -703,7 +704,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
prev_iff = iff;
newname = translate_IOP_to_pcap_name(u, iff->name, interfaceType); /* add a translation entry and get a point to the mangled name */
- bigger_buffer = realloc(iff->name, strlen(newname) + 1));
+ bigger_buffer = realloc(iff->name, strlen(newname) + 1);
if (bigger_buffer == NULL) { /* we now re-write the name stored in the interface list */
pcap_fmt_errmsg_for_errno(errbuf,
PCAP_ERRBUF_SIZE, errno, "realloc");
@@ -754,9 +755,9 @@ static void wait_for_all_answers(void) {
memcpy(&working_set, &readfds, sizeof(readfds)); /* otherwise, we still have to listen for more stuff, till we timeout */
retval = select(max_fs + 1, &working_set, NULL, NULL, &tv);
- if (retval == -1) { /* an error occured !!!!! */
+ if (retval == -1) { /* an error occurred !!!!! */
return;
- } else if (retval == 0) { /* timeout occured, so process what we've got sofar and return */
+ } else if (retval == 0) { /* timeout occurred, so process what we've got sofar and return */
printf("timeout\n");
return;
} else {
@@ -883,7 +884,7 @@ static void acn_start_monitor(int fd, int snaplen, int timeout, int promiscuous,
//printf("acn_start_monitor() complete\n"); // fulko
}
-static int pcap_inject_acn(pcap_t *p, const void *buf _U_, size_t size _U_) {
+static int pcap_inject_acn(pcap_t *p, const void *buf _U_, int size _U_) {
pcap_strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters",
PCAP_ERRBUF_SIZE);
return (-1);
@@ -915,12 +916,6 @@ static int pcap_setfilter_acn(pcap_t *handle, struct bpf_program *bpf) {
return 0;
}
-static int pcap_setdirection_acn(pcap_t *handle, pcap_direction_t d) {
- pcap_snprintf(handle->errbuf, sizeof(handle->errbuf),
- "Setting direction is not supported on ACN adapters");
- return -1;
-}
-
static int acn_read_n_bytes_with_timeout(pcap_t *handle, int count) {
struct timeval tv;
int retval, fd;
@@ -940,10 +935,10 @@ static int acn_read_n_bytes_with_timeout(pcap_t *handle, int count) {
bp = handle->bp;
while (count) {
retval = select(fd + 1, &w_fds, NULL, NULL, &tv);
- if (retval == -1) { /* an error occured !!!!! */
+ if (retval == -1) { /* an error occurred !!!!! */
// fprintf(stderr, "error during packet data read\n");
- return -1; /* but we need to return a good indication to prevent unneccessary popups */
- } else if (retval == 0) { /* timeout occured, so process what we've got sofar and return */
+ return -1; /* but we need to return a good indication to prevent unnecessary popups */
+ } else if (retval == 0) { /* timeout occurred, so process what we've got sofar and return */
// fprintf(stderr, "timeout during packet data read\n");
return -1;
} else {
@@ -997,7 +992,7 @@ static int pcap_activate_sita(pcap_t *handle) {
handle->inject_op = pcap_inject_acn;
handle->setfilter_op = pcap_setfilter_acn;
- handle->setdirection_op = pcap_setdirection_acn;
+ handle->setdirection_op = NULL; /* Not implemented */
handle->set_datalink_op = NULL; /* can't change data link type */
handle->getnonblock_op = pcap_getnonblock_fd;
handle->setnonblock_op = pcap_setnonblock_fd;
@@ -1046,7 +1041,7 @@ static int pcap_activate_sita(pcap_t *handle) {
pcap_t *pcap_create_interface(const char *device _U_, char *ebuf) {
pcap_t *p;
- p = pcap_create_common(ebuf, 0);
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_sita);
if (p == NULL)
return (NULL);