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

📄 olsrd_httpinfo.c

📁 wifi 无线网络路由协议OLSR linux下C代码
💻 C
📖 第 1 页 / 共 3 页
字号:
            size += snprintf(&buf[size], bufsize-size, "<td>Hyst scaling: %0.2f</td>\n", olsr_cnf->hysteresis_param.scaling);            size += snprintf(&buf[size], bufsize-size, "<td>Hyst lower/upper: %0.2f/%0.2f</td>\n", olsr_cnf->hysteresis_param.thr_low, olsr_cnf->hysteresis_param.thr_high);          }      }    size += snprintf(&buf[size], bufsize-size, "</tr>\n<tr>\n");    size += snprintf(&buf[size], bufsize-size, "<td>LQ extension: %s</td>\n", olsr_cnf->lq_level ? "Enabled" : "Disabled");    if (olsr_cnf->lq_level)      {        size += snprintf(&buf[size], bufsize-size, "<td>LQ level: %d</td>\n", olsr_cnf->lq_level);        size += snprintf(&buf[size], bufsize-size, "<td>LQ winsize: %d</td>\n", olsr_cnf->lq_wsize);      }    size += snprintf(&buf[size], bufsize-size, "</tr></table>\n");    size += snprintf(&buf[size], bufsize-size, "<h2>Interfaces</h2>\n");    size += snprintf(&buf[size], bufsize-size, "<table width=\"100%%\" border=\"0\">\n");    for(ifs = olsr_cnf->interfaces; ifs; ifs = ifs->next)      {	struct interface *rifs = ifs->interf;	size += snprintf(&buf[size], bufsize-size, "<tr><th colspan=3>%s</th>\n", ifs->name);	if(!rifs)	  {	    size += snprintf(&buf[size], bufsize-size, "<tr><td colspan=3>Status: DOWN</td></tr>\n");	    continue;	  }		if(olsr_cnf->ip_version == AF_INET)	  {	    size += snprintf(&buf[size], bufsize-size, "<tr><td>IP: %s</td>\n", 			    sockaddr_to_string(&rifs->int_addr));	    size += snprintf(&buf[size], bufsize-size, "<td>MASK: %s</td>\n", 			    sockaddr_to_string(&rifs->int_netmask));	    size += snprintf(&buf[size], bufsize-size, "<td>BCAST: %s</td></tr>\n",			    sockaddr_to_string(&rifs->int_broadaddr));	    size += snprintf(&buf[size], bufsize-size, "<tr><td>MTU: %d</td>\n", rifs->int_mtu);	    size += snprintf(&buf[size], bufsize-size, "<td>WLAN: %s</td>\n", rifs->is_wireless ? "Yes" : "No");	    size += snprintf(&buf[size], bufsize-size, "<td>STATUS: UP</td></tr>\n");	  }	else	  {	    size += snprintf(&buf[size], bufsize-size, "<tr><td>IP: %s</td>\n", olsr_ip_to_string((union olsr_ip_addr *)&rifs->int6_addr.sin6_addr));	    size += snprintf(&buf[size], bufsize-size, "<td>MCAST: %s</td>\n", olsr_ip_to_string((union olsr_ip_addr *)&rifs->int6_multaddr.sin6_addr));	    size += snprintf(&buf[size], bufsize-size, "<td></td></tr>\n");	    size += snprintf(&buf[size], bufsize-size, "<tr><td>MTU: %d</td>\n", rifs->int_mtu);	    size += snprintf(&buf[size], bufsize-size, "<td>WLAN: %s</td>\n", rifs->is_wireless ? "Yes" : "No");	    size += snprintf(&buf[size], bufsize-size, "<td>STATUS: UP</td></tr>\n");	  }	          }    size += snprintf(&buf[size], bufsize-size, "</table>\n");    if(olsr_cnf->allow_no_interfaces)      size += snprintf(&buf[size], bufsize-size, "<em>Olsrd is configured to run even if no interfaces are available</em><br>\n");    else      size += snprintf(&buf[size], bufsize-size, "<em>Olsrd is configured to halt if no interfaces are available</em><br>\n");    size += snprintf(&buf[size], bufsize-size, "<h2>Plugins</h2>\n");    size += snprintf(&buf[size], bufsize-size, "<table width=\"100%%\" border=\"0\"><tr><th>Name</th><th>Parameters</th></tr>\n");    for(pentry = olsr_cnf->plugins; pentry; pentry = pentry->next)      {	size += snprintf(&buf[size], bufsize-size, "<tr><td>%s</td>\n", pentry->name);	size += snprintf(&buf[size], bufsize-size, "<td><select>\n");	size += snprintf(&buf[size], bufsize-size, "<option>KEY, VALUE</option>\n");	for(pparam = pentry->params; pparam; pparam = pparam->next)	  {	    size += snprintf(&buf[size], bufsize-size, "<option>\"%s\", \"%s\"</option>\n",			    pparam->key,			    pparam->value);	  }	size += snprintf(&buf[size], bufsize-size, "</select></td></tr>\n");      }    size += snprintf(&buf[size], bufsize-size, "</table>\n");    size += section_title(&buf[size], bufsize-size, "Announced HNA entries");    if((olsr_cnf->ip_version == AF_INET) && (olsr_cnf->hna4_entries))      {	struct hna4_entry *hna4;		size += snprintf(&buf[size], bufsize-size,                         "<tr><th>Network</th><th>Netmask</th></tr>\n");		for(hna4 = olsr_cnf->hna4_entries; hna4; hna4 = hna4->next)	  {	    size += snprintf(&buf[size], bufsize-size, "<tr><td>%s</td><td>%s</td></tr>\n", 			    olsr_ip_to_string(&hna4->net),			    olsr_ip_to_string(&hna4->netmask));	  }      }    else if((olsr_cnf->ip_version == AF_INET6) && (olsr_cnf->hna6_entries))      {	struct hna6_entry *hna6;		size += snprintf(&buf[size], bufsize-size,                         "<tr><th>Network</th><th>Prefix length</th></tr>\n");		for(hna6 = olsr_cnf->hna6_entries; hna6; hna6 = hna6->next)	  {	    size += snprintf(&buf[size], bufsize-size, "<tr><td>%s</td><td>%d</td></tr>\n", 			    olsr_ip_to_string(&hna6->net),			    hna6->prefix_len);	  }	      }    size += snprintf(&buf[size], bufsize-size, "</table>\n");    return size;}static int build_neigh_body(char *buf, olsr_u32_t bufsize){  struct neighbor_entry *neigh;  struct neighbor_2_list_entry *list_2;  struct link_entry *link = NULL;  int size = 0, index, thop_cnt;  size += section_title(&buf[size], bufsize-size, "Links");  size += snprintf(&buf[size], bufsize-size,                   "<tr><th>Local IP</th><th>Remote IP</th><th>Hysteresis</th>\n");  if (olsr_cnf->lq_level > 0) {    size += snprintf(&buf[size], bufsize-size, "<th align=\"right\">LinkQuality</th><th>lost</th><th>total</th><th align=\"right\">NLQ</th><th align=\"right\">ETX</th>\n");  }  size += snprintf(&buf[size], bufsize-size, "</tr>\n");  /* Link set */  link = link_set;    while(link)      {        size += snprintf(&buf[size], bufsize-size, "<tr>");        size += build_ipaddr_with_link(&buf[size], bufsize, &link->local_iface_addr, -1);        size += build_ipaddr_with_link(&buf[size], bufsize, &link->neighbor_iface_addr, -1);	size += snprintf(&buf[size], bufsize-size, "<td align=\"right\">%0.2f</td>", link->L_link_quality);        if (olsr_cnf->lq_level > 0) {	    size += snprintf(&buf[size], bufsize-size,                           "<td align=\"right\">%0.2f</td>"                           "<td>%d</td>"                           "<td>%d</td>"                           "<td align=\"right\">%0.2f</td>"                           "<td align=\"right\">%0.2f</td></tr>\n",                           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);        }	size += snprintf(&buf[size], bufsize-size, "</tr>\n");	link = link->next;      }  size += snprintf(&buf[size], bufsize-size, "</table>\n");  size += section_title(&buf[size], bufsize-size, "Neighbors");  size += snprintf(&buf[size], bufsize-size,                    "<tr><th>IP address</th><th align=\"center\">SYM</th><th align=\"center\">MPR</th><th align=\"center\">MPRS</th><th align=\"center\">Willingness</th><th>2 Hop Neighbors</th></tr>\n");  /* Neighbors */  for(index=0;index<HASHSIZE;index++)    {      for(neigh = neighbortable[index].next;	  neigh != &neighbortable[index];	  neigh = neigh->next)	{          size += snprintf(&buf[size], bufsize-size, "<tr>");          size += build_ipaddr_with_link(&buf[size], bufsize, &neigh->neighbor_main_addr, -1);	  size += snprintf(&buf[size], bufsize-size, 			  "<td align=\"center\">%s</td>"			  "<td align=\"center\">%s</td>"			  "<td align=\"center\">%s</td>"			  "<td align=\"center\">%d</td>", 			  (neigh->status == SYM) ? "YES" : "NO",			  neigh->is_mpr ? "YES" : "NO",			  olsr_lookup_mprs_set(&neigh->neighbor_main_addr) ? "YES" : "NO",			  neigh->willingness);	  size += snprintf(&buf[size], bufsize-size, "<td><select>\n"                                                     "<option>IP ADDRESS</option>\n");	  thop_cnt = 0;	  for(list_2 = neigh->neighbor_2_list.next;	      list_2 != &neigh->neighbor_2_list;	      list_2 = list_2->next)	    {              size += snprintf(&buf[size], bufsize-size, "<option>%s</option>\n", olsr_ip_to_string(&list_2->neighbor_2->neighbor_2_addr));	      thop_cnt ++;	    }	  size += snprintf(&buf[size], bufsize-size, "</select> (%d)</td></tr>\n", thop_cnt);	}    }  size += snprintf(&buf[size], bufsize-size, "</table>\n");  return size;}static int build_topo_body(char *buf, olsr_u32_t bufsize){  int size = 0;  struct tc_entry *tc;  size += section_title(&buf[size], bufsize-size, "Topology Entries");  size += snprintf(&buf[size], bufsize-size, "<tr><th>Destination IP</th><th>Last Hop IP</th>");  if (olsr_cnf->lq_level > 0) {    size += snprintf(&buf[size], bufsize-size, "<th align=\"right\">LQ</th><th align=\"right\">ILQ</th><th align=\"right\">ETX</th>");  }  size += snprintf(&buf[size], bufsize-size, "</tr>\n");  OLSR_FOR_ALL_TC_ENTRIES(tc) {      struct tc_edge_entry *tc_edge;      OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {          size += snprintf(&buf[size], bufsize-size, "<tr>");          size += build_ipaddr_with_link(&buf[size], bufsize, &tc_edge->T_dest_addr, -1);          size += build_ipaddr_with_link(&buf[size], bufsize, &tc->addr, -1);          if (olsr_cnf->lq_level > 0) {              const double d = tc_edge->link_quality * tc_edge->inverse_link_quality;              size += snprintf(&buf[size], bufsize-size,                               "<td align=\"right\">%0.2f</td>"                               "<td align=\"right\">%0.2f</td>"                               "<td align=\"right\">%0.2f</td>\n",                               tc_edge->link_quality,                               tc_edge->inverse_link_quality,                               d ? 1.0 / d : 0.0);          }          size += snprintf(&buf[size], bufsize-size, "</tr>\n");      } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);  } OLSR_FOR_ALL_TC_ENTRIES_END(tc);  size += snprintf(&buf[size], bufsize-size, "</table>\n");  return size;}static int build_mid_body(char *buf, olsr_u32_t bufsize){  int size = 0;  olsr_u8_t index;  size += section_title(&buf[size], bufsize-size, "MID Entries");  size += snprintf(&buf[size], bufsize-size,                   "<tr><th>Main Address</th><th>Aliases</th></tr>\n");    /* MID */    for(index = 0;index < HASHSIZE; index++)    {      struct mid_entry *entry = mid_set[index].next;      while(entry != &mid_set[index])	{          int mid_cnt;          struct mid_address *alias;          size += snprintf(&buf[size], bufsize-size, "<tr>");          size += build_ipaddr_with_link(&buf[size], bufsize, &entry->main_addr, -1);	  size += snprintf(&buf[size], bufsize-size, "<td><select>\n<option>IP ADDRESS</option>\n");	  alias = entry->aliases;	  mid_cnt = 0;	  while(alias)	    {	      size += snprintf(&buf[size], bufsize-size, "<option>%s</option>\n", olsr_ip_to_string(&alias->alias));	      mid_cnt++;	      alias = alias->next_alias;	    }	  size += snprintf(&buf[size], bufsize-size, "</select> (%d)</td></tr>\n", mid_cnt);	  entry = entry->next;	}    }  size += snprintf(&buf[size], bufsize-size, "</table>\n");  return size;}static int build_nodes_body(char *buf, olsr_u32_t bufsize){  int size = 0;  size += build_neigh_body(&buf[size], bufsize-size);  size += build_topo_body(&buf[size], bufsize-size);  size += build_mid_body(&buf[size], bufsize-size);  return size;}static int build_all_body(char *buf, olsr_u32_t bufsize){  int size = 0;  size += build_config_body(&buf[size], bufsize-size);  size += build_routes_body(&buf[size], bufsize-size);  size += build_neigh_body(&buf[size], bufsize-size);  size += build_topo_body(&buf[size], bufsize-size);  size += build_mid_body(&buf[size], bufsize-size);  return size;}static int build_about_body(char *buf, olsr_u32_t bufsize){  return snprintf(buf, bufsize, about_frame, build_date, build_host);}static int build_cfgfile_body(char *buf, olsr_u32_t bufsize){  int size = 0, i = 0;  while(cfgfile_body[i] && strcmp(cfgfile_body[i], "<!-- CFGFILE -->")) {      size += snprintf(&buf[size], bufsize-size, cfgfile_body[i]);      i++;  }#ifdef NETDIRECT  {        /* Hack to make netdirect stuff work with           olsrd_write_cnf_buf        */        char tmpBuf[10000];        size = olsrd_write_cnf_buf(olsr_cnf, tmpBuf, 10000);        snprintf(&buf[size], bufsize-size, tmpBuf);  }#else  size += olsrd_write_cnf_buf(olsr_cnf, &buf[size], bufsize-size);#endif    if(size < 0) {    size = snprintf(buf, size, "ERROR GENERATING CONFIGFILE!\n");  }  i++;  while(cfgfile_body[i]) {      size += snprintf(&buf[size], bufsize-size, cfgfile_body[i]);      i++;  }#if 0  printf("RETURNING %d\n", size);#endif  return size;}static int check_allowed_ip(const struct allowed_net * const allowed_nets, const union olsr_ip_addr * const addr){    const struct allowed_net *alln;    for (alln = allowed_nets; alln != NULL; alln = alln->next) {        if((addr->v4 & alln->mask.v4) == (alln->net.v4 & alln->mask.v4)) {            return 1;        }    }    return 0;}#if 0/* * 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. */ int netsprintf(char *str, const char* format, ...){	va_list arg;	int rv;	va_start(arg, format);	rv = vsprintf(str, format, arg);	va_end(arg);	if (0 != netsprintf_direct) {		if (0 == netsprintf_error) {			if (0 > send(client_sockets[curr_clients], str, rv, 0)) {				olsr_printf(1, "(HTTPINFO) Failed sending data to client!\n");				netsprintf_error = 1;			}		}		return 0;	}	return rv;}#endifstatic ssize_t writen(int fd, const void *buf, size_t count){    size_t bytes_left = count;    const char *p = buf;    while (bytes_left > 0) {        const ssize_t written = write(fd, p, bytes_left);        if (written == -1)  { /* error */            if (errno == EINTR ) {                continue;            }            return -1;        }        /* We wrote something */        bytes_left -= written;        p += written;    }    return count;}

⌨️ 快捷键说明

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