1*d4be4cdeSjob /* $OpenBSD: output-csv.c,v 1.14 2024/02/22 12:49:42 job Exp $ */
25a1f8137Sclaudio /*
35a1f8137Sclaudio * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
45a1f8137Sclaudio *
55a1f8137Sclaudio * Permission to use, copy, modify, and distribute this software for any
65a1f8137Sclaudio * purpose with or without fee is hereby granted, provided that the above
75a1f8137Sclaudio * copyright notice and this permission notice appear in all copies.
85a1f8137Sclaudio *
95a1f8137Sclaudio * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
105a1f8137Sclaudio * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
115a1f8137Sclaudio * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
125a1f8137Sclaudio * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
135a1f8137Sclaudio * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
145a1f8137Sclaudio * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
155a1f8137Sclaudio * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
165a1f8137Sclaudio */
175a1f8137Sclaudio
185a1f8137Sclaudio #include <stdlib.h>
195a1f8137Sclaudio
205a1f8137Sclaudio #include "extern.h"
215a1f8137Sclaudio
221f9a8b94Sderaadt int
output_csv(FILE * out,struct vrp_tree * vrps,struct brk_tree * brks,struct vap_tree * vaps,struct vsp_tree * vsps,struct stats * st)236b83d8e3Sjob output_csv(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks,
24*d4be4cdeSjob struct vap_tree *vaps, struct vsp_tree *vsps, struct stats *st)
255a1f8137Sclaudio {
265a1f8137Sclaudio struct vrp *v;
27ed26e04bSderaadt
28a66158d7Sjob if (fprintf(out, "ASN,IP Prefix,Max Length,Trust Anchor,Expires\n") < 0)
298db993caSbenno return -1;
305a1f8137Sclaudio
315a1f8137Sclaudio RB_FOREACH(v, vrp_tree, vrps) {
3295b65f7cSderaadt char buf[64];
3395b65f7cSderaadt
345a1f8137Sclaudio ip_addr_print(&v->addr, v->afi, buf, sizeof(buf));
35a66158d7Sjob
36a66158d7Sjob if (fprintf(out, "AS%u,%s,%u,%s,%lld\n", v->asid, buf,
37dc508150Sclaudio v->maxlength, taldescs[v->talid],
38dc508150Sclaudio (long long)v->expires) < 0)
398db993caSbenno return -1;
405a1f8137Sclaudio }
418db993caSbenno return 0;
425a1f8137Sclaudio }
43