Proper .gitignore files
[debian/dhcpd-pools.git] / src / output.c
1 /*
2 ** Copyright (C) 2006- Sami Kerola <kerolasa@iki.fi>
3 **  
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
8 ** 
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ** GNU General Public License for more details.
13 ** 
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software 
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <stdio.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
26 #include <arpa/inet.h>
27
28 #include "dhcpd-pools.h"
29
30 int output_txt(void)
31 {
32         unsigned int i;
33         struct in_addr first, last;
34         struct range_t *range_p;
35         struct shared_network_t *shared_p;
36         int ret;
37         FILE *outfile;
38
39         if (config.output_file[0]) {
40                 outfile = fopen(config.output_file, "w+");
41                 if (outfile == NULL) {
42                         eprintf("output_txt: %s:", config.output_file);
43                         exit(EXIT_FAILURE);
44                 }
45         } else {
46                 outfile = stdout;
47         }
48
49         range_p = ranges;
50         shared_p = shared_networks;
51
52         if (config.output_limit[0] & output_limit_bit_1) {
53                 fprintf(outfile, "Ranges:\n");
54                 fprintf
55                     (outfile,
56                      "shared net name     first ip           last ip            max   cur    percent  touch   t+c  t+c perc");
57                 if (num_backups > 0) {
58                         fprintf(outfile, "     bu  bu perc");
59                 }
60                 fprintf(outfile, "\n");
61         }
62         if (config.output_limit[1] & output_limit_bit_1) {
63                 for (i = 0; i < num_ranges; i++) {
64                         first.s_addr = ntohl(range_p->first_ip + 1);
65                         last.s_addr = ntohl(range_p->last_ip - 1);
66
67                         if (range_p->shared_net) {
68                                 fprintf(outfile, "%-20s",
69                                         range_p->shared_net->name);
70                         } else {
71                                 fprintf(outfile, "not_defined         ");
72                         }
73                         fprintf(outfile, "%-16s", inet_ntoa(first));
74                         fprintf(outfile,
75                                 " - %-16s %5lu %5lu %10.3f  %5lu %5lu %9.3f",
76                                 inet_ntoa(last),
77                                 range_p->last_ip - range_p->first_ip - 1,
78                                 range_p->count,
79                                 (float) (100 * range_p->count) /
80                                 (range_p->last_ip - range_p->first_ip - 1),
81                                 range_p->touched,
82                                 range_p->touched + range_p->count,
83                                 (float) (100 *
84                                          (range_p->touched +
85                                           range_p->count)) /
86                                 (range_p->last_ip - range_p->first_ip -
87                                  1));
88                         if (num_backups > 0) {
89                                 fprintf(outfile, "%7lu %8.3f",
90                                         range_p->backups,
91                                         (float) (100 * range_p->backups) /
92                                         (range_p->last_ip -
93                                          range_p->first_ip - 1));
94                         }
95                         fprintf(outfile, "\n");
96                         range_p++;
97                 }
98         }
99         if (config.output_limit[1] & output_limit_bit_1
100             && config.output_limit[0] & output_limit_bit_2) {
101                 fprintf(outfile, "\n");
102         }
103         if (config.output_limit[0] & output_limit_bit_2) {
104                 fprintf(outfile, "Shared networks:\n");
105                 fprintf(outfile,
106                         "name                   max   cur     percent  touch    t+c  t+c perc");
107                 if (num_backups > 0) {
108                         fprintf(outfile, "     bu  bu perc");
109                 }
110                 fprintf(outfile, "\n");
111         }
112         if (config.output_limit[1] & output_limit_bit_2) {
113                 for (i = 0; i < num_shared_networks; i++) {
114                         shared_p++;
115                         fprintf(outfile,
116                                 "%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f",
117                                 shared_p->name, shared_p->available,
118                                 shared_p->used,
119                                 (float) (100 * shared_p->used) /
120                                 shared_p->available, shared_p->touched,
121                                 shared_p->touched + shared_p->used,
122                                 (float) (100 *
123                                          (shared_p->touched +
124                                           shared_p->used)) /
125                                 shared_p->available);
126                         if (num_backups > 0) {
127                                 fprintf(outfile, "%7lu %8.3f",
128                                         shared_p->backups,
129                                         (float) (100 * shared_p->backups) /
130                                         shared_p->available);
131                         }
132
133                         fprintf(outfile, "\n");
134                 }
135         }
136         if (config.output_limit[1] & output_limit_bit_2
137             && config.output_limit[0] & output_limit_bit_3) {
138                 fprintf(outfile, "\n");
139         }
140         if (config.output_limit[0] & output_limit_bit_3) {
141                 fprintf(outfile, "Sum of all ranges:\n");
142                 fprintf(outfile,
143                         "name                   max   cur     percent  touch    t+c  t+c perc");
144
145                 if (num_backups > 0) {
146                         fprintf(outfile, "     bu  bu perc");
147                 }
148                 fprintf(outfile, "\n");
149         }
150         if (config.output_limit[1] & output_limit_bit_3) {
151                 fprintf(outfile, "%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f",
152                         shared_networks->name,
153                         shared_networks->available,
154                         shared_networks->used,
155                         (float) (100 * shared_networks->used) /
156                         shared_networks->available,
157                         shared_networks->touched,
158                         shared_networks->touched + shared_networks->used,
159                         (float) (100 *
160                                  (shared_networks->touched +
161                                   shared_networks->used)) /
162                         shared_networks->available);
163
164                 if (num_backups > 0) {
165                         fprintf(outfile, "%7lu %8.3f",
166                                 shared_networks->backups,
167                                 (float) (100 * shared_networks->backups) /
168                                 shared_networks->available);
169                 }
170                 fprintf(outfile, "\n");
171         }
172         if (outfile == stdout) {
173                 ret = fflush(stdout);
174                 if (ret) {
175                         eprintf("output_txt: fflush:");
176                 }
177         } else {
178                 ret = fclose(outfile);
179                 if (ret) {
180                         eprintf("output_txt: fclose:");
181                 }
182         }
183
184         return 0;
185 }
186
187 int output_xml(void)
188 {
189         unsigned int i;
190         struct in_addr first, last;
191         struct range_t *range_p;
192         struct shared_network_t *shared_p;
193         int ret;
194         FILE *outfile;
195
196         if (config.output_file[0]) {
197                 outfile = fopen(config.output_file, "w+");
198                 if (outfile == NULL) {
199                         eprintf("output_xml: %s:", config.output_file);
200                         exit(EXIT_FAILURE);
201                 }
202         } else {
203                 outfile = stdout;
204         }
205
206         range_p = ranges;
207         shared_p = shared_networks;
208
209         if (config.output_limit[1] & output_limit_bit_1) {
210                 for (i = 0; i < num_ranges; i++) {
211                         first.s_addr = ntohl(range_p->first_ip + 1);
212                         last.s_addr = ntohl(range_p->last_ip - 1);
213
214                         fprintf(outfile, "<subnet>\n");
215
216                         if (range_p->shared_net) {
217                                 fprintf(outfile,
218                                         "\t<location>%s</location>\n",
219                                         range_p->shared_net->name);
220                         } else {
221                                 fprintf(outfile,
222                                         "\t<location></location>\n");
223                         }
224
225                         fprintf(outfile, "\t<network></network>\n");
226                         fprintf(outfile, "\t<netmask></netmask>\n");
227                         fprintf(outfile, "\t<range>%s ", inet_ntoa(first));
228                         fprintf(outfile, "- %s</range>\n",
229                                 inet_ntoa(last));
230                         fprintf(outfile, "\t<gateway></gateway>\n");
231                         fprintf(outfile, "\t<defined>%lu</defined>\n",
232                                 range_p->last_ip - range_p->first_ip - 1);
233                         fprintf(outfile, "\t<used>%lu</used>\n",
234                                 range_p->count);
235                         fprintf(outfile, "\t<free>%lu</free>\n",
236                                 range_p->last_ip - range_p->first_ip - 1 -
237                                 range_p->count);
238
239                         range_p++;
240
241                         fprintf(outfile, "</subnet>\n");
242                 }
243         }
244
245         if (config.output_limit[1] & output_limit_bit_2) {
246                 for (i = 0; i < num_shared_networks; i++) {
247                         shared_p++;
248
249                         fprintf(outfile, "<shared-network>\n");
250                         fprintf(outfile, "\t<location>%s</location>\n",
251                                 shared_p->name);
252                         fprintf(outfile, "\t<defined>%lu</defined>\n",
253                                 shared_p->available);
254                         fprintf(outfile, "\t<used>%lu</used>\n",
255                                 shared_p->used);
256                         fprintf(outfile, "\t<free>%lu</free>\n",
257                                 shared_p->available - shared_p->used);
258                         fprintf(outfile, "</shared-network>\n");
259                 }
260         }
261
262         if (config.output_limit[0] & output_limit_bit_3) {
263                 fprintf(outfile, "<summary>\n");
264                 fprintf(outfile, "\t<location>%s</location>\n",
265                         shared_networks->name);
266                 fprintf(outfile, "\t<defined>%lu</defined>\n",
267                         shared_networks->available);
268                 fprintf(outfile, "\t<used>%lu</used>\n",
269                         shared_networks->used);
270                 fprintf(outfile, "\t<free>%lu</free>\n",
271                         shared_networks->available -
272                         shared_networks->used);
273                 fprintf(outfile, "</summary>\n");
274         }
275
276         if (outfile == stdout) {
277                 ret = fflush(stdout);
278                 if (ret) {
279                         eprintf("output_xml: fflush:");
280                 }
281         } else {
282                 ret = fclose(outfile);
283                 if (ret) {
284                         eprintf("output_xml: fclose:");
285                 }
286         }
287
288         return 0;
289 }
290
291 void html_header(FILE * f)
292 {
293         fprintf(f,
294                 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \n");
295         fprintf(f, "  \"http://www.w3.org/TR/html4/strict.dtd\">\n");
296         fprintf(f, "<html>\n");
297         fprintf(f, "<head>\n");
298         fprintf(f, "<meta http-equiv=\"Content-Type\" ");
299         fprintf(f, "content=\"text/html; charset=iso-8859-1\">\n");
300         fprintf(f, "  <title>ISC dhcpd stats</title>\n");
301         fprintf(f, "  <style  TYPE=\"text/css\">\n");
302         fprintf(f, "  <!--\n");
303         fprintf(f, "    table.dhcpd-pools {\n");
304         fprintf(f, "      color: black;\n");
305         fprintf(f, "      vertical-align: middle;\n");
306         fprintf(f, "      text-align: center;\n");
307         fprintf(f, "    }\n");
308         fprintf(f, "    table.dhcpd-pools th.section {\n");
309         fprintf(f, "      color: black;\n");
310         fprintf(f, "      font-size: large;\n");
311         fprintf(f, "      vertical-align: middle;\n");
312         fprintf(f, "      text-align: left;\n");
313         fprintf(f, "    }\n");
314         fprintf(f, "    table.dhcpd-pools th.calign {\n");
315         fprintf(f, "      color: black;\n");
316         fprintf(f, "      vertical-align: middle;\n");
317         fprintf(f, "      text-align: center;\n");
318         fprintf(f, "      text-decoration: underline;\n");
319         fprintf(f, "    }\n");
320         fprintf(f, "    table.dhcpd-pools th.ralign {\n");
321         fprintf(f, "      color: black;\n");
322         fprintf(f, "      vertical-align: middle;\n");
323         fprintf(f, "      text-align: right;\n");
324         fprintf(f, "      text-decoration: underline;\n");
325         fprintf(f, "    }\n");
326         fprintf(f, "    table.dhcpd-pools td.calign {\n");
327         fprintf(f, "      color: black;\n");
328         fprintf(f, "      vertical-align: middle;\n");
329         fprintf(f, "      text-align: center;\n");
330         fprintf(f, "    }\n");
331         fprintf(f, "    table.dhcpd-pools td.ralign {\n");
332         fprintf(f, "      color: black;\n");
333         fprintf(f, "      vertical-align: middle;\n");
334         fprintf(f, "      text-align: right;\n");
335         fprintf(f, "    }\n");
336         fprintf(f, "    p.created {\n");
337         fprintf(f, "      font-size: small;\n");
338         fprintf(f, "      color: grey;\n");
339         fprintf(f, "    }\n");
340         fprintf(f, "    p.updated {\n");
341         fprintf(f, "      font-size: small;\n");
342         fprintf(f, "      color: grey;\n");
343         fprintf(f, "      font-style: italic;\n");
344         fprintf(f, "    }\n");
345         fprintf(f, "  -->\n");
346         fprintf(f, "  </style>\n");
347         fprintf(f, "</head>\n");
348         fprintf(f, "<body>\n");
349 }
350
351 void html_footer(FILE * f)
352 {
353         fprintf(f, "<p><br></p>\n");
354         fprintf(f, "<hr>\n");
355         fprintf(f, "<p class=created>\nData generated by ");
356         fprintf(f, "<a href=\"%s\">", PACKAGE_URL);
357         fprintf(f, "dhcpd-pools</a>.\n</p>\n");
358
359         fprintf(f, "<p class=updated>\n");
360         fprintf(f, "<script type=\"text/javascript\">\n");
361         fprintf(f, "  document.write(\"Last Updated On \" + ");
362         fprintf(f, "document.lastModified + \".\")\n");
363         fprintf(f, "</script>\n<br>\n</p>\n");
364         fprintf(f, "</body>\n");
365         fprintf(f, "</html>\n");
366 }
367
368 void newrow(FILE * f)
369 {
370         fprintf(f, "<tr>\n");
371 }
372
373 void endrow(FILE * f)
374 {
375         fprintf(f, "</tr>\n\n");
376 }
377
378 void output_line(FILE * f, char *type, char *class, char *text)
379 {
380         fprintf(f, "  <%s class=%s>%s</%s>\n", type, class, text, type);
381 }
382
383 void output_long(FILE * f, char *type, unsigned long unlong)
384 {
385         fprintf(f, "  <%s class=ralign>%lu</%s>\n", type, unlong, type);
386 }
387
388 void output_float(FILE * f, char *type, float fl)
389 {
390         fprintf(f, "  <%s class=ralign>%.3f</%s>\n", type, fl, type);
391 }
392
393 void table_start(FILE * f)
394 {
395         fprintf(f, "<table width=\"75%%\" ");
396         fprintf(f, "class=\"dhcpd-pools\" ");
397         fprintf(f, "summary=\"ISC dhcpd pool usage report\">\n");
398 }
399
400 void table_end(FILE * f)
401 {
402         fprintf(f, "</table>\n");
403 }
404
405 void newsection(FILE * f, char *title)
406 {
407         newrow(f);
408         output_line(f, "td", "calign", "&nbsp;");
409         endrow(f);
410
411         newrow(f);
412         output_line(f, "th", "section", title);
413         endrow(f);
414 }
415
416 int output_html(void)
417 {
418         unsigned int i;
419         struct in_addr first, last;
420         struct range_t *range_p;
421         struct shared_network_t *shared_p;
422         int ret;
423         FILE *outfile;
424
425         if (config.output_file[0]) {
426                 outfile = fopen(config.output_file, "w+");
427                 if (outfile == NULL) {
428                         eprintf("output_html: %s:", config.output_file);
429                         exit(EXIT_FAILURE);
430                 }
431         } else {
432                 outfile = stdout;
433         }
434
435         range_p = ranges;
436         shared_p = shared_networks;
437
438         if (fullhtml) {
439                 html_header(outfile);
440         }
441         table_start(outfile);
442         if (config.output_limit[0] & output_limit_bit_1) {
443                 newsection(outfile, "Ranges:");
444                 newrow(outfile);
445                 output_line(outfile, "th", "calign", "shared net name");
446                 output_line(outfile, "th", "calign", "first ip");
447                 output_line(outfile, "th", "calign", "last ip");
448                 output_line(outfile, "th", "ralign", "max");
449                 output_line(outfile, "th", "ralign", "cur");
450                 output_line(outfile, "th", "ralign", "percent");
451                 output_line(outfile, "th", "ralign", "touch");
452                 output_line(outfile, "th", "ralign", "t+c");
453                 output_line(outfile, "th", "ralign", "t+c perc");
454                 if (num_backups > 0) {
455                         output_line(outfile, "th", "ralign", "bu");
456                         output_line(outfile, "th", "ralign", "bu perc");
457                 }
458                 endrow(outfile);
459         }
460         if (config.output_limit[1] & output_limit_bit_1) {
461                 for (i = 0; i < num_ranges; i++) {
462                         first.s_addr = ntohl(range_p->first_ip + 1);
463                         last.s_addr = ntohl(range_p->last_ip - 1);
464
465                         newrow(outfile);
466                         if (range_p->shared_net) {
467                                 output_line(outfile, "td", "calign",
468                                             range_p->shared_net->name);
469                         } else {
470                                 output_line(outfile, "td", "calign",
471                                             "not_defined");
472                         }
473                         output_line(outfile, "td", "calign",
474                                     inet_ntoa(first));
475                         output_line(outfile, "td", "calign",
476                                     inet_ntoa(last));
477                         output_long(outfile, "td",
478                                     range_p->last_ip - range_p->first_ip -
479                                     1);
480                         output_long(outfile, "td", range_p->count);
481                         output_float(outfile, "td",
482                                      (float) (100 * range_p->count) /
483                                      (range_p->last_ip -
484                                       range_p->first_ip - 1));
485                         output_long(outfile, "td", range_p->touched);
486                         output_long(outfile, "td",
487                                     range_p->touched + range_p->count);
488                         output_float(outfile, "td",
489                                      (float) (100 *
490                                               (range_p->touched +
491                                                range_p->count)) /
492                                      (range_p->last_ip -
493                                       range_p->first_ip - 1));
494                         if (num_backups > 0) {
495                                 output_long(outfile, "td",
496                                             range_p->backups);
497                                 output_float(outfile, "td",
498                                              (float) (100 *
499                                                       range_p->backups) /
500                                              (range_p->last_ip -
501                                               range_p->first_ip - 1));
502                         }
503                         endrow(outfile);
504                         range_p++;
505                 }
506         }
507         table_end(outfile);
508         table_start(outfile);
509         if (config.output_limit[0] & output_limit_bit_2) {
510                 newsection(outfile, "Shared networks:");
511
512                 newrow(outfile);
513                 output_line(outfile, "th", "calign", "name");
514                 output_line(outfile, "th", "ralign", "max");
515                 output_line(outfile, "th", "ralign", "cur");
516                 output_line(outfile, "th", "ralign", "percent");
517                 output_line(outfile, "th", "ralign", "touch");
518                 output_line(outfile, "th", "ralign", "t+c");
519                 output_line(outfile, "th", "ralign", "t+c perc");
520                 if (num_backups > 0) {
521                         output_line(outfile, "th", "ralign", "bu");
522                         output_line(outfile, "th", "ralign", "bu perc");
523                 }
524                 endrow(outfile);
525         }
526         if (config.output_limit[1] & output_limit_bit_2) {
527                 for (i = 0; i < num_shared_networks; i++) {
528                         shared_p++;
529                         newrow(outfile);
530                         output_line(outfile, "td", "calign",
531                                     shared_p->name);
532                         output_long(outfile, "td", shared_p->available);
533                         output_long(outfile, "td", shared_p->used);
534                         output_float(outfile, "td",
535                                      (float) (100 * shared_p->used) /
536                                      shared_p->available);
537                         output_long(outfile, "td", shared_p->touched);
538                         output_long(outfile, "td",
539                                     shared_p->touched + shared_p->used);
540                         output_float(outfile, "td",
541                                      (float) (100 *
542                                               (shared_p->touched +
543                                                shared_p->used)) /
544                                      shared_p->available);
545                         if (num_backups > 0) {
546                                 output_long(outfile, "td",
547                                             shared_p->backups);
548                                 output_float(outfile, "td",
549                                              (float) (100 *
550                                                       shared_p->backups) /
551                                              shared_p->available);
552                         }
553
554                         endrow(outfile);
555                 }
556         }
557         if (config.output_limit[0] & output_limit_bit_3) {
558                 newsection(outfile, "Sum of all ranges:");
559
560                 newrow(outfile);
561                 output_line(outfile, "th", "calign", "name");
562                 output_line(outfile, "th", "ralign", "max");
563                 output_line(outfile, "th", "ralign", "cur");
564                 output_line(outfile, "th", "ralign", "percent");
565                 output_line(outfile, "th", "ralign", "touch");
566                 output_line(outfile, "th", "ralign", "t+c");
567                 output_line(outfile, "th", "ralign", "t+c perc");
568                 if (num_backups > 0) {
569                         output_line(outfile, "th", "ralign", "bu");
570                         output_line(outfile, "th", "ralign", "bu perc");
571                 }
572
573                 endrow(outfile);
574         }
575         if (config.output_limit[1] & output_limit_bit_3) {
576                 newrow(outfile);
577                 output_line(outfile, "td", "calign",
578                             shared_networks->name);
579                 output_long(outfile, "td", shared_networks->available);
580                 output_long(outfile, "td", shared_networks->used);
581                 output_float(outfile, "td",
582                              (float) (100 * shared_networks->used) /
583                              shared_networks->available);
584                 output_long(outfile, "td", shared_networks->touched);
585                 output_long(outfile, "td",
586                             shared_networks->touched +
587                             shared_networks->used);
588                 output_float(outfile, "td",
589                              (float) (100 *
590                                       (shared_networks->touched +
591                                        shared_networks->used)) /
592                              shared_networks->available);
593                 if (num_backups > 0) {
594                         output_long(outfile, "td",
595                                     shared_networks->backups);
596                         output_float(outfile, "td",
597                                      (float) (100 *
598                                               shared_networks->backups) /
599                                      shared_networks->available);
600                 }
601                 endrow(outfile);
602         }
603         table_end(outfile);
604         if (fullhtml) {
605                 html_footer(outfile);
606         }
607         if (outfile == stdout) {
608                 ret = fflush(stdout);
609                 if (ret) {
610                         eprintf("output_html: fflush:");
611                 }
612         } else {
613                 ret = fclose(outfile);
614                 if (ret) {
615                         eprintf("output_html: fclose:");
616                 }
617         }
618         return 0;
619 }
620
621 int output_csv(void)
622 {
623         unsigned int i;
624         struct in_addr first, last;
625         struct range_t *range_p;
626         struct shared_network_t *shared_p;
627         FILE *outfile;
628         int ret;
629
630         if (config.output_file[0]) {
631                 outfile = fopen(config.output_file, "w+");
632                 if (outfile == NULL) {
633                         eprintf("output_csv: %s:", config.output_file);
634                         exit(EXIT_FAILURE);
635                 }
636         } else {
637                 outfile = stdout;
638         }
639
640         range_p = ranges;
641         shared_p = shared_networks;
642
643         if (config.output_limit[0] & output_limit_bit_1) {
644                 fprintf(outfile, "\"Ranges:\"\n");
645                 fprintf
646                     (outfile,
647                      "\"shared net name\",\"first ip\",\"last ip\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\"");
648                 if (num_backups > 0) {
649                         fprintf(outfile, ",\"bu\",\"bu perc\"");
650                 }
651                 fprintf(outfile, "\n");
652
653         }
654         if (config.output_limit[1] & output_limit_bit_1) {
655                 for (i = 0; i < num_ranges; i++) {
656                         first.s_addr = ntohl(range_p->first_ip + 1);
657                         last.s_addr = ntohl(range_p->last_ip - 1);
658
659                         if (range_p->shared_net) {
660                                 fprintf(outfile, "\"%s\",",
661                                         range_p->shared_net->name);
662                         } else {
663                                 fprintf(outfile, "\"not_defined\",");
664                         }
665                         fprintf(outfile, "\"%s\",", inet_ntoa(first));
666                         fprintf(outfile,
667                                 "\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
668                                 inet_ntoa(last),
669                                 range_p->last_ip - range_p->first_ip - 1,
670                                 range_p->count,
671                                 (float) (100 * range_p->count) /
672                                 (range_p->last_ip - range_p->first_ip - 1),
673                                 range_p->touched,
674                                 range_p->touched + range_p->count,
675                                 (float) (100 *
676                                          (range_p->touched +
677                                           range_p->count)) /
678                                 (range_p->last_ip - range_p->first_ip -
679                                  1));
680                         if (num_backups > 0) {
681                                 fprintf(outfile, ",\"%lu\",\"%.3f\"",
682                                         range_p->backups,
683                                         (float) (100 * range_p->backups) /
684                                         (range_p->last_ip -
685                                          range_p->first_ip - 1));
686                         }
687
688
689                         fprintf(outfile, "\n");
690                         range_p++;
691                 }
692                 fprintf(outfile, "\n");
693         }
694         if (config.output_limit[0] & output_limit_bit_2) {
695                 fprintf(outfile, "\"Shared networks:\"\n");
696                 fprintf(outfile,
697                         "\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\"");
698                 if (num_backups > 0) {
699                         fprintf(outfile, ",\"bu\",\"bu perc\"");
700                 }
701                 fprintf(outfile, "\n");
702         }
703         if (config.output_limit[1] & output_limit_bit_2) {
704
705                 for (i = 0; i < num_shared_networks; i++) {
706                         shared_p++;
707                         fprintf(outfile,
708                                 "\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
709                                 shared_p->name, shared_p->available,
710                                 shared_p->used,
711                                 (float) (100 * shared_p->used) /
712                                 shared_p->available, shared_p->touched,
713                                 shared_p->touched + shared_p->used,
714                                 (float) (100 *
715                                          (shared_p->touched +
716                                           shared_p->used)) /
717                                 shared_p->available);
718                         if (num_backups > 0) {
719                                 fprintf(outfile, ",\"%lu\",\"%.3f\"",
720                                         shared_p->backups,
721                                         (float) (100 * shared_p->backups) /
722                                         shared_p->available);
723                         }
724
725                         fprintf(outfile, "\n");
726
727
728                 }
729                 fprintf(outfile, "\n");
730         }
731         if (config.output_limit[0] & output_limit_bit_3) {
732                 fprintf(outfile, "\"Sum of all ranges:\"\n");
733                 fprintf(outfile,
734                         "\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\"");
735                 if (num_backups > 0) {
736                         fprintf(outfile, ",\"bu\",\"bu perc\"");
737                 }
738                 fprintf(outfile, "\n");
739         }
740         if (config.output_limit[1] & output_limit_bit_3) {
741
742                 fprintf(outfile,
743                         "\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
744                         shared_networks->name, shared_networks->available,
745                         shared_networks->used,
746                         (float) (100 * shared_networks->used) /
747                         shared_networks->available,
748                         shared_networks->touched,
749                         shared_networks->touched + shared_networks->used,
750                         (float) (100 *
751                                  (shared_networks->touched +
752                                   shared_networks->used)) /
753                         shared_networks->available);
754                 if (num_backups > 0) {
755                         fprintf(outfile, "%7lu %8.3f",
756                                 shared_networks->backups,
757                                 (float) (100 * shared_networks->backups) /
758                                 shared_networks->available);
759                 }
760                 fprintf(outfile, "\n");
761
762         }
763         if (outfile == stdout) {
764                 ret = fflush(stdout);
765                 if (ret) {
766                         eprintf("output_cvs: fflush:");
767                 }
768
769         } else {
770                 ret = fclose(outfile);
771                 if (ret) {
772                         eprintf("output_cvs: fclose:");
773                 }
774
775         }
776         return 0;
777 }