diff options
author | Epoch Qwert <epoch@53flpnlls43fcguy.onion> | 2014-11-23 14:25:42 -0600 |
---|---|---|
committer | Epoch Qwert <epoch@53flpnlls43fcguy.onion> | 2014-11-23 14:25:42 -0600 |
commit | 30300843e0c66ca3eefa97f5787f95b07c256d2f (patch) | |
tree | b29343b30092689786ffcac3913b683ff7555dbe /src/bin/rrd.c | |
parent | a23b5f921d551863dbcae494e58622164a1d3492 (diff) | |
download | misc-30300843e0c66ca3eefa97f5787f95b07c256d2f.tar.gz misc-30300843e0c66ca3eefa97f5787f95b07c256d2f.zip |
fixed gitignore. >_> added a bunch of new piddly shit.
Diffstat (limited to 'src/bin/rrd.c')
-rw-r--r-- | src/bin/rrd.c | 91 |
1 files changed, 91 insertions, 0 deletions
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; + } + +} |