/*
* The dhcpd-pools has BSD 2-clause license which also known as "Simplified
* BSD License" or "FreeBSD License".
*
* Copyright 2006- Sami Kerola. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing
* official policies, either expressed or implied, of Sami Kerola.
*/
#include <config.h>
#include <arpa/inet.h>
#include <err.h>
#include <langinfo.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#define _FILE_OFFSET_BITS 64
#include <inttypes.h>
#include "dhcpd-pools.h"
int output_txt(void)
{
unsigned int i;
struct in_addr first, last;
struct range_t *range_p;
struct shared_network_t *shared_p;
int ret;
FILE *outfile;
if (config.output_file[0]) {
outfile = fopen(config.output_file, "w+");
if (outfile == NULL) {
err(EXIT_FAILURE, "output_txt: %s", config.output_file);
}
} else {
outfile = stdout;
}
range_p = ranges;
shared_p = shared_networks;
if (config.output_limit[0] & output_limit_bit_1) {
fprintf(outfile, "Ranges:\n");
fprintf
(outfile,
"shared net name first ip last ip max cur percent touch t+c t+c perc");
if (0 < num_backups) {
fprintf(outfile, " bu bu perc");
}
fprintf(outfile, "\n");
}
if (config.output_limit[1] & output_limit_bit_1) {
for (i = 0; i < num_ranges; i++) {
first.s_addr = ntohl(range_p->first_ip + 1);
last.s_addr = ntohl(range_p->last_ip - 1);
if (range_p->shared_net) {
fprintf(outfile, "%-20s",
range_p->shared_net->name);
} else {
fprintf(outfile, "not_defined ");
}
fprintf(outfile, "%-16s", inet_ntoa(first));
fprintf(outfile,
" - %-16s %5" PRIu32
" %5lu %10.3f %5lu %5lu %9.3f",
inet_ntoa(last),
range_p->last_ip - range_p->first_ip - 1,
range_p->count,
(float)(100 * range_p->count) /
(range_p->last_ip - range_p->first_ip - 1),
range_p->touched,
range_p->touched + range_p->count,
(float)(100 *
(range_p->touched +
range_p->count)) / (range_p->last_ip -
range_p->first_ip -
1));
if (0 < num_backups) {
fprintf(outfile, "%7lu %8.3f",
range_p->backups,
(float)(100 * range_p->backups) /
(range_p->last_ip -
range_p->first_ip - 1));
}
fprintf(outfile, "\n");
range_p++;
}
}
if (config.output_limit[1] & output_limit_bit_1
&& config.output_limit[0] & output_limit_bit_2) {
fprintf(outfile, "\n");
}
if (config.output_limit[0] & output_limit_bit_2) {
fprintf(outfile, "Shared networks:\n");
fprintf(outfile,
"name max cur percent touch t+c t+c perc");
if (0 < num_backups) {
fprintf(outfile, " bu bu perc");
}
fprintf(outfile, "\n");
}
if (config.output_limit[1] & output_limit_bit_2) {
for (i = 0; i < num_shared_networks; i++) {
shared_p++;
fprintf(outfile,
"%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f",
shared_p->name, shared_p->available,
shared_p->used,
(float)(100 * shared_p->used) /
shared_p->available, shared_p->touched,
shared_p->touched + shared_p->used,
(float)(100 *
(shared_p->touched +
shared_p->used)) /
shared_p->available);
if (0 < num_backups) {
fprintf(outfile, "%7lu %8.3f",
shared_p->backups,
(float)(100 * shared_p->backups) /
shared_p->available);
}
fprintf(outfile, "\n");
}
}
if (config.output_limit[1] & output_limit_bit_2
&& config.output_limit[0] & output_limit_bit_3) {
fprintf(outfile, "\n");
}
if (config.output_limit[0] & output_limit_bit_3) {
fprintf(outfile, "Sum of all ranges:\n");
fprintf(outfile,
"name max cur percent touch t+c t+c perc");
if (0 < num_backups) {
fprintf(outfile, " bu bu perc");
}
fprintf(outfile, "\n");
}
if (config.output_limit[1] & output_limit_bit_3) {
fprintf(outfile, "%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f",
shared_networks->name,
shared_networks->available,
shared_networks->used,
(float)(100 * shared_networks->used) /
shared_networks->available,
shared_networks->touched,
shared_networks->touched + shared_networks->used,
(float)(100 *
(shared_networks->touched +
shared_networks->used)) /
shared_networks->available);
if (0 < num_backups) {
fprintf(outfile, "%7lu %8.3f",
shared_networks->backups,
(float)(100 * shared_networks->backups) /
shared_networks->available);
}
fprintf(outfile, "\n");
}
if (outfile == stdout) {
ret = fflush(stdout);
if (ret) {
warn("output_txt: fflush");
}
} else {
ret = close_stream(outfile);
if (ret) {
warn("output_txt: fclose");
}
}
return 0;
}
int output_xml(void)
{
unsigned int i;
struct in_addr first, last;
struct range_t *range_p;
struct shared_network_t *shared_p;
struct macaddr_t *macaddr_p;
int ret;
FILE *outfile;
if (config.output_file[0]) {
outfile = fopen(config.output_file, "w+");
if (outfile == NULL) {
err(EXIT_FAILURE, "output_xml: %s", config.output_file);
}
} else {
outfile = stdout;
}
range_p = ranges;
shared_p = shared_networks;
fprintf(outfile, "<dhcpstatus>\n");
if (macaddr != NULL) {
for (macaddr_p = macaddr; macaddr_p->next != NULL;
macaddr_p = macaddr_p->next) {
fprintf(outfile,
"<active_lease>\n\t<ip>%s</ip>\n\t<macaddress>%s</macaddress>\n</active_lease>\n",
macaddr_p->ip, macaddr_p->ethernet);
}
}
if (config.output_limit[1] & output_limit_bit_1) {
for (i = 0; i < num_ranges; i++) {
first.s_addr = ntohl(range_p->first_ip + 1);
last.s_addr = ntohl(range_p->last_ip - 1);
fprintf(outfile, "<subnet>\n");
if (range_p->shared_net) {
fprintf(outfile,
"\t<location>%s</location>\n",
range_p->shared_net->name);
} else {
fprintf(outfile, "\t<location></location>\n");
}
fprintf(outfile, "\t<network></network>\n");
fprintf(outfile, "\t<netmask></netmask>\n");
fprintf(outfile, "\t<range>%s ", inet_ntoa(first));
fprintf(outfile, "- %s</range>\n", inet_ntoa(last));
fprintf(outfile, "\t<gateway></gateway>\n");
fprintf(outfile, "\t<defined>%" PRIu32 "</defined>\n",
range_p->last_ip - range_p->first_ip - 1);
fprintf(outfile, "\t<used>%lu</used>\n",
range_p->count);
fprintf(outfile, "\t<free>%lu</free>\n",
range_p->last_ip - range_p->first_ip - 1 -
range_p->count);
range_p++;
fprintf(outfile, "</subnet>\n");
}
}
if (config.output_limit[1] & output_limit_bit_2) {
for (i = 0; i < num_shared_networks; i++) {
没有合适的资源?快使用搜索试试~ 我知道了~
Linux DHCP图形化管理工具
5星 · 超过95%的资源 需积分: 50 40 下载量 14 浏览量
2012-11-25
17:28:08
上传
评论
收藏 359KB GZ 举报
温馨提示
共38个文件
c:7个
in:5个
am:4个
Linux DHCP图形化管理工具,需要Gcc g++编译器. 可以实现图形化管理dhcp
资源推荐
资源详情
资源评论
收起资源包目录
dhcpd-pools-2.18.tar.gz (38个子文件)
dhcpd-pools-2.18
config.guess 44KB
config.sub 35KB
AUTHORS 17B
contrib
dhcpd-pools.cgi 574B
Makefile.am 88B
snmptest.pl 14KB
Makefile.in 13KB
COPYING 2KB
aclocal.m4 335KB
INSTALL 15KB
src
other.c 6KB
output.c 23KB
dhcpd-pools.c 6KB
defaults.h 2KB
Makefile.am 286B
sort.c 5KB
analyze.c 4KB
dhcpd-pools.h 7KB
Makefile.in 18KB
getdata.c 12KB
hash.c 2KB
install-sh 14KB
Makefile.am 148B
configure 555KB
missing 10KB
depcomp 20KB
config.h.in 6KB
NEWS 7KB
configure.ac 3KB
man
dhcpd-pools.1 4KB
Makefile.am 144B
Makefile.in 14KB
TODO 1KB
Makefile.in 24KB
README 6KB
ltmain.sh 275KB
ChangeLog 4KB
THANKS 415B
共 38 条
- 1
资源评论
- sagill02013-09-03主要是介绍有点少 其他的不错
- houchunyi2013-08-05非常好用!谢谢分享!
- besthief19872018-10-11还没试过,谢谢分享!
wang412664752
- 粉丝: 8
- 资源: 66
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功