1 /* $OpenBSD: main.c,v 1.5 2021/04/13 08:21:12 claudio Exp $ */ 2 3 /* 4 * Copyright (c) 2015 Martin Pieuchot 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include "srp_compat.h" 20 21 #include <sys/socket.h> 22 #include <net/route.h> 23 #include <net/rtable.h> 24 25 #include <err.h> 26 #include <stdio.h> 27 #include <stdlib.h> 28 #include <string.h> 29 30 #include "util.h" 31 32 __dead void 33 usage(void) 34 { 35 extern const char *__progname; 36 fprintf(stderr, "Usage: %s [inet|inet6] <file>\n", __progname); 37 exit(1); 38 } 39 40 int 41 main(int argc, char *argv[]) 42 { 43 char *filename; 44 sa_family_t af; 45 46 if (argc != 3) 47 usage(); 48 49 af = strncmp(argv[1], "inet6", 5) ? AF_INET : AF_INET6; 50 filename = argv[2]; 51 52 rtable_init(); 53 54 do_from_file(0, af, filename, route_insert); 55 do_from_file(0, af, filename, route_lookup); 56 57 rtable_walk(0, af, NULL, rtentry_dump, NULL); 58 59 do_from_file(0, af, filename, route_delete); 60 61 return (0); 62 } 63