1*2e154ce3Sclaudio /* $OpenBSD: main.c,v 1.5 2021/04/13 08:21:12 claudio Exp $ */
2996673c0Smpi
3996673c0Smpi /*
4996673c0Smpi * Copyright (c) 2015 Martin Pieuchot
5996673c0Smpi *
6996673c0Smpi * Permission to use, copy, modify, and distribute this software for any
7996673c0Smpi * purpose with or without fee is hereby granted, provided that the above
8996673c0Smpi * copyright notice and this permission notice appear in all copies.
9996673c0Smpi *
10996673c0Smpi * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11996673c0Smpi * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12996673c0Smpi * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13996673c0Smpi * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14996673c0Smpi * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15996673c0Smpi * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16996673c0Smpi * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17996673c0Smpi */
18996673c0Smpi
198ceda520Smpi #include "srp_compat.h"
208ceda520Smpi
21996673c0Smpi #include <sys/socket.h>
22996673c0Smpi #include <net/route.h>
23*2e154ce3Sclaudio #include <net/rtable.h>
24996673c0Smpi
25996673c0Smpi #include <err.h>
26996673c0Smpi #include <stdio.h>
27996673c0Smpi #include <stdlib.h>
28996673c0Smpi #include <string.h>
29996673c0Smpi
30996673c0Smpi #include "util.h"
31996673c0Smpi
32996673c0Smpi __dead void
usage(void)33996673c0Smpi usage(void)
34996673c0Smpi {
35996673c0Smpi extern const char *__progname;
36996673c0Smpi fprintf(stderr, "Usage: %s [inet|inet6] <file>\n", __progname);
37996673c0Smpi exit(1);
38996673c0Smpi }
39996673c0Smpi
40996673c0Smpi int
main(int argc,char * argv[])41996673c0Smpi main(int argc, char *argv[])
42996673c0Smpi {
43996673c0Smpi char *filename;
44996673c0Smpi sa_family_t af;
45996673c0Smpi
46996673c0Smpi if (argc != 3)
47996673c0Smpi usage();
48996673c0Smpi
49996673c0Smpi af = strncmp(argv[1], "inet6", 5) ? AF_INET : AF_INET6;
50996673c0Smpi filename = argv[2];
51996673c0Smpi
52996673c0Smpi rtable_init();
53996673c0Smpi
54996673c0Smpi do_from_file(0, af, filename, route_insert);
55996673c0Smpi do_from_file(0, af, filename, route_lookup);
56996673c0Smpi
573924ad6bSvisa rtable_walk(0, af, NULL, rtentry_dump, NULL);
58996673c0Smpi
59996673c0Smpi do_from_file(0, af, filename, route_delete);
60996673c0Smpi
61996673c0Smpi return (0);
62996673c0Smpi }
63