/** * ip_range_split() callback. * * Insert IP range in database, linking it to the proper country code. */ static void gip_add_cidr(uint32 ip, uint bits, void *udata) { struct range_context *ctx = udata; iprange_err_t error; uint16 cc; if (GNET_PROPERTY(reload_debug) > 4) printf("GEO adding %s/%d for \"%s\"\n", ip_to_string(ip), bits, ctx->line); cc = ctx->country; error = iprange_add_cidr(geo_db, ip, bits, cc); switch (error) { case IPR_ERR_OK: break; /* FALL THROUGH */ default: g_warning("%s, line %d: rejected entry \"%s\" (%s/%d): %s", gip_source[GIP_IPV4].file, ctx->linenum, ctx->line, ip_to_string(ip), bits, iprange_strerror(error)); return; } }
/* * the main method * receives a Flow message and prints out its associated information * If the message belongs to another class, an exception is thrown. */ virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { if ( m->type() == MSG_ID(Flow) ) { auto flow = static_cast<const Flow *>(m.get()); std::stringstream ss; const FlowKey& fk = flow->key(); int duration = flow->end_time() - flow->start_time(); ss<<"packets="<<flow->packets() << ","; ss<<"bytes="<<flow->bytes() << ","; ss<<"start="<<flow->start_time() << ","; ss<<"end="<<flow->end_time() << ","; ss<<"duration.us="<<duration<< ","; ss<<"source.ip4="<<ip_to_string(fk.src_ip4)<< ","; ss<<"source.port="<<fk.src_port<< ","; ss<<"destination.ip4="<<ip_to_string(fk.dst_ip4)<< ","; ss<<"destination.port="<<fk.dst_port; /* ss<<"Flow of "<< flow->packets() << " packets and "<<flow->bytes()<<" bytes begin at "<<flow->start_time()<<" end at "<<flow->end_time()<< "duration (ms.) "<<duration <<std::endl; ss<<"SRC IP "<<ip_to_string(fk.src_ip4)<<" SRC port "<<fk.src_port<<std::endl; ss<<"DST IP "<<ip_to_string(fk.dst_ip4)<<" DST port "<<fk.dst_port<<std::endl; //ss<<"protocol "<<fk.proto<<std::endl; */ blocklog(ss.str(),log_info); } else { throw std::runtime_error("Flowprinter: wrong message type"); } }
int main(int argc, char *argv[]) { if (argc > 1) { return mainUtil(argc, argv); }; printf("Kernel IPv4 routing table:\n"); printf("Network Gateway Interface\n"); int fd = _glidix_routetab(AF_INET); _glidix_in_route route; while (1) { ssize_t count = read(fd, &route, sizeof(_glidix_in_route)); if (count < sizeof(_glidix_in_route)) { break; }; char network[20]; char gate[17]; ip_to_string(&route.dest, &route.mask, network); ip_to_string(&route.gateway, NULL, gate); printf("%s%s%s\n", network, gate, route.ifname); }; close(fd); printf("\nKernel IPv6 routing table:\n"); printf("Network Next hop Interface\n"); fd = _glidix_routetab(AF_INET6); _glidix_in6_route route6; while (1) { ssize_t count = read(fd, &route6, sizeof(_glidix_in6_route)); if (count < sizeof(_glidix_in6_route)) { break; }; char network[35]; char gateway[35]; ip6_to_string(&route6.dest, &route6.mask, network); ip6_to_string(&route6.gateway, NULL, gateway); printf("%s%s%s\n", network, gateway, route6.ifname); }; close(fd); return 0; };
void fprintf_route(FILE *out, struct route *route) { fprintf(out, "%-15s %-15s %-15s %.2x:%.2x:%.2x:%.2x:%.2x:%.2x %-5s %-6d %.2x:%.2x:%.2x:%.2x:%.2x:%.2x %-15s\n", ip_to_string(route->destination), ip_to_string(route->netmask), ip_to_string(route->gateway), PRINT_MAC(route->gateway_macaddress), route->interface.interface_name, route->interface.interface_index, PRINT_MAC(route->interface.interface_macaddress), ip_to_string(route->interface.interface_ipaddress) ); }
static void endpoints_to_string(FILE *s, const struct packet *packet) { char src_string[ADDR_STR_LEN]; char dst_string[ADDR_STR_LEN]; struct tuple tuple; get_packet_tuple(packet, &tuple); fprintf(s, "%s:%u > %s:%u", ip_to_string(&tuple.src.ip, src_string), ntohs(tuple.src.port), ip_to_string(&tuple.dst.ip, dst_string), ntohs(tuple.dst.port)); }
void ip_dissector_dump(const packet_t* packet) { if (!ip_dissector_handles(packet)) { return; } struct iphdr* header = (struct iphdr*) packet->data; printf(IP_OUTPUT_HEADER); printf("Source address : %s\n", ip_to_string(header->saddr)); printf("Destination address : %s\n", ip_to_string(header->daddr)); printf("Checksum : 0x%x\n", ntohs(header->check)); printf(IP_OUTPUT_FOOTER); }
/* Parse the IPv6 header and the TCP header inside. We do not * currently support parsing IPv6 extension headers or any layer 4 * protocol other than TCP. Return a packet_parse_result_t. * Note that packet_end points to the byte beyond the end of packet. */ static int parse_ipv6(struct packet *packet, u8 *header_start, u8 *packet_end, char **error) { u8 *p = header_start; packet->ipv6 = (struct ipv6 *) (p); /* Check that header fits in sniffed packet. */ const int ip_header_bytes = packet_ip_header_len(packet); assert(ip_header_bytes >= 0); assert(ip_header_bytes == sizeof(*packet->ipv6)); if (p + ip_header_bytes > packet_end) { asprintf(error, "IPv6 header overflows packet"); goto error_out; } /* Check that payload fits in sniffed packet. */ const int ip_total_bytes = (ip_header_bytes + ntohs(packet->ipv6->payload_len)); packet->ip_bytes = ip_total_bytes; if (p + ip_total_bytes > packet_end) { asprintf(error, "IPv6 payload overflows packet"); goto error_out; } assert(ip_header_bytes <= ip_total_bytes); /* Move on to the header inside. */ p += ip_header_bytes; assert(p <= packet_end); if (DEBUG_LOGGING) { char src_string[ADDR_STR_LEN]; char dst_string[ADDR_STR_LEN]; struct ip_address src_ip, dst_ip; ip_from_ipv6(&packet->ipv6->src_ip, &src_ip); ip_from_ipv6(&packet->ipv6->dst_ip, &dst_ip); DEBUGP("src IP: %s\n", ip_to_string(&src_ip, src_string)); DEBUGP("dst IP: %s\n", ip_to_string(&dst_ip, dst_string)); } /* Examine the L4 header. */ const int layer4_bytes = ip_total_bytes - ip_header_bytes; const int layer4_protocol = packet->ipv6->next_header; return parse_layer4(packet, p, layer4_protocol, layer4_bytes, packet_end, error); error_out: return PACKET_BAD; }
int ipc_eval_route_packet(struct routemsg *msg) { struct route_entry rt_ent; char dev[5]; char gw[16]; char itoa_buf[10]; dev[4] = '\0'; memset(&gw[0], 0, 16); printf("Processing route packet\n"); memset(rt_ent.if_name, 0, MAX_IF_NAMESIZ); /* Fill struct */ memcpy(&rt_ent.gw, &msg->gateway_addr, ipsize); memcpy(&rt_ent.dst, &msg->target_addr, ipsize); memcpy(rt_ent.if_name, msg->device, 4); rt_ent.hopcnt = msg->metric; if (msg->add) { memcpy(&dev[0], &msg->device[0], 4); /*Add node to node list */ memcpy(&gw[0], ip_to_string(&msg->gateway_addr), 16); gui_itoa(msg->metric, itoa_buf); route_list_add(ip_to_string(&msg->target_addr), gw, dev, itoa_buf); printf("\tRoute to %s(hc %d) added\n", ip_to_string(&msg->target_addr), rt_ent.hopcnt); /* printf("\tRoute to %s added\n", ip_to_string(&msg->target_addr)); printf("\tGateway %s\n", gw); printf("\tInterface %s\n", msg->device); printf("\tMetric %d\n", msg->metric); */ } else { if (route_list_del(ip_to_string(&msg->target_addr)) < 1) printf("COULD NOT FIND ROUTE TO DELETE!\n\n"); printf("\tRoute to %s deleted\n", ip_to_string(&msg->target_addr)); } return 1; }
void SyncedSDFileSystem::on_master_event(TCPSocketEvent e) { debug("MASTER: got event: %d", e); TCPSocketErr err; Host slave; TCPSocket *slave_socket; MasterNodeHandler *dispatcher; switch (e) { case TCPSOCKET_ACCEPT: debug("MASTER: accepting new connection"); err = tcp_socket_->accept(&slave, &slave_socket); if (err) { // TODO: handle errors } debug("MASTER: creating new handler"); dispatcher = new MasterNodeHandler(this, slave, slave_socket); node_handlers_.insert(pair<string, MasterNodeHandler *>(ip_to_string(slave.getIp()), dispatcher)); // dispatcher should destroy self when done or disconnected break; case TCPSOCKET_CONTIMEOUT: case TCPSOCKET_CONRST: case TCPSOCKET_CONABRT: case TCPSOCKET_ERROR: case TCPSOCKET_DISCONNECTED: // TODO: handle errors break; case TCPSOCKET_CONNECTED: case TCPSOCKET_READABLE: case TCPSOCKET_WRITEABLE: default: // these should never happen break; } }
void send_ARP_request(addr_ip_t ip, int num) { char ip_str[16]; ip_to_string(ip_str, ip); debug_println("Sending an ARP request (number %d) to %s:", num, ip_str); byte *packet = malloc_or_die(ARP_PACKET_LENGTH*sizeof(byte)); //Free'd (below). struct arp_hdr *arhdr = (void *)packet; ARH_HARD_TYPE_SET(arhdr, 1); ARH_PROTO_TYPE_SET(arhdr, IPV4_ETHERTYPE); ARH_HARD_LEN_SET(arhdr, 6); ARH_PROTO_LEN_SET(arhdr, 4); ARH_OP_SET(arhdr, 1); interface_t *interface = sr_integ_findsrcintf(ip); if (interface == NULL) { debug_println("ERROR: can't send ARP request, ip %s is not next hop!", ip_str); return; } ARH_SENDER_MAC_SET(arhdr, interface->mac); ARH_SENDER_IP_SET(arhdr, interface->ip); ARH_TARGET_IP_SET(arhdr, ip); ARH_TARGET_MAC_SET(arhdr, make_mac_addr(0, 0, 0, 0, 0, 0)); send_packet(packet, interface->ip, ip, 28, TRUE, FALSE); free(packet); }
/* Handle a DHCPDISCOVER message. */ static uint32_t discover(uint64_t hwaddr, uint32_t *siaddr) { lock_lock(); /* Figure out a suitable IP address to offer them */ uint32_t offer; do { offer = (my_ip & ~0xff) | (uint32_t)next_offer_octet; next_offer_octet++; } while ((offer & 0xff) == 0 || offer == my_ip || offer == routing_table[0] || offer == routing_table[1] || offer == routing_table[2] || offer == routing_table[3]); lock_unlock(); /* Pass them our IP address so they can pass it back to us when requested * IP assignment. This thing is in the DHCP spec to allow for multiple DHCP * servers on the same network. */ *siaddr = my_ip; char pretty_ip[STRLEN_IP]; ip_to_string(offer, pretty_ip); dprintf("%s: Sending DHCPOFFER of IP %s\n", get_instance_name(), pretty_ip); return offer; }
static void zuma_mbox_setenv(void) { char *data, buf[32]; unsigned char save = 0; data = getenv("baudrate"); if(!data || (zuma_console_baud != simple_strtoul(data, NULL, 10))) { sprintf(buf, "%6d", zuma_console_baud); setenv("baudrate", buf); save=1; printf("baudrate doesn't match from mbox\n"); } ip_to_string(zuma_ip, buf); setenv("ipaddr", buf); sprintf(buf,"%02x:%02x:%02x:%02x:%02x:%02x", zuma_prv_mac[0], zuma_prv_mac[1], zuma_prv_mac[2], zuma_prv_mac[3], zuma_prv_mac[4], zuma_prv_mac[5]); setenv("ethaddr", buf); sprintf(buf,"%02x",zuma_slot_bac); setenv("bacslot", buf); if(save) saveenv(); }
int process_mid(int size, olsr_u8_t vtime, union olsr_ip_addr *originator, union mid_message *m) { struct midaddr *midaddr; struct midaddr6 *midaddr6; printf("Processing MID from %s size = %d\n", ip_to_string(originator), size); /* Calculate size of the midinfo */ size = size - 4 - 4 - ipsize; if (ipversion == AF_INET) midaddr = &m->v4.mid_addr[0]; else midaddr6 = &m->v6.mid_addr[0]; //printf("MID size: %d\n", size); while (size > 0) { if (ipversion == AF_INET) { //printf("MID: add node %s\n", ip_to_string((union olsr_ip_addr *)&midaddr->addr)); add_mid_node(originator, (union olsr_ip_addr *)&midaddr->addr, vtime); midaddr++; } else { add_mid_node(originator, (union olsr_ip_addr *)&midaddr6->addr, vtime); //printf("MID: add node %s\n", ip_to_string((union olsr_ip_addr *)&midaddr6->addr)); midaddr6++; } size = size - ipsize; } //printf("DONE\n"); return 0; }
static void *am33xx_net_boot(void) { void *buf = NULL; int err; int len; struct dhcp_req_param dhcp_param; const char *bootfile, *ip; char *file; am33xx_register_ethaddr(0, 0); memset(&dhcp_param, 0, sizeof(struct dhcp_req_param)); dhcp_param.vendor_id = "am335x barebox-mlo"; err = dhcp(20, &dhcp_param); if (err) { printf("dhcp failed\n"); return NULL; } /* * Older tftp server don't send the file size. * Then tftpfs needs temporary place to store the file. */ err = mount("none", "ramfs", "/", NULL); if (err < 0) { printf("failed to mount ramfs\n"); return NULL; } err = make_directory(TFTP_MOUNT); if (err) return NULL; ip = ip_to_string(net_get_serverip()); err = mount(ip, "tftp", TFTP_MOUNT, NULL); if (err < 0) { printf("Unable to mount.\n"); return NULL; } bootfile = getenv("bootfile"); if (!bootfile) { printf("bootfile not found.\n"); return NULL; } file = asprintf("%s/%s", TFTP_MOUNT, bootfile); buf = read_file(file, &len); if (!buf) printf("could not read %s.\n", bootfile); free(file); umount(TFTP_MOUNT); return buf; }
/** * matches: * '/bgp/ipv4/all/from-asn/:asn/:length' * * @param bgp : main bgp instance * @param tokens : "api-get all-from-asn :asn :length" * @return a JSON array of prefixes owned by ASN */ std::string BGP::api_get_all_origin_as(BGP* bgp, std::vector<std::string>& tokens) { if (tokens.size() < 4) { return "{\"entries\":[\"prefix\":\"invalid number of parameters\"]}"; } bgp->lock_adj_rib_in(); uint32_t asn = string_to_uint32_t(tokens[2]); uint32_t length = string_to_uint32_t(tokens[3]); // container to hold matches std::vector<prefix_matches> ip_matches; uint8_t len = 0; for (bgp_adj_rib::iterator it_entry = bgp->get_adj_rib_in().begin(); it_entry != bgp->get_adj_rib_in().end(); ++it_entry) { if (it_entry->second.as_path != nullptr) { len = (it_entry->second.as_path->length - 1); // we only want blocks larger than or equal too /24 if (it_entry->second.nlri.prefix_length <= length) { if (it_entry->second.as_path->seg_value[len] == asn) { ip_matches.push_back({it_entry->second.nlri.prefix, it_entry->second.nlri.prefix_length}); } } } } bgp->unlock_adj_rib_in(); std::stringstream s_s; s_s.clear(); s_s << "{\"entries\":["; if (!ip_matches.empty()) { std::vector<prefix_matches>::iterator it_match; for (it_match = ip_matches.begin(); it_match != ip_matches.end(); ++it_match) { s_s << "\"" << ip_to_string(it_match->ip) << '/' << (int) it_match->length << "\""; if ((it_match + 1) != ip_matches.end()) { s_s << ","; } } } s_s << "]}"; return s_s.str(); }
std::string Alert::to_string() const { std::stringstream ss; ss << "Alert " << m_alert_name << " from " << m_analyzer; ss << " (" << m_identifier << "): "; for (unsigned int i = 0; i < m_sources.size(); i++) { if (i > 0) ss << ", "; ss << ip_to_string(m_sources[i].get_ipv4()); } ss << " -> "; for (unsigned int i = 0; i < m_targets.size(); i++) { if (i > 0) ss << ", "; ss << ip_to_string(m_targets[i].get_ipv4()); } return ss.str(); }
static void netboot_update_env (void) { char tmp[22]; if (NetOurGatewayIP) { ip_to_string (NetOurGatewayIP, tmp); setenv ("gatewayip", tmp); } if (NetOurSubnetMask) { ip_to_string (NetOurSubnetMask, tmp); setenv ("netmask", tmp); } if (NetOurHostName[0]) setenv ("hostname", NetOurHostName); if (NetOurRootPath[0]) setenv ("rootpath", NetOurRootPath); if (NetOurIP) { ip_to_string (NetOurIP, tmp); setenv ("ipaddr", tmp); } if (NetServerIP) { ip_to_string (NetServerIP, tmp); setenv ("serverip", tmp); } if (NetOurDNSIP) { ip_to_string (NetOurDNSIP, tmp); setenv ("dnsip", tmp); } #if defined(CONFIG_BOOTP_DNS2) if (NetOurDNS2IP) { ip_to_string (NetOurDNS2IP, tmp); setenv ("dnsip2", tmp); } #endif if (NetOurNISDomain[0]) setenv ("domain", NetOurNISDomain); #if defined(CONFIG_CMD_SNTP) \ && defined(CONFIG_BOOTP_TIMEOFFSET) if (NetTimeOffset) { sprintf (tmp, "%d", NetTimeOffset); setenv ("timeoffset", tmp); } #endif #if defined(CONFIG_CMD_SNTP) \ && defined(CONFIG_BOOTP_NTPSERVER) if (NetNtpServerIP) { ip_to_string (NetNtpServerIP, tmp); setenv ("ntpserverip", tmp); } #endif }
static inline int iprange_net_collision(const void *p, const void *q) { const struct iprange_net *a = p, *b = q; g_warning("iprange_sync(): %s/0x%x overlaps with %s/0x%x", ip_to_string(a->ip), a->mask, host_addr_to_string(host_addr_get_ipv4(b->ip)), b->mask); return a->mask < b->mask ? 1 : -1; }
static int iprange_net4_collision(const void *p, const void *q) { const struct iprange_net4 *a = p, *b = q; g_warning("iprange_sync(): %s/%u overlaps with %s/%u", ip_to_string(a->ip), a->bits, host_addr_to_string(host_addr_get_ipv4(b->ip)), b->bits); return a->bits < b->bits ? 1 : -1; }
static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char tmp[22]; if (NetLoop(LINKLOCAL) < 0) return 1; NetOurGatewayIP = 0; ip_to_string(NetOurGatewayIP, tmp); setenv("gatewayip", tmp); ip_to_string(NetOurSubnetMask, tmp); setenv("netmask", tmp); ip_to_string(NetOurIP, tmp); setenv("ipaddr", tmp); setenv("llipaddr", tmp); /* store this for next time */ return 0; }
int ipc_eval_net_info(struct netmsg *msg) { char info[256]; printf("Evaluating NET info...\n"); /* printf("\tMain address: %s\n", ip_to_string(&msg->main_addr)); printf("\tMid adresses: %d\n", msg->mids); printf("\tHna adresses: %d\n", msg->hnas); printf("\tHELLO interval: %f\n", (float)(ntohs(msg->hello_int))); printf("\tHELLO LAN interval: %f\n", (float)(ntohs(msg->hello_lan_int))); printf("\tTC interval: %d\n", ntohs(msg->tc_int)); printf("\tNeighbor hold time: %d\n", ntohs(msg->neigh_hold)); printf("\tTopology hold: %d\n", ntohs(msg->topology_hold)); */ if (msg->ipv6 == 0) { ipversion = AF_INET; ipsize = sizeof(struct in_addr); sprintf(&info[0], "IP version 4\nMain address: %s\nMid addresses: %d\nHna addresses: %d\nHELLO interval: %d\nHELLO LAN interval: %d\nTC interval: %d\nNeighbor hold time: %d\nTopology hold: %d\n", ip_to_string(&msg->main_addr), msg->mids, msg->hnas, ntohs(msg->hello_int), ntohs(msg->hello_lan_int), ntohs(msg->tc_int), ntohs(msg->neigh_hold), ntohs(msg->topology_hold)); } else { ipversion = AF_INET6; ipsize = sizeof(struct in6_addr); sprintf(&info[0], "IP version 6\nMain address: %s\nMid addresses: %d\nHna addresses: %d\nHELLO interval: %d\nHELLO LAN interval: %d\nTC interval: %d\nNeighbor hold time: %d\nTopology hold: %d\n", ip_to_string(&msg->main_addr), msg->mids, msg->hnas, ntohs(msg->hello_int), ntohs(msg->hello_lan_int), ntohs(msg->tc_int), ntohs(msg->neigh_hold), ntohs(msg->topology_hold)); } memcpy(&main_addr, &msg->main_addr, ipsize); set_net_info(&info[0], 0); return 0; }
int intf_to_string( interface_t* intf, char* buf, int len ) { const char* name; char mac[STRLEN_MAC]; char ip[STRLEN_IP]; const char* status; /* get the string representation of the interface */ name = intf->name; mac_to_string( mac, &intf->mac ); ip_to_string( ip, intf->ip ); status = ( intf->enabled ? "Up" : "Down" ); /* put the str rep into buf */ return my_snprintf( buf, len, STR_INTF_FORMAT, name, mac, ip, status ); }
IPaddr_t resolv(char *host) { IPaddr_t ip; const char *ns; if (!string_to_ip(host, &ip)) return ip; dns_ip = 0; dns_state = STATE_INIT; ns = getenv("net.nameserver"); if (!ns || !*ns) { printk("%s: no nameserver specified in $net.nameserver\n", __func__); return 0; } if (string_to_ip(ns, &ip)) return 0; debug("resolving host %s via nameserver %s\n", host, ip_to_string(ip)); dns_con = net_udp_new(ip, DNS_PORT, dns_handler, NULL); if (IS_ERR(dns_con)) return PTR_ERR(dns_con); dns_timer_start = get_time_ns(); dns_send(host); while (dns_state != STATE_DONE) { if (ctrlc()) { break; } net_poll(); if (is_timeout(dns_timer_start, SECOND)) { dns_timer_start = get_time_ns(); printf("T "); dns_send(host); } } net_unregister(dns_con); return dns_ip; }
/* Handle a DHCPREQ message */ static uint32_t request(unsigned int client, uint32_t ip, uint32_t siaddr) { if (siaddr != my_ip) { /* This message was intended for a different DHCP server. In a real * system we wouldn't send a DHCPNAK here, but would just ignore this * message. In this simulated setup we are the only server and we * *must* send a reply, so we just NAK it. */ dprintf("%s: Sending DHCPNAK due to server IP mismatch\n", get_instance_name()); return 0; } assert(client < routing_table_sz && "DHCPREQ from non-existent client"); lock_lock(); /* IP address the client gets. This will remain 0 after the logic below if * we're denying the client's request. */ uint32_t assigned = 0; if (routing_table[client] == ip) { /* They requested their existing IP. OK, whatever. */ dprintf("%s: Sending DHCPACK to client %u for its existing IP\n", get_instance_name(), client); assigned = ip; } else if (ip != my_ip && ip != 0 && ip != routing_table[0] && ip != routing_table[1] && ip != routing_table[2] && ip != routing_table[3]) { /* They requested an IP that was not ours, 0 or in the routing table * already. XXX: we should probably block the broadcast IP here too. */ char pretty_ip[STRLEN_IP]; ip_to_string(ip, pretty_ip); dprintf("%s: Sending DHCPACK to client %u of IP %s\n", get_instance_name(), client, pretty_ip); routing_table[client] = ip; assigned = ip; } lock_unlock(); return assigned; }
void set_net_info(gchar * info, int disp_button) { gchar title[255]; memset(&title[0], 0, sizeof(title)); gtk_label_set_text((GtkLabel *) info_label, info); gtk_label_set_text((GtkLabel *) net_label, "Connected"); snprintf(&title[0], sizeof(title), "%s - %s", olsrd_version, ip_to_string(&main_addr)); gtk_window_set_title(GTK_WINDOW(main_window), title); if (disp_button) gtk_widget_show(connect_button); else gtk_widget_hide(connect_button); }
int get_subjectaltname(X509* cert, char* buf, int buf_len){ /* Copy "," separated dNSName values of the subjectAltName extension, to pBuf */ GENERAL_NAMES *gens; GENERAL_NAME *gen; int i; char *sub_str= buf; int space_taken=0; int space_left= buf_len; gens = X509_get_ext_d2i(cert , NID_subject_alt_name, NULL, NULL); for(i = 0; i < sk_GENERAL_NAME_num(gens); i++){ gen = sk_GENERAL_NAME_value(gens, i); syslog(LOG_INFO,"1sub_str"); if((gen->type == GEN_DNS)||(gen->type == GEN_URI)){ if(0 < space_left) space_taken= copy_csv_to_buffer(sub_str, (char*)gen->d.ia5->data, buf_len, space_left); space_left= space_left -space_taken; } if(gen->type == GEN_IPADD) { if(0 < space_left) { const int oline_len = 40; char oline[oline_len]; oline[0]='\0'; ip_to_string(oline, oline_len, gen); space_taken= copy_csv_to_buffer(sub_str, oline, buf_len, space_left); space_left= space_left - space_taken; } } syslog(LOG_INFO,"2 sub_str: %s space_taken:%d space_left:%d",sub_str, space_taken, space_left); } sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); return CERT_OK; }
void handle_not_repsponding_to_arp(byte *payload, unsigned len) { debug_println("Not responding to arp:\n"); packet_info_t *pi = malloc_or_die(sizeof(packet_info_t)); //Free'd (below). pi->packet = malloc_or_die((IPV4_HEADER_OFFSET+len)*sizeof(uint8_t)); //Free'd (below). pi->len = len; memcpy(pi->packet+IPV4_HEADER_OFFSET, payload, len); struct eth_hdr *ethhdr = (void *)pi->packet; ETH_DEST_SET(ethhdr, make_mac_addr(0, 0, 0, 0, 0, 0)); ETH_SRC_SET(ethhdr, make_mac_addr(0, 0, 0, 0, 0, 0)); ETH_TYPE_SET(ethhdr, 0); //Reverse soruce and destination again. struct ip_hdr *iphdr;/* = (void *)pi->packet+IPV4_HEADER_OFFSET; swap_bytes(&IPH_SRC(iphdr), &IPH_DEST(iphdr), 4);*/ unsigned i; for (i = 0; i < pi->len; i += 2) printf("%02X%02X ", *(pi->packet+i),*(pi->packet+i+1)); printf("\n"); if (generate_response_ICMP_packet(pi, 3, 1)) return; iphdr = (void *)pi->packet+IPV4_HEADER_OFFSET; //pi->packet have moved in memory, so re-define. IPH_CHKSUM_SET(iphdr, 0); IPH_CHKSUM_SET(iphdr, htons(calc_checksum(pi->packet+IPV4_HEADER_OFFSET, IPV4_HEADER_LENGTH))); for (i = 0; i < pi->len; i += 2) printf("%02X%02X ", *(pi->packet+i),*(pi->packet+i+1)); printf("\n"); addr_ip_t target_ip = sr_integ_findnextip(IPH_DEST(iphdr)); char target_ip_str[STRLEN_IP]; ip_to_string(target_ip_str, target_ip); debug_println("target_ip=%s", target_ip_str); //send_packet(pi->packet+IPV4_HEADER_OFFSET, IPH_SRC(iphdr), target_ip, pi->len-IPV4_HEADER_OFFSET, FALSE, FALSE); free(pi->packet); free(pi); }
int process_tc(int size, olsr_u8_t vtime, union olsr_ip_addr *originator, union tc_message *m) { struct neigh_info *mprsinfo; struct neigh_info6 *mprsinfo6; printf("Processing TC from %s size = %d\n", ip_to_string(originator), size); /* Updating timer */ if (!update_timer_node(originator, vtime)) add_node(originator, vtime); /* Calculate size of the mprsinfo */ size = size - 4 - 8 - ipsize; //printf("TC Size: %d\n", size); if (ipversion == AF_INET) mprsinfo = &m->v4.neigh[0]; else mprsinfo6 = &m->v6.neigh[0]; while (size > 0) { if (ipversion == AF_INET) { //printf("\tprocessing TC: %s\n", ip_to_string((union olsr_ip_addr *)&mprsinfo->addr)); add_node((union olsr_ip_addr *)&mprsinfo->addr, vtime); update_timer_mpr((union olsr_ip_addr *)&mprsinfo->addr, originator, vtime); mprsinfo++; } else { //printf("\tprocessing TC: %s\n", ip_to_string((union olsr_ip_addr *)&mprsinfo6->addr)); //printf("TC: add node %s\n", ip_to_string((union olsr_ip_addr *)&mprsinfo6->addr)); add_node((union olsr_ip_addr *)&mprsinfo6->addr, vtime); update_timer_mpr((union olsr_ip_addr *)&mprsinfo6->addr, originator, vtime); mprsinfo6++; } size = size - ipsize; //printf("\tsize: %d\n", size); } //printf("DONE\n"); return 0; }
ip_mac_t *router_find_arp_entry( router_t *router, addr_ip_t ip) { char ip_str[STRLEN_IP]; ip_to_string(ip_str, ip); debug_println("Finding arp entry for %s.", ip_str); pthread_mutex_lock(&router->arp_cache_lock); unsigned i; for (i = 0; i < router->num_arp_cache; i++) { if (router->arp_cache[i].ip == ip) { pthread_mutex_unlock(&router->arp_cache_lock); return &router->arp_cache[i]; } } pthread_mutex_unlock(&router->arp_cache_lock); return NULL; }
/* *Remove a node from the list */ int remove_nodes_list(union olsr_ip_addr *node) { char *ip; char *in_ip = ip_to_string(node); int i; for (i = 0; i < node_list_size; i++) { gtk_clist_get_text(GTK_CLIST(node_list), i, 0, (gchar **) & ip); if (strcmp(in_ip, ip) == 0) { //printf("Found entry!\n"); gtk_clist_remove(GTK_CLIST(node_list), i); node_list_size--; return 1; } } return 0; }