summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/filemon.c72
-rw-r--r--src/bin/ipconvert.c8
-rw-r--r--src/bin/rrd.c91
3 files changed, 171 insertions, 0 deletions
diff --git a/src/bin/filemon.c b/src/bin/filemon.c
new file mode 100644
index 0000000..6930673
--- /dev/null
+++ b/src/bin/filemon.c
@@ -0,0 +1,72 @@
+//ripped from the netbsd man page for kqueue
+//and modified very slightly.
+//I'll add some more stuff as I find a use for it.
+ #include <sys/types.h>
+ #include <sys/event.h>
+ #include <sys/time.h>
+ #include <stdio.h>
+ #include <unistd.h>
+ #include <stdlib.h>
+ #include <fcntl.h>
+ #include <err.h>
+
+ int
+ main(int argc, char *argv[])
+ {
+ int fd, kq, nev;
+ struct kevent ev;
+ static const struct timespec tout = { 1, 0 };
+
+ if ((fd = open(argv[1], O_RDONLY)) == -1)
+ err(1, "Cannot open `%s'", argv[1]);
+
+ if ((kq = kqueue()) == -1)
+ err(1, "Cannot create kqueue");
+
+ EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
+ NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|
+ NOTE_RENAME|NOTE_REVOKE, 0, 0);
+ if (kevent(kq, &ev, 1, NULL, 0, &tout) == -1)
+ err(1, "kevent");
+ for (;;) {
+ nev = kevent(kq, NULL, 0, &ev, 1, &tout);
+ if (nev == -1)
+ err(1, "kevent");
+ if (nev == 0)
+ continue;
+ if (ev.fflags & (NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|NOTE_RENAME|NOTE_REVOKE)) {
+ printf("%s: ",argv[1]);
+ }
+ if (ev.fflags & NOTE_DELETE) {
+ printf("deleted ");
+ ev.fflags &= ~NOTE_DELETE;
+ }
+ if (ev.fflags & NOTE_WRITE) {
+ printf("written ");
+ ev.fflags &= ~NOTE_WRITE;
+ }
+ if (ev.fflags & NOTE_EXTEND) {
+ printf("extended ");
+ ev.fflags &= ~NOTE_EXTEND;
+ }
+ if (ev.fflags & NOTE_ATTRIB) {
+ printf("chmod/chown/utimes ");
+ ev.fflags &= ~NOTE_ATTRIB;
+ }
+ if (ev.fflags & NOTE_LINK) {
+ printf("hardlinked ");
+ ev.fflags &= ~NOTE_LINK;
+ }
+ if (ev.fflags & NOTE_RENAME) {
+ printf("renamed ");
+ ev.fflags &= ~NOTE_RENAME;
+ }
+ if (ev.fflags & NOTE_REVOKE) {
+ printf("revoked ");
+ ev.fflags &= ~NOTE_REVOKE;
+ }
+ printf("\n");
+ if (ev.fflags)
+ warnx("unknown event 0x%x\n", ev.fflags);
+ }
+ }
diff --git a/src/bin/ipconvert.c b/src/bin/ipconvert.c
new file mode 100644
index 0000000..5420e27
--- /dev/null
+++ b/src/bin/ipconvert.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int main(int argc,char *argv[]) {
+ int addr=inet_addr(argv[1]);
+ printf("%x\n",htonl(addr));
+ printf("%u\n",htonl(addr));
+ printf("%u.%u.%u.%u\n",addr&255,addr>>8&255,addr>>16&255,addr>>24&255);
+}
diff --git a/src/bin/rrd.c b/src/bin/rrd.c
new file mode 100644
index 0000000..bbb907d
--- /dev/null
+++ b/src/bin/rrd.c
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <sys/sysctl.h>
+#include <net/route.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+/*
+mostly ripped. just outputs routes from KRT on NetBSD.
+used to look closer at a difference of output from route and netstat.
+*/
+
+get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
+{
+ int i;
+
+ for (i = 0; i < RTAX_MAX; i++) {
+ if (addrs & (1 << i)) {
+ rti_info[i] = sa;
+ sa = (struct sockaddr *)((char *)(sa) +
+ RT_ROUNDUP(sa->sa_len));
+ } else
+ rti_info[i] = NULL;
+ }
+}
+
+
+void print_sa6(struct sockaddr *sa) {
+ int i=0;
+ struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
+ struct in6_addr *in6 = &sa6->sin6_addr;
+ if(sa) {
+ for(i=0;i<16;i++) {
+ printf("%02x",(unsigned char)in6->s6_addr[i]);
+ i++;
+ printf("%02x",(unsigned char)in6->s6_addr[i]);
+ if(i != 15) printf(":");
+ }
+ } else {
+ printf("none");
+ }
+ printf("\n");
+}
+
+void p_rtentry(struct rt_msghdr *rtm) {
+ struct sockadrr *sa = (struct sockaddr *)(rtm+1);
+ struct sockaddr *rti_info[RTAX_MAX];
+ struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
+ struct in6_addr *in6 = &sa6->sin6_addr;
+ get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
+
+ printf("addr: ");
+ print_sa6(rti_info[RTAX_DST]);
+ printf("mask: ");
+ print_sa6(rti_info[RTAX_NETMASK]);
+ printf("gate: ");
+ print_sa6(rti_info[RTAX_GATEWAY]);
+ printf("\n");
+}
+
+int main() {
+// sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp,
+// const void *newp, size_t newlen);
+ int needed;
+ struct rt_msghdr *rtm;
+ struct sockaddr *sa;
+ char *buf,*next,*lim;
+ int mib[6];
+ mib[0]=CTL_NET;
+ mib[1]=PF_ROUTE;
+ mib[2]=0;
+ mib[3]=AF_INET6;
+ mib[4]=NET_RT_DUMP;
+ mib[5]=0;
+ sysctl(mib,6,NULL,&needed,NULL,0);
+ buf=malloc(needed);
+ sysctl(mib,6,buf,&needed,NULL,0);
+ lim=buf+needed;
+ if (buf) {
+ for (next = buf; next < lim; next += rtm->rtm_msglen) {
+ rtm = (struct rt_msghdr *)next;
+ sa = (struct sockaddr *)(rtm + 1);
+ if (sa->sa_family != AF_INET6)
+ continue;
+ p_rtentry(rtm);
+ }
+ free(buf);
+ buf = NULL;
+ }
+
+}