Lines Matching +full:no +full:- +full:dump +full:- +full:oops

2  *  pcap-sita.c: Packet capture interface additions for SITA ACN devices
39 #include "pcap-int.h"
41 #include "pcap-sita.h"
43 /* non-configurable manifests follow */
96 if (iff->name && (strlen(iff->name) > longest_name_len)) longest_name_len = strlen(iff->name); in dump_interface_list()
97 iff = iff->next; in dump_interface_list()
102 n = (iff->name) ? iff->name : ""; in dump_interface_list()
103 d = (iff->description) ? iff->description : ""; in dump_interface_list()
104 f = (iff->flags == PCAP_IF_LOOPBACK) ? "L" : ""; in dump_interface_list()
106 addr = iff->addresses; in dump_interface_list()
109 printf("%15s ", (addr->addr) ? inet_ntoa(((struct sockaddr_in *)addr->addr)->sin_addr) : ""); in dump_interface_list()
110 …printf("%15s ", (addr->netmask) ? inet_ntoa(((struct sockaddr_in *)addr->netmask)->sin_addr) : ""… in dump_interface_list()
111 …printf("%15s ", (addr->broadaddr) ? inet_ntoa(((struct sockaddr_in *)addr->broadaddr)->sin_addr) … in dump_interface_list()
112 …printf("%15s ", (addr->dstaddr) ? inet_ntoa(((struct sockaddr_in *)addr->dstaddr)->sin_addr) : ""… in dump_interface_list()
114 addr = addr->next; in dump_interface_list()
116 iff = iff->next; in dump_interface_list()
120 static void dump(unsigned char *ptr, int i, int indent) { in dump() function
122 for (; i > 0; i--) { in dump()
136 printf("%3d: %p %p next: %p\n", if_number++, iff->name, iff->description, iff->next); in dump_interface_list_p()
137 dump((unsigned char *)iff, sizeof(pcap_if_t), 5); in dump_interface_list_p()
138 addr = iff->addresses; in dump_interface_list_p()
140 …intf(" %p %p %p %p, next: %p\n", addr->addr, addr->netmask, addr->broadaddr, addr->dstadd… in dump_interface_list_p()
141 dump((unsigned char *)addr, sizeof(pcap_addr_t), 10); in dump_interface_list_p()
142 addr = addr->next; in dump_interface_list_p()
144 iff = iff->next; in dump_interface_list_p()
159 char *n = (p->name) ? p->name : ""; in dump_unit_table()
160 char *i = (p->IOPname) ? p->IOPname : ""; in dump_unit_table()
161 p = p->next; in dump_unit_table()
162 printf(" %12s -> %12s\n", i, n); in dump_unit_table()
191 if ((len = recv(fd, buf, count, 0)) <= 0) return -1; /* read in whatever data was sent to us */ in read_client_nbytes()
192 count -= len; in read_client_nbytes()
201 cur = u->iface; in empty_unit_iface()
203 if (cur->name) free(cur->name); /* throwing away the contents if they exist */ in empty_unit_iface()
204 if (cur->IOPname) free(cur->IOPname); in empty_unit_iface()
205 p = cur->next; in empty_unit_iface()
209 u->iface = 0; /* and finally remember that there are no remaining structure */ in empty_unit_iface()
216 if (u->imsg) { /* then if an inbound message buffer exists */ in empty_unit()
219 …bigger_buffer = (char *)realloc(u->imsg, 1); /* and re-allocate the old large buffer into a new… in empty_unit()
220 if (bigger_buffer == NULL) { /* oops, realloc call failed */ in empty_unit()
224 u->imsg = bigger_buffer; in empty_unit()
253 if (p->IOPname) last_name = p->name; /* remembering the last name found */ in find_nth_interface_name()
254 if (n-- == 0) return last_name; /* and if we hit the instance requested */ in find_nth_interface_name()
255 p = p->next; in find_nth_interface_name()
265 int acn_parse_hosts_file(char *errbuf) { /* returns: -1 = error, 0 = OK */ in acn_parse_hosts_file()
276 return -1; in acn_parse_hosts_file()
278 while (fgets(buf, MAX_LINE_SIZE-1, fp)) { /* while looping over the file */ in acn_parse_hosts_file()
283 pos = strspn(buf, " \t"); /* then find the first non-white space */ in acn_parse_hosts_file()
294 chassis = *(ptr2 + 3) - '0'; /* extract the chassis number */ in acn_parse_hosts_file()
295 geoslot = *(ptr2 + 5) - '0'; /* and geo-slot number */ in acn_parse_hosts_file()
308 u->ip = ptr2; /* and remember the whole shebang */ in acn_parse_hosts_file()
309 u->chassis = chassis; in acn_parse_hosts_file()
310 u->geoslot = geoslot; in acn_parse_hosts_file()
313 if (*errbuf) return -1; in acn_parse_hosts_file()
321 if (u->serv_addr == NULL) { in open_with_IOP()
322 u->serv_addr = malloc(sizeof(struct sockaddr_in)); in open_with_IOP()
325 if (u->serv_addr == NULL) { /* oops, we didn't get the memory requested */ in open_with_IOP()
326 fprintf(stderr, "malloc() request for u->serv_addr failed, value of errno is: %d\n", errno); in open_with_IOP()
331 ip = u->ip; in open_with_IOP()
333 memset((char *)u->serv_addr, 0, sizeof(struct sockaddr_in)); in open_with_IOP()
334 u->serv_addr->sin_family = AF_INET; in open_with_IOP()
335 u->serv_addr->sin_addr.s_addr = inet_addr(ip); in open_with_IOP()
336 u->serv_addr->sin_port = htons(IOP_SNIFFER_PORT); in open_with_IOP()
342 if (connect(sockfd, (struct sockaddr *)u->serv_addr, sizeof(struct sockaddr_in)) < 0) { in open_with_IOP()
346 if (flag == LIVE) u->fd = sockfd; in open_with_IOP()
347 else u->find_fd = sockfd; in open_with_IOP()
348 u->first_time = 0; in open_with_IOP()
349 return sockfd; /* return the non-zero file descriptor as a 'success' indicator */ in open_with_IOP()
368 if (find_unit_by_fd(handle->fd, &chassis, &geoslot, &u) == 0) in pcap_cleanup_acn()
372 u->first_time = 0; in pcap_cleanup_acn()
388 len -= nwritten; in send_to_fd()
399 next_iff = iff->next; in acn_freealldevs()
400 for (addr = iff->addresses; addr != NULL; addr = next_addr) { in acn_freealldevs()
401 next_addr = addr->next; in acn_freealldevs()
402 if (addr->addr) free(addr->addr); in acn_freealldevs()
403 if (addr->netmask) free(addr->netmask); in acn_freealldevs()
404 if (addr->broadaddr) free(addr->broadaddr); in acn_freealldevs()
405 if (addr->dstaddr) free(addr->dstaddr); in acn_freealldevs()
408 if (iff->name) free(iff->name); in acn_freealldevs()
409 if (iff->description) free(iff->description); in acn_freealldevs()
416 snprintf(buf, bufsize, "%s_%d_%d", proto, u->chassis, u->geoslot); in nonUnified_IOP_port_name()
422 portnum = ((u->chassis - 1) * 64) + ((u->geoslot - 1) * 8) + IOPportnum + 1; in unified_IOP_port_name()
434 if (iface == NULL) { /* oops, we didn't get the memory requested */ in translate_IOP_to_pcap_name()
440 iface->iftype = iftype; /* remember the interface type of this interface */ in translate_IOP_to_pcap_name()
442 iface->IOPname = strdup(IOPname); /* copy it and stick it into the structure */ in translate_IOP_to_pcap_name()
443 if (iface->IOPname == NULL) { /* oops, we didn't get the memory requested */ in translate_IOP_to_pcap_name()
483 iface->name = strdup(buf); /* make a copy and stick it into the structure */ in translate_IOP_to_pcap_name()
484 if (iface->name == NULL) { /* oops, we didn't get the memory requested */ in translate_IOP_to_pcap_name()
489 if (u->iface == 0) { /* if this is the first name */ in translate_IOP_to_pcap_name()
490 u->iface = iface; /* stick this entry at the head of the list */ in translate_IOP_to_pcap_name()
492 iface_ptr = u->iface; in translate_IOP_to_pcap_name()
493 while (iface_ptr->next) { /* otherwise scan the list */ in translate_IOP_to_pcap_name()
494 iface_ptr = iface_ptr->next; /* till we're at the last entry */ in translate_IOP_to_pcap_name()
496 iface_ptr->next = iface; /* then tack this entry on the end of the list */ in translate_IOP_to_pcap_name()
498 return iface->name; in translate_IOP_to_pcap_name()
508 s1_p1_len = s1_p2 - s1; /* the prefix length is the difference in pointers */ in if_sort()
512 s1_p2 = 0; /* and there is no suffix */ in if_sort()
515 s2_p1_len = s2_p2 - s2; in if_sort()
538 while ((p2 = p1->next)) { in sort_if_table()
539 if (if_sort(p1->name, p2->name) > 0) { in sort_if_table()
541 temp = p2->next; in sort_if_table()
542 prev->next = p2; in sort_if_table()
543 p2->next = p1; in sort_if_table()
544 p1->next = temp; in sort_if_table()
546 temp = p2->next; in sort_if_table()
548 p2->next = p1; in sort_if_table()
549 p1->next = temp; in sort_if_table()
556 p1 = p1->next; in sort_if_table()
564 static int process_client_data (char *errbuf) { /* returns: -1 = error, 0 = OK */ in process_client_data()
582 ptr = u->imsg; /* point to the start of the msg for this IOP */ in process_client_data()
583 while (ptr < (u->imsg + u->len)) { in process_client_data()
587 return -1; in process_client_data()
591 if (prev_iff) prev_iff->next = iff; /* insert a forward link */ in process_client_data()
594 if ((iff->name = malloc(*ptr + 1)) == NULL) { /* get that amount of space */ in process_client_data()
598 return -1; in process_client_data()
600 memcpy(iff->name, (ptr + 1), *ptr); /* copy the name into the malloc'ed space */ in process_client_data()
601 *(iff->name + *ptr) = 0; /* and null terminate the string */ in process_client_data()
607 if ((iff->description = malloc(*ptr + 1)) == NULL) { /* get that amount of space */ in process_client_data()
611 return -1; in process_client_data()
613 memcpy(iff->description, (ptr + 1), *ptr); /* copy the name into the malloc'ed space */ in process_client_data()
614 *(iff->description + *ptr) = 0; /* and null terminate the string */ in process_client_data()
623 …if (flags) iff->flags = PCAP_IF_LOOPBACK; /* if this is a loopback style interface, lets mark … in process_client_data()
628 while (address_count--) { in process_client_data()
633 return -1; in process_client_data()
636 if (iff->addresses == 0) iff->addresses = addr; in process_client_data()
637 if (prev_addr) prev_addr->next = addr; /* insert a forward link */ in process_client_data()
643 return -1; in process_client_data()
646 addr->addr = (struct sockaddr *)s; in process_client_data()
647 s->sin_family = AF_INET; in process_client_data()
648 s->sin_addr.s_addr = *(bpf_u_int32 *)(ptr + 1); /* copy the address in */ in process_client_data()
657 return -1; in process_client_data()
662 addr->netmask = (struct sockaddr *)s; in process_client_data()
663 s->sin_family = AF_INET; in process_client_data()
664 s->sin_addr.s_addr = *(bpf_u_int32*)(ptr + 1); in process_client_data()
673 return -1; in process_client_data()
678 addr->broadaddr = (struct sockaddr *)s; in process_client_data()
679 s->sin_family = AF_INET; in process_client_data()
680 s->sin_addr.s_addr = *(bpf_u_int32*)(ptr + 1); in process_client_data()
689 return -1; in process_client_data()
694 addr->dstaddr = (struct sockaddr *)s; in process_client_data()
695 s->sin_family = AF_INET; in process_client_data()
696 s->sin_addr.s_addr = *(bpf_u_int32*)(ptr + 1); in process_client_data()
704 …newname = translate_IOP_to_pcap_name(u, iff->name, interfaceType); /* add a translation entry and… in process_client_data()
705 bigger_buffer = realloc(iff->name, strlen(newname) + 1); in process_client_data()
706 if (bigger_buffer == NULL) { /* we now re-write the name stored in the interface list */ in process_client_data()
709 return -1; in process_client_data()
711 iff->name = bigger_buffer; in process_client_data()
712 strcpy(iff->name, newname); /* to this new name */ in process_client_data()
729 if ((u->imsg = realloc(u->imsg, (u->len + len))) == NULL) /* extend the buffer for the new data */ in read_client_data()
731 memcpy((u->imsg + u->len), buf, len); /* append the new data */ in read_client_data()
732 u->len += len; in read_client_data()
756 if (retval == -1) { /* an error occurred !!!!! */ in wait_for_all_answers()
775 static char *get_error_response(int fd, char *errbuf) { /* return a pointer on error, NULL on no e… in get_error_response()
792 int acn_findalldevs(char *errbuf) { /* returns: -1 = error, 0 = OK */ in acn_findalldevs()
801 if (u->ip && (open_with_IOP(u, FIND))) { /* connect to the remote IOP */ in acn_findalldevs()
802 send_to_fd(u->find_fd, 1, (unsigned char *)"\0"); in acn_findalldevs()
803 if (get_error_response(u->find_fd, errbuf)) in acn_findalldevs()
806 if (u->find_fd > max_fs) in acn_findalldevs()
807 max_fs = u->find_fd; /* remember the highest number currently in use */ in acn_findalldevs()
808 FD_SET(u->find_fd, &readfds); /* we are going to want to read this guy's response to */ in acn_findalldevs()
809 u->len = 0; in acn_findalldevs()
810 send_to_fd(u->find_fd, 1, (unsigned char *)"Q"); /* this interface query request */ in acn_findalldevs()
817 return -1; in acn_findalldevs()
825 send_to_fd(handle->fd, 1, (unsigned char *)"S"); /* send the get_stats command to the IOP */ in pcap_stats_acn()
827 …if (read_client_nbytes(handle->fd, sizeof(buf), buf) == -1) return -1; /* try reading the required… in pcap_stats_acn()
829 …ps->ps_recv = ntohl(*(uint32_t *)&buf[0]); /* break the buffer into its three 32 bit compon… in pcap_stats_acn()
830 ps->ps_drop = ntohl(*(uint32_t *)&buf[4]); in pcap_stats_acn()
831 ps->ps_ifdrop = ntohl(*(uint32_t *)&buf[8]); in pcap_stats_acn()
846 if (u->ip != NULL) { in acn_open_live()
847 p = u->iface; in acn_open_live()
849 …if (p->IOPname && p->name && (strcmp(p->name, name) == 0)) { /* and if we found the interface w… in acn_open_live()
850 *linktype = p->iftype; in acn_open_live()
852 …send_to_fd(u->fd, strlen(p->IOPname)+1, (unsigned char *)p->IOPname); /* send the IOP's interface … in acn_open_live()
853 if (get_error_response(u->fd, errbuf)) { in acn_open_live()
854 return -1; in acn_open_live()
856 return u->fd; /* and return that open descriptor */ in acn_open_live()
858 p = p->next; in acn_open_live()
863 return -1; /* if the interface wasn't found, return an error */ in acn_open_live()
872 if (u->first_time == 0) { in acn_start_monitor()
880 u->first_time = 1; in acn_start_monitor()
886 pcapint_strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters", in pcap_inject_acn()
888 return (-1); in pcap_inject_acn()
892 int fd = handle->fd; in pcap_setfilter_acn()
899 count = bpf->bf_len; in pcap_setfilter_acn()
902 p = bpf->bf_insns; in pcap_setfilter_acn()
903 while (count--) { /* followed by the list of instructions */ in pcap_setfilter_acn()
904 shortInt = htons(p->code); in pcap_setfilter_acn()
905 longInt = htonl(p->k); in pcap_setfilter_acn()
907 send_to_fd(fd, 1, (unsigned char *)&p->jt); in pcap_setfilter_acn()
908 send_to_fd(fd, 1, (unsigned char *)&p->jf); in pcap_setfilter_acn()
913 return -1; in pcap_setfilter_acn()
929 fd = handle->fd; in acn_read_n_bytes_with_timeout()
933 bp = handle->bp; in acn_read_n_bytes_with_timeout()
936 if (retval == -1) { /* an error occurred !!!!! */ in acn_read_n_bytes_with_timeout()
938 return -1; /* but we need to return a good indication to prevent unnecessary popups */ in acn_read_n_bytes_with_timeout()
941 return -1; in acn_read_n_bytes_with_timeout()
945 return -1; in acn_read_n_bytes_with_timeout()
947 count -= len; in acn_read_n_bytes_with_timeout()
960 …acn_start_monitor(handle->fd, handle->snapshot, handle->opt.timeout, handle->opt.promisc, handle->… in pcap_read_acn()
963 handle->bp = packet_header; in pcap_read_acn()
964 …if (acn_read_n_bytes_with_timeout(handle, HEADER_SIZE) == -1) return 0; /* try to read a packet … in pcap_read_acn()
971 …handle->bp = (u_char *)handle->buffer + handle->offset; /* start off the receive pointer a… in pcap_read_acn()
972 …if (acn_read_n_bytes_with_timeout(handle, pcap_header.caplen) == -1) return 0; /* then try to read… in pcap_read_acn()
974 callback(user, &pcap_header, handle->bp); /* call the user supplied callback function */ in pcap_read_acn()
981 if (handle->opt.rfmon) { in pcap_activate_sita()
983 * No monitor mode on SITA devices (they're not Wi-Fi in pcap_activate_sita()
991 handle->inject_op = pcap_inject_acn; in pcap_activate_sita()
992 handle->setfilter_op = pcap_setfilter_acn; in pcap_activate_sita()
993 handle->setdirection_op = NULL; /* Not implemented */ in pcap_activate_sita()
994 handle->set_datalink_op = NULL; /* can't change data link type */ in pcap_activate_sita()
995 handle->getnonblock_op = pcapint_getnonblock_fd; in pcap_activate_sita()
996 handle->setnonblock_op = pcapint_setnonblock_fd; in pcap_activate_sita()
997 handle->cleanup_op = pcap_cleanup_acn; in pcap_activate_sita()
998 handle->read_op = pcap_read_acn; in pcap_activate_sita()
999 handle->stats_op = pcap_stats_acn; in pcap_activate_sita()
1001 fd = acn_open_live(handle->opt.device, handle->errbuf, in pcap_activate_sita()
1002 &handle->linktype); in pcap_activate_sita()
1003 if (fd == -1) in pcap_activate_sita()
1014 if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN) in pcap_activate_sita()
1015 handle->snapshot = MAXIMUM_SNAPLEN; in pcap_activate_sita()
1017 handle->fd = fd; in pcap_activate_sita()
1018 handle->bufsize = handle->snapshot; in pcap_activate_sita()
1022 handle->buffer = malloc(handle->bufsize + handle->offset); in pcap_activate_sita()
1023 if (!handle->buffer) { in pcap_activate_sita()
1024 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, in pcap_activate_sita()
1031 * "handle->fd" is a socket, so "select()" and "poll()" in pcap_activate_sita()
1034 handle->selectable_fd = handle->fd; in pcap_activate_sita()
1046 p->activate_op = pcap_activate_sita; in pcapint_create_interface()
1059 return -1; in pcapint_platform_finddevs()
1065 return -1; in pcapint_platform_finddevs()
1067 devlistp->beginning = acn_if_list; in pcapint_platform_finddevs()
1079 return PCAP_VERSION_STRING " (SITA-only)"; in pcap_lib_version()