static void handle_features_reply( uint64_t datapath_id, uint32_t transaction_id, uint32_t n_buffers, uint8_t n_tables, uint32_t capabilities, uint32_t actions, const list_element *phy_ports, void *user_data) { UNUSED( transaction_id ); UNUSED( n_buffers ); UNUSED( n_tables ); UNUSED( capabilities ); UNUSED( actions ); show_desc *show_desc = user_data; desc_entry *desc = lookup_hash_entry( show_desc->db, &datapath_id ); if ( desc == NULL ) { return; } display_desc( &desc->desc_stats ); display_datapath_id( datapath_id ); list_element ports_list; memcpy( &ports_list, phy_ports, sizeof( list_element ) ); for ( list_element *port = &ports_list; port != NULL; port = port->next ) { display_port( port->data ); } delete_hash_entry( show_desc->db, &datapath_id ); show_desc->count--; xfree( desc ); if ( show_desc->count == 0 ) { stop_trema(); } }
static void handle_port_desc_reply( uint64_t datapath_id, uint32_t transaction_id, uint16_t type, uint16_t flags, const buffer *data, void *user_data ) { UNUSED( transaction_id ); UNUSED( type ); UNUSED( flags ); show_desc *show_desc = user_data; desc_entry *desc = lookup_hash_entry( show_desc->db, &datapath_id ); if ( desc == NULL ) { return; } append_to_tail( &desc->port_desc, duplicate_buffer( data ) ); if ( more_requests( flags ) ) { return; } display_desc( &desc->desc_stats ); display_datapath_id( datapath_id ); for ( list_element *e = desc->port_desc; e != NULL; e = e->next ) { buffer *data = e->data; struct ofp_port *port = ( struct ofp_port * ) data->data; size_t length = data->length; while ( length >= sizeof( struct ofp_port ) ) { display_port( port ); length -= ( uint16_t ) sizeof( struct ofp_port ); port++; } free_buffer( e->data ); } delete_list( desc->port_desc ); delete_hash_entry( show_desc->db, &datapath_id ); show_desc->count--; xfree( desc ); if ( show_desc->count == 0 ) { stop_trema(); } }
int main(int argc, char **argv) { unsigned char buffer[BUFSIZE]; int dumpstyle = ASCII; int size; int s; char *port = NULL, *dev = NULL; struct sockaddr sa; socklen_t asize = sizeof(sa); struct ifreq ifr; int proto = ETH_P_AX25; int exit_code = EXIT_SUCCESS; timestamp = 0; while ((s = getopt(argc, argv, "8achip:rtv")) != -1) { switch (s) { case '8': sevenbit = 0; break; case 'a': proto = ETH_P_ALL; break; case 'c': color = 1; break; case 'h': dumpstyle = HEX; break; case 'i': ibmhack = 1; break; case 'p': port = optarg; break; case 'r': dumpstyle = READABLE; break; case 't': timestamp = 1; break; case 'v': printf("listen: %s\n", VERSION); return 0; case ':': fprintf(stderr, "listen: option -p needs a port name\n"); return 1; case '?': fprintf(stderr, "Usage: listen [-8] [-a] [-c] [-h] [-i] [-p port] [-r] [-t] [-v]\n"); return 1; } } if (ax25_config_load_ports() == 0) fprintf(stderr, "listen: no AX.25 port data configured\n"); if (port != NULL) { if ((dev = ax25_config_get_dev(port)) == NULL) { fprintf(stderr, "listen: invalid port name - %s\n", port); return 1; } } if ((sock = socket(PF_PACKET, SOCK_PACKET, htons(proto))) == -1) { perror("socket"); return 1; } if (color) { color = initcolor(); /* Initialize color support */ if (!color) printf("Could not initialize color support.\n"); } setservent(1); while (!sigint) { asize = sizeof(sa); signal(SIGINT, handle_sigint); signal(SIGTERM, handle_sigint); if ((size = recvfrom(sock, buffer, sizeof(buffer), 0, &sa, &asize)) == -1) { /* * Signals are cared for by the handler, and we * don't want to abort on SIGWINCH */ if (errno == EINTR) { refresh(); continue; } else if (!(errno == EBADF && sigint)) { perror("recv"); exit_code = errno; } break; } signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); if (sock == -1 || sigint) break; if (dev != NULL && strcmp(dev, sa.sa_data) != 0) continue; if (proto == ETH_P_ALL) { strcpy(ifr.ifr_name, sa.sa_data); signal(SIGINT, handle_sigint); signal(SIGTERM, handle_sigint); if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { if (!(errno == EBADF && sigint)) { perror("SIOCGIFHWADDR"); exit_code = errno; break; } } signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); if (sock == -1 || sigint) break; if (ifr.ifr_hwaddr.sa_family == AF_AX25) { display_port(sa.sa_data); #ifdef NEW_AX25_STACK ax25_dump(buffer, size, dumpstyle); #else ki_dump(buffer, size, dumpstyle); #endif /* lprintf(T_DATA, "\n"); */ } } else { display_port(sa.sa_data); #ifdef NEW_AX25_STACK ax25_dump(buffer, size, dumpstyle); #else ki_dump(buffer, size, dumpstyle); #endif /* lprintf(T_DATA, "\n"); */ } if (color) refresh(); } if (color) endwin(); return exit_code; }