static void empty_unit(int chassis, int geoslot) { unit_t *u = &units[chassis][geoslot]; empty_unit_iface(u); if (u->imsg) { /* then if an inbound message buffer exists */ u->imsg = (char *)realloc(u->imsg, 1); /* and re-allocate the old large buffer into a new small one */ if (u->imsg == NULL) { /* oops, realloc call failed */ fprintf(stderr, "Warning...call to realloc() failed, value of errno is %d\n", errno); } } static void empty_unit_table(void) { int chassis, geoslot; for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) { for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) { if (units[chassis][geoslot].ip != NULL) { free(units[chassis][geoslot].ip); /* get rid of the malloc'ed space that holds the IP address */ units[chassis][geoslot].ip = 0; /* then set the pointer to NULL */ } empty_unit(chassis, geoslot); } } }
static void empty_unit(int chassis, int geoslot) { unit_t *u = &units[chassis][geoslot]; empty_unit_iface(u); if (u->imsg) { /* then if an inbound message buffer exists */ u->imsg = (char *)realloc(u->imsg, 1); /* and re-allocate the old large buffer into a new small one */ } }
static void empty_unit(int chassis, int geoslot) { unit_t *u = &units[chassis][geoslot]; empty_unit_iface(u); if (u->imsg) { /* then if an inbound message buffer exists */ u->imsg = (char *)realloc(u->imsg, 1); /* and re-allocate the old large buffer into a new small one */ if (u->imsg == NULL) /* oops, realloc() call failed */ snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc: u->serv_addr %s", pcap_strerror(errno)); } }
static void empty_unit(int chassis, int geoslot) { unit_t *u = &units[chassis][geoslot]; empty_unit_iface(u); if (u->imsg) { /* then if an inbound message buffer exists */ u->imsg = (char *)realloc(u->imsg, 1); /* and re-allocate the old large buffer into a new small one */ if (u->imsg == NULL) /* oops, realloc call failed */ fprintf(stderr, "Warning...call to realloc() failed, value of errno is %d\n", errno); } }
static int process_client_data (char *errbuf) { /* returns: -1 = error, 0 = OK */ int chassis, geoslot; unit_t *u; pcap_if_t *iff, *prev_iff; pcap_addr_t *addr, *prev_addr; char *ptr; int address_count; struct sockaddr_in *s; char *newname; bpf_u_int32 interfaceType; unsigned char flags; prev_iff = 0; for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) { for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) { /* now loop over all the devices */ u = &units[chassis][geoslot]; empty_unit_iface(u); ptr = u->imsg; /* point to the start of the msg for this IOP */ while (ptr < (u->imsg + u->len)) { if ((iff = malloc(sizeof(pcap_if_t))) == NULL) { snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); return -1; } memset((char *)iff, 0, sizeof(pcap_if_t)); /* bzero() is deprecated, replaced with memset() */ if (acn_if_list == 0) acn_if_list = iff; /* remember the head of the list */ if (prev_iff) prev_iff->next = iff; /* insert a forward link */ if (*ptr) { /* if there is a count for the name */ if ((iff->name = malloc(*ptr + 1)) == NULL) { /* get that amount of space */ snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); return -1; } memcpy(iff->name, (ptr + 1), *ptr); /* copy the name into the malloc'ed space */ *(iff->name + *ptr) = 0; /* and null terminate the string */ ptr += *ptr; /* now move the pointer forwards by the length of the count plus the length of the string */ } ptr++; if (*ptr) { /* if there is a count for the description */ if ((iff->description = malloc(*ptr + 1)) == NULL) { /* get that amount of space */ snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); return -1; } memcpy(iff->description, (ptr + 1), *ptr); /* copy the name into the malloc'ed space */ *(iff->description + *ptr) = 0; /* and null terminate the string */ ptr += *ptr; /* now move the pointer forwards by the length of the count plus the length of the string */ } ptr++; interfaceType = ntohl(*(bpf_u_int32 *)ptr); ptr += 4; /* skip over the interface type */ flags = *ptr++; if (flags) iff->flags = PCAP_IF_LOOPBACK; /* if this is a loopback style interface, lets mark it as such */ address_count = *ptr++; prev_addr = 0; while (address_count--) { if ((addr = malloc(sizeof(pcap_addr_t))) == NULL) { snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); return -1; } memset((char *)addr, 0, sizeof(pcap_addr_t)); /* bzero() is deprecated, replaced with memset() */ if (iff->addresses == 0) iff->addresses = addr; if (prev_addr) prev_addr->next = addr; /* insert a forward link */ if (*ptr) { /* if there is a count for the address */ if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) { /* get that amount of space */ snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); return -1; } memset((char *)s, 0, sizeof(struct sockaddr_in)); /* bzero() is deprecated, replaced with memset() */ addr->addr = (struct sockaddr *)s; s->sin_family = AF_INET; s->sin_addr.s_addr = *(bpf_u_int32 *)(ptr + 1); /* copy the address in */ ptr += *ptr; /* now move the pointer forwards according to the specified length of the address */ } ptr++; /* then forwards one more for the 'length of the address' field */ if (*ptr) { /* process any netmask */ if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) { snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); return -1; } /* bzero() is deprecated, replaced with memset() */ memset((char *)s, 0, sizeof(struct sockaddr_in)); addr->netmask = (struct sockaddr *)s; s->sin_family = AF_INET; s->sin_addr.s_addr = *(bpf_u_int32*)(ptr + 1); ptr += *ptr; } ptr++; if (*ptr) { /* process any broadcast address */ if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) { snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); return -1; } /* bzero() is deprecated, replaced with memset() */ memset((char *)s, 0, sizeof(struct sockaddr_in)); addr->broadaddr = (struct sockaddr *)s; s->sin_family = AF_INET; s->sin_addr.s_addr = *(bpf_u_int32*)(ptr + 1); ptr += *ptr; } ptr++; if (*ptr) { /* process any destination address */ if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) { snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); return -1; } /* bzero() is deprecated, replaced with memset() */ memset((char *)s, 0, sizeof(struct sockaddr_in)); addr->dstaddr = (struct sockaddr *)s; s->sin_family = AF_INET; s->sin_addr.s_addr = *(bpf_u_int32*)(ptr + 1); ptr += *ptr; } ptr++; prev_addr = addr; } 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 */ if ((iff->name = realloc(iff->name, strlen(newname) + 1)) == NULL) { /* we now re-write the name stored in the interface list */ snprintf(errbuf, PCAP_ERRBUF_SIZE, "realloc: %s", pcap_strerror(errno)); return -1; } strcpy(iff->name, newname); /* to this new name */ } } } return 0; }