/*************************************************************************** * data_reply.c * * Sat Apr 5 09:36:32 CEST 2008 * Copyright 2008-2016 Jaime Penalba Estebanez * Copyright 2009 Janusz Uzycki * * Data abstraction layer part for arp replies ****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * 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 * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include "misc.h" #include "data_al.h" /* Pointers to hold list data */ struct data_registry *first_reply, *last_reply; /* Pointer to handle list */ struct data_registry *current_reply; /* Registry data counter */ struct data_counter reply_count; /* Screen printing buffers */ char line[300], tline[300]; extern char blank[]; /* Initialize required data */ void reply_init() { first_reply = NULL; last_reply = NULL; } /* Used to beging the iteration between registries */ void reply_beginning_registry() { current_reply = first_reply; } /* Go to next registry */ void reply_next_registry(void) { current_reply = current_reply->next; } /* Return current registry mainly to check if its null */ struct data_registry *reply_current_reply(void) { return current_reply; } /* Return hosts count */ int reply_hosts_count(void) { return reply_count.hosts; } /* Print current registry line (for interactive mode) */ void reply_print_line() { int j; sprintf(line, " "); sprintf(tline, " "); /* Set IP */ sprintf(tline, "%s ", current_reply->sip); strcat(line, tline); /* Fill with spaces */ for (j=strlen(line); j<17; j++) strcat(line, blank); /* IP & MAC */ sprintf(tline, "%02x:%02x:%02x:%02x:%02x:%02x ", current_reply->header->smac[0], current_reply->header->smac[1], current_reply->header->smac[2], current_reply->header->smac[3], current_reply->header->smac[4], current_reply->header->smac[5]); strcat(line, tline); /* Count, Length & Vendor */ sprintf(tline, "%5d %7d %s", current_reply->count, current_reply->header->length, current_reply->vendor ); strcat(line, tline); /* Fill again with spaces and cut the string to fit width */ for (j=strlen(line); (jfocused == 0) printf("%s\n", line); else printf(KNOWN_COLOR, line); } /* Add new data to the registry list */ void reply_add_registry(struct data_registry *registry) { int i = 0; _data_unique.add_registry(registry); if ( first_reply == NULL ) { reply_count.hosts++; search_mac(registry); first_reply = registry; last_reply = registry; } else { struct data_registry *tmp_registry; tmp_registry = first_reply; /* Check for dupe packets */ while ( tmp_registry != NULL && i != 1 ) { if ( ( strcmp(tmp_registry->sip, registry->sip) == 0 ) && ( memcmp(tmp_registry->header->smac, registry->header->smac, 6) == 0 ) ) { tmp_registry->count++; tmp_registry->header->length += registry->header->length; i = 1; } tmp_registry = tmp_registry->next; } /* Add it if isnt dupe */ if ( i != 1 ) { reply_count.hosts++; search_mac(registry); last_reply->next = registry; last_reply = registry; } } reply_count.pakets++; reply_count.length += registry->header->length; } void reply_print_header_sumary(int width) { int j; sprintf(line, " %i Captured ARP Reply packets, from %i hosts. Total size: %i", reply_count.pakets, reply_count.hosts, reply_count.length); printf("%s", line); /* Fill with spaces */ for (j=strlen(line); j