int main(void) { // board setup stuff led_init(); uart_init(); floppy_low_init(); sdpin_init(); spi_low_cs_init(); spi_low_mst_init(); //timer_init(); // say hello uart_send_string((u08 *)"--- dfx-sampler sam7x/SPI ---"); uart_send_crlf(); // do initial setup rtc_init(); memory_init(); floppy_select_on(); track_init(); floppy_select_off(); net_init(); // print current RTC uart_send_string((u08 *)"rtc: "); uart_send_string((u08 *)rtc_get_time_str()); uart_send_crlf(); // show network info net_info(); while(1) { uart_send_string((u08 *)"> "); led_green(1); // get next command via SPI u08 *cmd; u08 len = cmd_uart_get_next(&cmd); led_green(0); if(len>0) { u08 result[CMD_MAX_SIZE]; u08 res_size = CMD_MAX_SIZE; // parse and execute command cmd_parse(len, cmd, &res_size, result); // report result if(res_size > 0) { uart_send_data(result, res_size); uart_send_crlf(); } } } }
int main(int argc, char* argv[]) { GError *error = NULL; GOptionContext *context; context = g_option_context_new ("[ip_address] [mask] - calculate network information"); g_option_context_add_main_entries (context, entries, NULL); //g_option_context_add_group (context, glib_get_option_group (TRUE)); if(!g_option_context_parse(context, &argc, &argv, &error)) { g_print("option parsing failed: %s\n", error->message); } if(verbose) { if(argc != 1) print_info(); } if(vlsm_counts) { if(argc == 3) vlsm_tree(argv[argc-2],argv[argc-1],vlsm_counts); } else if(do_host_count) { if(argc == 3) host_tree(argv[argc-2],argv[argc-1],do_host_count); } else if(do_net_count) { net_tree(argv[argc-2],argv[argc-1],do_net_count); } else if(do_summary) { net_summary(); } else { if(argc == 3) net_info(argv[argc-2],argv[argc-1]); else { print_info(); print_usage(); } } return 0; }
static int _send_connection_list(const char *user, const char *type) { const char *info_type = NULL; list *conn_list = NULL; if (strcmp(type, NET_LIST_CLIENTS) == 0) { info_type = NET_INFO_CLIENTS; conn_list = &g_clients; } else if (strcmp(type, NET_LIST_SERVERS) == 0) { info_type = NET_INFO_SERVERS; conn_list = &g_servers; } struct net_client *conn; list_foreach(conn_list, conn) { net_info(g_lobby, user, info_type, conn->name, conn->state, conn->connections); }
bool sinsp_container_manager::parse_rkt(sinsp_container_info *container, const string &podid, const string &appname) { bool ret = false; Json::Reader reader; Json::Value jroot; unordered_map<string, uint32_t> image_ports; char image_manifest_path[SCAP_MAX_PATH_SIZE]; snprintf(image_manifest_path, sizeof(image_manifest_path), "%s/var/lib/rkt/pods/run/%s/appsinfo/%s/manifest", scap_get_host_root(), podid.c_str(), appname.c_str()); ifstream image_manifest(image_manifest_path); if(reader.parse(image_manifest, jroot)) { container->m_image = jroot["name"].asString(); for(const auto& label_entry : jroot["labels"]) { container->m_labels.emplace(label_entry["name"].asString(), label_entry["value"].asString()); } auto version_label_it = container->m_labels.find("version"); if(version_label_it != container->m_labels.end()) { container->m_image += ":" + version_label_it->second; } for(const auto& image_port : jroot["app"]["ports"]) { image_ports.emplace(image_port["name"].asString(), image_port["port"].asUInt()); } ret = true; } char net_info_path[SCAP_MAX_PATH_SIZE]; snprintf(net_info_path, sizeof(net_info_path), "%s/var/lib/rkt/pods/run/%s/net-info.json", scap_get_host_root(), podid.c_str()); ifstream net_info(net_info_path); if(reader.parse(net_info, jroot) && jroot.size() > 0) { auto first_net = jroot[0]; if(inet_pton(AF_INET, first_net["ip"].asCString(), &container->m_container_ip) == -1) { ASSERT(false); } container->m_container_ip = ntohl(container->m_container_ip); } char pod_manifest_path[SCAP_MAX_PATH_SIZE]; snprintf(pod_manifest_path, sizeof(pod_manifest_path), "%s/var/lib/rkt/pods/run/%s/pod", scap_get_host_root(), podid.c_str()); ifstream pod_manifest(pod_manifest_path); if(reader.parse(pod_manifest, jroot) && jroot.size() > 0) { for(const auto& jport : jroot["ports"]) { auto host_port = jport["hostPort"].asUInt(); if(host_port > 0) { sinsp_container_info::container_port_mapping port_mapping; port_mapping.m_host_port = host_port; port_mapping.m_container_port = image_ports.at(jport["name"].asString()); container->m_port_mappings.emplace_back(move(port_mapping)); } } } return ret; }
// wiznet commands static void cmd_wiznet(void) { u08 cmd, res, val; u16 addr, wval; u08 exit = 0; while((cmd = get_char()) != 0) { switch(cmd) { // ---------- low level/debug ---------- case 'r': // low level: read byte <addr/16> addr = parse_hex_byte(0) << 8 | parse_hex_byte(0); wiz_low_begin(); res = wiz_low_read(addr); wiz_low_end(); set_result(res); uart_send_hex_word_space(addr); uart_send_hex_byte_crlf(res); break; case 'w': // low level: write byte <addr/16><val/8> addr = parse_hex_byte(0) << 8 | parse_hex_byte(0); val = parse_hex_byte(0); wiz_low_begin(); wiz_low_write(addr,val); wiz_low_end(); set_result(val); uart_send_hex_word_space(addr); uart_send_hex_byte_crlf(val); break; case 'R': // low level: read word <addr/16> addr = parse_hex_byte(0) << 8 | parse_hex_byte(0); wiz_low_begin(); res = wiz_low_read_word(addr); wiz_low_end(); set_result(res); uart_send_hex_word_space(addr); uart_send_hex_word_crlf(res); break; case 'W': // low level: write byte <addr/16><val/8> addr = parse_hex_byte(0) << 8 | parse_hex_byte(0); wval = parse_hex_byte(0) << 8 | parse_hex_byte(0); wiz_low_begin(); wiz_low_write_word(addr,wval); wiz_low_end(); set_result(wval); uart_send_hex_word_space(addr); uart_send_hex_word_crlf(wval); break; // ---------- config ---------- case '?': net_info(); break; case 'm': // set mac addr 6*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<6;i++) { wc->mac_addr[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 's': // set src ip 4*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<4;i++) { wc->src_ip[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 't': // set tgt ip 4*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<4;i++) { wc->tgt_ip[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 'n': // set netmask 4*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<4;i++) { wc->net_msk[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 'g': // set gateway 4*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<4;i++) { wc->gw_ip[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 'o': // src port { wiz_cfg_t *wc = wiz_get_cfg(); wc->src_port = parse_hex_word(1234); } break; case 'p': // tgt port { wiz_cfg_t *wc = wiz_get_cfg(); wc->tgt_port = parse_hex_word(6800); } break; // ----- load/save config ----- case 'S': // save to sram wiz_save_cfg(); break; case 'L': // load from sram wiz_load_cfg(); wiz_realize_cfg(); break; case 'c': // connect test { int result = wiz_begin_tcp_client(); if(result == 0) { uart_send_string((u08 *)"connected"); const char *hw = "hello world!\r\n"; wiz_write_tcp((u08 *)hw, 14); uart_send_string((u08 *)"disconnect"); wiz_end_tcp_client(); } set_result(result); } break; case 'i': net_init(); break; default: set_result(ERROR_SYNTAX); case '.': exit = 1; break; } if(exit) break; } }