⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 olsrd_txtinfo.c

📁 wifi 无线网络路由协议OLSR linux下C代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        char requ[128];        ssize_t s = recv(ipc_connection, (void*)&requ, sizeof(requ), 0); /* Win32 needs the cast here */        if (0 < s) {            requ[s] = 0;            /* To print out neighbours only on the Freifunk Status             * page the normal output is somewhat lengthy. The             * header parsing is sufficient for standard wget.             */            neighonly = (0 != strstr(requ, "/neighbours"));        }    }    send_info(neighonly);	      close(ipc_connection);    ipc_open = 0;}static void ipc_print_neigh_link(void){    struct neighbor_entry *neigh;    struct neighbor_2_list_entry *list_2;    struct link_entry *link = NULL;    int index, thop_cnt;    ipc_sendf("Table: Links\nLocal IP\tremote IP\tHysteresis\tLinkQuality\tlost\ttotal\tNLQ\tETX\n");    /* Link set */    link = link_set;    while(link)	{	ipc_sendf( "%s\t%s\t%0.2f\t%0.2f\t%d\t%d\t%0.2f\t%0.2f\t\n",                   olsr_ip_to_string(&link->local_iface_addr),                   olsr_ip_to_string(&link->neighbor_iface_addr),                   link->L_link_quality,                    link->loss_link_quality,                   link->lost_packets,                    link->total_packets,                   link->neigh_link_quality,                    (link->loss_link_quality * link->neigh_link_quality) ? 1.0 / (link->loss_link_quality * link->neigh_link_quality) : 0.0);        link = link->next;    }    ipc_sendf("\nTable: Neighbors\nIP address\tSYM\tMPR\tMPRS\tWillingness\t2 Hop Neighbors\n");    /* Neighbors */    for(index = 0; index < HASHSIZE; index++) {        for(neigh = neighbortable[index].next;            neigh != &neighbortable[index];            neigh = neigh->next) {            ipc_sendf("%s\t%s\t%s\t%s\t%d\t",                       olsr_ip_to_string(&neigh->neighbor_main_addr),                      (neigh->status == SYM) ? "YES" : "NO",                      neigh->is_mpr ? "YES" : "NO",                      olsr_lookup_mprs_set(&neigh->neighbor_main_addr) ? "YES" : "NO",                      neigh->willingness);            thop_cnt = 0;            for(list_2 = neigh->neighbor_2_list.next;                list_2 != &neigh->neighbor_2_list;                list_2 = list_2->next)                {                    //size += sprintf(&buf[size], "<option>%s</option>\n", olsr_ip_to_string(&list_2->neighbor_2->neighbor_2_addr));                    thop_cnt ++;                }            ipc_sendf("%d\n", thop_cnt);	}    }    ipc_sendf("\n");}static void ipc_print_routes(void){    struct rt_entry *rt;    struct avl_node *rt_tree_node;    ipc_sendf("Table: Routes\nDestination\tGateway\tMetric\tETX\tInterface\n");    /* Walk the route table */    for (rt_tree_node = avl_walk_first(&routingtree);         rt_tree_node;         rt_tree_node = avl_walk_next(rt_tree_node)) {        rt = rt_tree_node->data;        ipc_sendf( "%s/%d\t%s\t%d\t%.3f\t%s\t\n",                   olsr_ip_to_string(&rt->rt_dst.prefix),                   rt->rt_dst.prefix_len,                   olsr_ip_to_string(&rt->rt_best->rtp_nexthop.gateway),                   rt->rt_best->rtp_metric.hops,                   rt->rt_best->rtp_metric.etx,                   if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));    }    ipc_sendf("\n");}static void ipc_print_topology(void){    struct tc_entry *tc;    struct tc_edge_entry *tc_edge;    ipc_sendf("Table: Topology\nDestination IP\tLast hop IP\tLQ\tILQ\tETX\n");    /* Topology */      OLSR_FOR_ALL_TC_ENTRIES(tc) {        OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {            ipc_sendf( "%s\t%s\t%0.2f\t%0.2f\t%0.2f\n",                        olsr_ip_to_string(&tc_edge->T_dest_addr),                       olsr_ip_to_string(&tc->addr),                        tc_edge->link_quality,                       tc_edge->inverse_link_quality,                       (tc_edge->link_quality * tc_edge->inverse_link_quality) ? 1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality) : 0.0);        } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);    } OLSR_FOR_ALL_TC_ENTRIES_END(tc);    ipc_sendf("\n");}static void ipc_print_hna(void){    int size;    olsr_u8_t index;    struct hna_entry *tmp_hna;    struct hna_net *tmp_net;    struct hna4_entry *hna4;    struct hna6_entry *hna6;    size = 0;    ipc_sendf("Table: HNA\nNetwork\tNetmask\tGateway\n");    /* Announced HNA entries */    for(hna4 = olsr_cnf->hna4_entries; hna4; hna4 = hna4->next) {        ipc_sendf("%s\t%s\t%s\n",                  olsr_ip_to_string(&hna4->net),                  olsr_ip_to_string(&hna4->netmask),                  olsr_ip_to_string(&olsr_cnf->main_addr));    }    for(hna6 = olsr_cnf->hna6_entries; hna6; hna6 = hna6->next) {        ipc_sendf("%s\t%d\t%s\n",                  olsr_ip_to_string(&hna6->net),                  hna6->prefix_len,                  olsr_ip_to_string(&olsr_cnf->main_addr));    }    /* HNA entries */    for(index = 0; index < HASHSIZE; index++) {        tmp_hna = hna_set[index].next;        /* Check all entrys */        while(tmp_hna != &hna_set[index]) {            /* Check all networks */            tmp_net = tmp_hna->networks.next;	                  while(tmp_net != &tmp_hna->networks) {		if (AF_INET == olsr_cnf->ip_version) {                    ipc_sendf("%s\t%s\t%s\n",                              olsr_ip_to_string(&tmp_net->A_network_addr),                              olsr_ip_to_string((union olsr_ip_addr *)&tmp_net->A_netmask.v4),                              olsr_ip_to_string(&tmp_hna->A_gateway_addr));		} else {                    ipc_sendf("%s\t%d\t%s\n",                              olsr_ip_to_string(&tmp_net->A_network_addr),                              tmp_net->A_netmask.v6,                              olsr_ip_to_string(&tmp_hna->A_gateway_addr));		}                tmp_net = tmp_net->next;	    }	                  tmp_hna = tmp_hna->next;	}    }    ipc_sendf("\n");}static void ipc_print_mid(void){    int index;    unsigned short is_first;    struct mid_entry *entry;    struct mid_address *alias;    ipc_sendf("Table: MID\nIP\tAliases\n");    /* MID */    for(index = 0; index < HASHSIZE; index++) {        entry = mid_set[index].next;                while( entry != &mid_set[index] ) {            ipc_sendf( olsr_ip_to_string( &entry->main_addr ) );            alias = entry->aliases;            is_first = 1;            while( alias ) {                ipc_sendf( "%s%s",                           ( is_first ? "\t" : ";" ),                           olsr_ip_to_string( &alias->alias )                           );                alias = alias->next_alias;                is_first = 0;            }            entry = entry->next;            ipc_sendf("\n");        }    }    ipc_sendf("\n");}static void  send_info(int neighonly){    /* Print minimal http header */    ipc_sendf("HTTP/1.0 200 OK\n");    ipc_sendf("Content-type: text/plain\n\n");    /* Print tables to IPC socket */	    /* links + Neighbors */    ipc_print_neigh_link();	    /* topology */    if (!neighonly) ipc_print_topology();	    /* hna */    if (!neighonly) ipc_print_hna();    /* mid */    if (!neighonly) ipc_print_mid();    /* routes */    if (!neighonly) ipc_print_routes();}/* * In a bigger mesh, there are probs with the fixed * bufsize. Because the Content-Length header is * optional, the sprintf() is changed to a more * scalable solution here. */ static int  ipc_sendf(const char* format, ...){    char txtnetbuf[TXT_IPC_BUFSIZE];    va_list arg;    int rv;#if defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __MacOSX__    int flags = 0;#else    int flags = MSG_NOSIGNAL;#endif    va_start(arg, format);    rv = vsnprintf(txtnetbuf, sizeof(txtnetbuf), format, arg);    va_end(arg);    if(ipc_socket_up) {        if (0 > send(ipc_connection, txtnetbuf, rv, flags)) {#ifndef NODEBUG            olsr_printf(1, "(TXTINFO) Failed sending data to client!\n");#endif            close(ipc_connection);            return - 1;        }    }    return rv;}/* * Local Variables: * mode: c * style: linux * c-basic-offset: 4 * indent-tabs-mode: nil * End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -