Beispiel #1
0
void refresh_othwindow(struct othptable *table)
{
	int target_row = 0;
	struct othptabent *entry;

	wattrset(table->othpwin, STDATTR);
	tx_colorwin(table->othpwin);

	entry = table->firstvisible;

	while ((entry != NULL) && (entry != table->lastvisible->next_entry)) {
		printothpentry(table, entry, target_row, 0, NULL);
		target_row++;
		entry = entry->next_entry;
	}

	update_panels();
	doupdate();
}
Beispiel #2
0
struct othptabent *add_othp_entry(struct othptable *table, struct pkt_hdr *pkt,
				  struct sockaddr_storage *saddr,
				  struct sockaddr_storage *daddr,
				  int is_ip,
				  int protocol,
				  char *packet2,
				  char *ifname, int *rev_lookup, int rvnfd,
				  int logging, FILE *logfile, int fragment)
{
	struct othptabent *new_entry;
	struct othptabent *temp;

	new_entry = xmallocz(sizeof(struct othptabent));

	new_entry->is_ip = is_ip;
	new_entry->fragment = fragment;

	if (options.mac || !is_ip) {
		if (pkt->pkt_hatype == ARPHRD_ETHER) {
			convmacaddr((char *) pkt->ethhdr->h_source, new_entry->smacaddr);
			convmacaddr((char *) pkt->ethhdr->h_dest, new_entry->dmacaddr);
		} else if (pkt->pkt_hatype == ARPHRD_FDDI) {
			convmacaddr((char *) pkt->fddihdr->saddr, new_entry->smacaddr);
			convmacaddr((char *) pkt->fddihdr->daddr, new_entry->dmacaddr);
		}
	}

	if (is_ip) {
		sockaddr_copy(&new_entry->saddr, saddr);
		sockaddr_copy(&new_entry->daddr, daddr);

		revname(rev_lookup, saddr, new_entry->s_fqdn,
			sizeof(new_entry->s_fqdn), rvnfd);
		revname(rev_lookup, daddr, new_entry->d_fqdn,
			sizeof(new_entry->d_fqdn), rvnfd);

		if (!fragment) {
			if (protocol == IPPROTO_ICMP) {
				new_entry->un.icmp.type =
				    ((struct icmphdr *) packet2)->type;
				new_entry->un.icmp.code =
				    ((struct icmphdr *) packet2)->code;
			} else if (protocol == IPPROTO_ICMPV6) {
				new_entry->un.icmp6.type =
				    ((struct icmp6_hdr *) packet2)->icmp6_type;
				new_entry->un.icmp6.code =
				    ((struct icmp6_hdr *) packet2)->icmp6_code;
			} else if (protocol == IPPROTO_UDP) {
				servlook(ntohs(((struct udphdr *) packet2)->source),
					 IPPROTO_UDP, new_entry->un.udp.s_sname,
					 10);
				servlook(ntohs(((struct udphdr *) packet2)->dest),
					 IPPROTO_UDP, new_entry->un.udp.d_sname,
					 10);
			} else if (protocol == IPPROTO_OSPFIGP) {
				new_entry->un.ospf.type =
				    ((struct ospfhdr *) packet2)->ospf_type;
				new_entry->un.ospf.area =
				    ntohl(((struct ospfhdr *) packet2)->
					  ospf_areaid.s_addr);
				inet_ntop(AF_INET,
					  &((struct ospfhdr *)packet2)->ospf_routerid,
					  new_entry->un.ospf.routerid,
					  sizeof(new_entry->un.ospf.routerid));
			}
		}
	} else {
		new_entry->linkproto = pkt->pkt_hatype;

		if (protocol == ETH_P_ARP) {
			new_entry->un.arp.opcode =
			    ((struct arp_hdr *) packet2)->ar_op;
			memcpy(&(new_entry->un.arp.src_ip_address),
			       &(((struct arp_hdr *) packet2)->ar_sip), 4);
			memcpy(&(new_entry->un.arp.dest_ip_address),
			       &(((struct arp_hdr *) packet2)->ar_tip), 4);
		} else if (protocol == ETH_P_RARP) {
			new_entry->un.rarp.opcode =
			    ((struct arphdr *) packet2)->ar_op;
			memcpy(&(new_entry->un.rarp.src_mac_address),
			       &(((struct arp_hdr *) packet2)->ar_sha), 6);
			memcpy(&(new_entry->un.rarp.dest_mac_address),
			       &(((struct arp_hdr *) packet2)->ar_tha), 6);
		}
	}

	new_entry->protocol = protocol;
	strcpy(new_entry->iface, ifname);

	new_entry->pkt_length = pkt->pkt_len;

	if (table->head == NULL) {
		new_entry->prev_entry = NULL;
		table->head = new_entry;
		table->firstvisible = new_entry;
	}
	/*
	 * Max number of entries in the lower window is 512.  Upon reaching
	 * this figure, oldest entries are thrown out.
	 */

	if (table->count == 512) {
		if (table->firstvisible == table->head) {
			wscrl(table->othpwin, 1);
			printothpentry(table, table->lastvisible->next_entry,
				       table->oimaxy - 1, logging, logfile);
			table->firstvisible = table->firstvisible->next_entry;
			table->lastvisible = table->lastvisible->next_entry;
		}
		temp = table->head;
		table->head = table->head->next_entry;
		table->head->prev_entry = NULL;
		free(temp);
	} else
		table->count++;

	if (table->tail != NULL) {
		new_entry->prev_entry = table->tail;
		table->tail->next_entry = new_entry;
	}
	table->tail = new_entry;
	new_entry->next_entry = NULL;

	table->lastpos++;
	new_entry->index = table->lastpos;

	if (table->count <= table->oimaxy) {
		table->lastvisible = new_entry;
		printothpentry(table, new_entry, table->count - 1, logging,
			       logfile);
	} else if (table->lastvisible == table->tail->prev_entry) {
		wscrl(table->othpwin, 1);
		table->firstvisible = table->firstvisible->next_entry;
		table->lastvisible = table->tail;
		printothpentry(table, new_entry, table->oimaxy - 1, logging,
			       logfile);
	}
	return new_entry;
}
Beispiel #3
0
struct othptabent *add_othp_entry(struct othptable *table,
                                  struct tcptable *tcptab,
                                  unsigned long saddr, unsigned long daddr,
                                  int is_ip, int protocol,
                                  unsigned short linkproto, char *packet,
                                  char *packet2, unsigned int br,
                                  char *ifname, int *rev_lookup, int rvnfd,
                                  unsigned int tm, int logging,
                                  FILE * logfile, int servnames,
                                  int fragment, int *nomem)
{
    struct othptabent *new_entry;
    struct othptabent *temp;
    struct in_addr isaddr, idaddr;

    new_entry = malloc(sizeof(struct othptabent));

    if (new_entry == NULL) {
        printnomem();
        *nomem = 1;
        return NULL;
    }
    bzero(new_entry, sizeof(struct othptabent));

    new_entry->is_ip = is_ip;
    new_entry->fragment = fragment;

    if ((table->mac) || (!is_ip)) {
        if ((linkproto == LINK_ETHERNET) || (linkproto == LINK_PLIP)) {
            convmacaddr(((struct ethhdr *) packet)->h_source,
                        new_entry->smacaddr);
            convmacaddr(((struct ethhdr *) packet)->h_dest,
                        new_entry->dmacaddr);
        } else if (linkproto == LINK_FDDI) {
            convmacaddr(((struct fddihdr *) packet)->saddr,
                        new_entry->smacaddr);
            convmacaddr(((struct fddihdr *) packet)->daddr,
                        new_entry->dmacaddr);
        } else if (linkproto == LINK_TR) {
            convmacaddr(((struct trh_hdr *) packet)->saddr,
                        new_entry->smacaddr);
            convmacaddr(((struct trh_hdr *) packet)->daddr,
                        new_entry->dmacaddr);
        }
    }

    if (is_ip) {
        new_entry->saddr = isaddr.s_addr = saddr;
        new_entry->daddr = idaddr.s_addr = daddr;

        revname(rev_lookup, &isaddr, new_entry->s_fqdn, rvnfd);
        revname(rev_lookup, &idaddr, new_entry->d_fqdn, rvnfd);

        if (!fragment) {
            if (protocol == IPPROTO_ICMP) {
                new_entry->un.icmp.type =
                    ((struct icmphdr *) packet2)->type;
                new_entry->un.icmp.code =
                    ((struct icmphdr *) packet2)->code;
            } else if (protocol == IPPROTO_UDP) {
                servlook(servnames, ((struct udphdr *) packet2)->source,
                         IPPROTO_UDP, new_entry->un.udp.s_sname, 10);
                servlook(servnames, ((struct udphdr *) packet2)->dest,
                         IPPROTO_UDP, new_entry->un.udp.d_sname, 10);
            } else if (protocol == IPPROTO_OSPFIGP) {
                new_entry->un.ospf.type =
                    ((struct ospfhdr *) packet2)->ospf_type;
                new_entry->un.ospf.area =
                    ntohl(((struct ospfhdr *) packet2)->ospf_areaid.
                          s_addr);
                strcpy(new_entry->un.ospf.routerid,
                       inet_ntoa(((struct ospfhdr *)
                                  packet2)->ospf_routerid));
            }
        }
    } else {
        new_entry->linkproto = linkproto;

        if (protocol == ETH_P_ARP) {
            new_entry->un.arp.opcode = ((struct arp_hdr *) packet2)->ar_op;
            memcpy(&(new_entry->un.arp.src_ip_address),
                   &(((struct arp_hdr *) packet2)->ar_sip), 4);
            memcpy(&(new_entry->un.arp.dest_ip_address),
                   &(((struct arp_hdr *) packet2)->ar_tip), 4);
        } else if (protocol == ETH_P_RARP) {
            new_entry->un.rarp.opcode = ((struct arphdr *) packet2)->ar_op;
            memcpy(&(new_entry->un.rarp.src_mac_address),
                   &(((struct arp_hdr *) packet2)->ar_sha), 6);
            memcpy(&(new_entry->un.rarp.dest_mac_address),
                   &(((struct arp_hdr *) packet2)->ar_tha), 6);
        }
    }

    new_entry->protocol = protocol;
    strcpy(new_entry->iface, ifname);

    new_entry->pkt_length = br;

    if (table->head == NULL) {
        new_entry->prev_entry = NULL;
        table->head = new_entry;
        table->firstvisible = new_entry;
    }
    /*
     * Max number of entries in the lower window is 512.  Upon reaching
     * this figure, oldest entries are thrown out.
     */

    if (table->count == 512) {
        if (table->firstvisible == table->head) {
            wscrl(table->othpwin, 1);
            printothpentry(table, table->lastvisible->next_entry,
                           table->oimaxy - 1, logging, logfile);
            table->firstvisible = table->firstvisible->next_entry;
            table->lastvisible = table->lastvisible->next_entry;
        }
        temp = table->head;
        table->head = table->head->next_entry;
        table->head->prev_entry = NULL;
        free(temp);
    } else
        table->count++;

    if (table->tail != NULL) {
        new_entry->prev_entry = table->tail;
        table->tail->next_entry = new_entry;
    }
    table->tail = new_entry;
    new_entry->next_entry = NULL;

    table->lastpos++;
    new_entry->index = table->lastpos;

    if (table->count <= table->oimaxy) {
        table->lastvisible = new_entry;
        printothpentry(table, new_entry, table->count - 1, logging,
                       logfile);
    } else if (table->lastvisible == table->tail->prev_entry) {
        wscrl(table->othpwin, 1);
        table->firstvisible = table->firstvisible->next_entry;
        table->lastvisible = table->tail;
        printothpentry(table, new_entry, table->oimaxy - 1, logging,
                       logfile);
    }
    return new_entry;
}