Skip to content

Instantly share code, notes, and snippets.

View MrPeanutButta's full-sized avatar
🤙

Aaron MrPeanutButta

🤙
View GitHub Profile
// http://www.sigcomm.org/sites/default/files/ccr/papers/2012/October/2378956-2378961.pdf
int dir_24_8_lookup(uint32_t dst) {
int nh = tbl_0_23[dst >> 8]; // index in the next hop table
if (nh & 0x8000)nh = tbl_24_31[((nh & 0x7fff) << 8) | (dst & 0xff)];
return nh;
}
@MrPeanutButta
MrPeanutButta / ipv4_broadcast_addr.c
Last active December 17, 2015 03:09
Returns the highest IP address in subnet range.
#include <cstdint>
#include <arpa/inet.h>
/** Returns the IPv4 broadcast address for a given subnet.
*
* Assuming host is little endian.
* Assuming your host is Linux :)
*
* subtracting 1 from the return will yield last usable host address.
*
@MrPeanutButta
MrPeanutButta / bit_flip.c
Created May 1, 2013 22:40
useful bitflip. designing software DIR-24-8-basic.
/*
* for use with software DIR-24-8-basic.
* personal implementation.
*/
void flip_state(uint32_t &prefix, uint8_t &position){
prefix = prefix ^ 1<<position;
}
@MrPeanutButta
MrPeanutButta / more.c
Last active December 15, 2015 23:29
pipe output to 'more' or 'less'
int more(const char *buffer) {
pid_t pid(fork());
int status(0);
if (!pid) {
FILE *output{};
output = popen("more", "w");
if (!output) {