struct interface * if_ifwithaddr(const union olsr_ip_addr *addr) { struct interface *ifp; if(!addr) return NULL; for (ifp = ifnet; ifp; ifp = ifp->int_next) { if(olsr_cnf->ip_version == AF_INET) { /* IPv4 */ //printf("Checking: %s == ", inet_ntoa(((struct sockaddr_in *)&ifp->int_addr)->sin_addr)); //printf("%s\n", olsr_ip_to_string(addr)); if (((struct sockaddr_in *)&ifp->int_addr)->sin_addr.s_addr == addr->v4.s_addr) return ifp; } else { /* IPv6 */ //printf("Checking %s ", olsr_ip_to_string((union olsr_ip_addr *)&ifp->int6_addr.sin6_addr)); //printf("== %s\n", olsr_ip_to_string((union olsr_ip_addr *)&((struct sockaddr_in6 *)addr)->sin6_addr)); if (ip6equal(&ifp->int6_addr.sin6_addr, &addr->v6)) return ifp; } } return NULL; }
/** * Check if a hello message states this node as a MPR. * * @param message the message to check * @param n_link the buffer to put the link status in * *@return 1 if we are selected as MPR 0 if not */ static bool lookup_mpr_status(const struct hello_message *message, const struct interface *in_if) { struct hello_neighbor *neighbors; for (neighbors = message->neighbors; neighbors; neighbors = neighbors->next) { if ( neighbors->link != UNSPEC_LINK && (olsr_cnf->ip_version == AF_INET ? ip4equal(&neighbors->address.v4, &in_if->ip_addr.v4) : ip6equal(&neighbors->address.v6, &in_if->int6_addr.sin6_addr))) { if (neighbors->link == SYM_LINK && neighbors->status == MPR_NEIGH) { return true; } break; } } /* Not found */ return false; }
/** * write latlon positions to a file */ void mapwrite_work(FILE* fmap) { int hash; struct olsr_if *ifs; union olsr_ip_addr ip; struct ipaddr_str strbuf1, strbuf2; struct tc_entry *tc; struct tc_edge_entry *tc_edge; if (!my_names || !fmap) return; for (ifs = olsr_cnf->interfaces; ifs; ifs = ifs->next) { if (0 != ifs->interf) { if (olsr_cnf->ip_version == AF_INET) { if (!(ip4equal((struct in_addr *)&olsr_cnf->main_addr, &ifs->interf->int_addr.sin_addr))) { if (0 > fprintf(fmap, "Mid('%s','%s');\n", olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr), olsr_ip_to_string(&strbuf2, (union olsr_ip_addr *)&ifs->interf->int_addr.sin_addr))) { return; } } } else if (!(ip6equal((struct in6_addr *)&olsr_cnf->main_addr, &ifs->interf->int6_addr.sin6_addr))) { if (0 > fprintf(fmap, "Mid('%s','%s');\n", olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr), olsr_ip_to_string(&strbuf2, (union olsr_ip_addr *)&ifs->interf->int6_addr.sin6_addr))) { return; } } } } for (hash = 0; hash < HASHSIZE; hash++) { struct mid_entry *entry = mid_set[hash].next; while(entry != &mid_set[hash]) { struct mid_address *alias = entry->aliases; while(alias) { if (0 > fprintf(fmap, "Mid('%s','%s');\n", olsr_ip_to_string(&strbuf1, &entry->main_addr), olsr_ip_to_string(&strbuf2, &alias->alias))) { return; } alias = alias->next_alias; } entry = entry->next; } } lookup_defhna_latlon(&ip); sprintf(my_latlon_str, "%f,%f,%d", my_lat, my_lon, get_isdefhna_latlon()); if (0 > fprintf(fmap, "Self('%s',%s,'%s','%s');\n", olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr), my_latlon_str, olsr_ip_to_string(&strbuf2, &ip), my_names->name)) { return; } for (hash = 0; hash < HASHSIZE; hash++) { struct db_entry *entry; struct list_node *list_head, *list_node; list_head = &latlon_list[hash]; for (list_node = list_head->next; list_node != list_head; list_node = list_node->next) { entry = list2db(list_node); if (NULL != entry->names) { if (0 > fprintf(fmap, "Node('%s',%s,'%s','%s');\n", olsr_ip_to_string(&strbuf1, &entry->originator), entry->names->name, olsr_ip_to_string(&strbuf2, &entry->names->ip), lookup_name_latlon(&entry->originator))) { return; } } } } OLSR_FOR_ALL_TC_ENTRIES(tc) { OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) { char* lla = lookup_position_latlon(&tc->addr); char* llb = lookup_position_latlon(&tc_edge->T_dest_addr); if (NULL != lla && NULL != llb) { struct lqtextbuffer lqbuffer, lqbuffer2; /* * To speed up processing, Links with both positions are named PLink() */ if (0 > fprintf(fmap, "PLink('%s','%s',%s,%s,%s,%s);\n", olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr), olsr_ip_to_string(&strbuf2, &tc->addr), get_tc_edge_entry_text(tc_edge, ',', &lqbuffer2), get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer), lla, llb)) { return; } } else { struct lqtextbuffer lqbuffer, lqbuffer2; /* * If one link end pos is unkown, only send Link() */ if (0 > fprintf(fmap, "Link('%s','%s',%s,%s);\n", olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr), olsr_ip_to_string(&strbuf2, &tc->addr), get_tc_edge_entry_text(tc_edge, ',', &lqbuffer2), get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer))) { return; } } } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge); } OLSR_FOR_ALL_TC_ENTRIES_END(tc);