Changeset View
Changeset View
Standalone View
Standalone View
sbin/route/route.c
Show All 38 Lines | |||||
#endif | #endif | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/file.h> | #include <sys/file.h> | ||||
#ifdef JAIL | |||||
#include <sys/jail.h> | |||||
#endif | |||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <net/if.h> | #include <net/if.h> | ||||
#include <net/route.h> | #include <net/route.h> | ||||
#include <net/if_dl.h> | #include <net/if_dl.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <netinet/if_ether.h> | #include <netinet/if_ether.h> | ||||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||||
#include <netdb.h> | #include <netdb.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#ifdef JAIL | |||||
#include <jail.h> | |||||
#include <nl_types.h> | |||||
#endif | |||||
#include <paths.h> | #include <paths.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <sysexits.h> | #include <sysexits.h> | ||||
#include <time.h> | #include <time.h> | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
stop_read = 1; | stop_read = 1; | ||||
} | } | ||||
static void | static void | ||||
usage(const char *cp) | usage(const char *cp) | ||||
{ | { | ||||
#ifdef JAIL | |||||
const char *jail = "[-j jail] "; | |||||
#else | |||||
const char *jail = ""; | |||||
#endif | |||||
if (cp != NULL) | if (cp != NULL) | ||||
warnx("bad keyword: %s", cp); | warnx("bad keyword: %s", cp); | ||||
errx(EX_USAGE, "usage: route [-46dnqtv] command [[modifiers] args]"); | errx(EX_USAGE, "usage: route [-46dnqtv] %scommand [[modifiers] args]", jail); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
int ch; | int ch; | ||||
size_t len; | size_t len; | ||||
#ifdef JAIL | |||||
int jid; | |||||
const char *options = "46nqdj:tv"; | |||||
jid = 0; | |||||
#else | |||||
const char *options = "46nqdtv"; | |||||
#endif | |||||
if (argc < 2) | if (argc < 2) | ||||
usage(NULL); | usage(NULL); | ||||
while ((ch = getopt(argc, argv, "46nqdtv")) != -1) | while ((ch = getopt(argc, argv, options)) != -1) | ||||
switch(ch) { | switch(ch) { | ||||
case '4': | case '4': | ||||
#ifdef INET | #ifdef INET | ||||
af = AF_INET; | af = AF_INET; | ||||
aflen = sizeof(struct sockaddr_in); | aflen = sizeof(struct sockaddr_in); | ||||
#else | #else | ||||
errx(1, "IPv4 support is not compiled in"); | errx(1, "IPv4 support is not compiled in"); | ||||
#endif | #endif | ||||
Show All 16 Lines | case 'v': | ||||
verbose = 1; | verbose = 1; | ||||
break; | break; | ||||
case 't': | case 't': | ||||
tflag = 1; | tflag = 1; | ||||
break; | break; | ||||
case 'd': | case 'd': | ||||
debugonly = 1; | debugonly = 1; | ||||
break; | break; | ||||
#ifdef JAIL | |||||
case 'j': | |||||
jid = jail_getid(optarg); | |||||
break; | |||||
#endif | |||||
case '?': | case '?': | ||||
default: | default: | ||||
usage(NULL); | usage(NULL); | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
#ifdef JAIL | |||||
if (jid > 0) { | |||||
(void)catopen("libc", NL_CAT_LOCALE); | |||||
if (jail_attach(jid) == -1) { | |||||
if (errno == EINVAL) | |||||
errx(1, "jail does not exist"); | |||||
err(1, "jail_attach()"); | |||||
} | |||||
} else if (jid == -1) { | |||||
errx(1, "jail does not exist"); | |||||
} | |||||
#endif | |||||
pid = getpid(); | pid = getpid(); | ||||
uid = geteuid(); | uid = geteuid(); | ||||
if (tflag) | if (tflag) | ||||
s = open(_PATH_DEVNULL, O_WRONLY, 0); | s = open(_PATH_DEVNULL, O_WRONLY, 0); | ||||
else | else | ||||
s = socket(PF_ROUTE, SOCK_RAW, 0); | s = socket(PF_ROUTE, SOCK_RAW, 0); | ||||
if (s < 0) | if (s < 0) | ||||
▲ Show 20 Lines • Show All 1,736 Lines • Show Last 20 Lines |