Skip to content

Instantly share code, notes, and snippets.

@javiermon
javiermon / mac2bin.py
Last active August 29, 2015 14:01
mac2bin.py
#!/usr/bin/python
# netaddr does this and more:
# >>> import netaddr
# >>> netaddr.EUI('d4:be:d9:23:d5:bf').words
import sys
if len(sys.argv) != 2:
print "usage %s mac-addr" % sys.argv[0]
sys.exit(-1)
@javiermon
javiermon / toolchain.txt
Last active January 4, 2016 22:09
embedded toolchain
- Download the toochain from http://buildroot.uclibc.org/downloads/
Once downloaded & unpacked:
make menuconfig
Then configure the toolchain, check kernel, uclibc, etc versions:
- kernel version (uname -a)
linux 2.6 (manually specified?)
linux version: 2.6.22
- Kernel & arch:
@javiermon
javiermon / kernel_page_size.txt
Created January 22, 2014 08:08
Get the kernel page size
One approximate method is to read /proc/meminfo and check Mapped size (on mine its 52544 kB as of now)
and then check nr_mapped in /proc/vmstat (on mine its 131136 as of now). Finally PAGE_SIZE = Mapped/nr_mapped.
Sometimes this gives you an accurate value (as in the current example I've quoted)
and sometimes its approximate but very close.

High-level

I want to write about why GDB is a great tool for learning C. At least part of the difficulty in learning C is that the language isn’t as interactive as using Python or Ruby.

TL;DR You can kinda use gdb as a repl for c

What’s the smallest possible program we could debug to learn about pointers?

@javiermon
javiermon / hexdump.c
Last active May 31, 2022 23:01
hexdump.c
#include <stdio.h>
void hexDump(char *desc, void *addr, int len)
{
int i;
unsigned char buff[17];
unsigned char *pc = addr;
// Output description if given.
if (desc != NULL)
#include <stdio.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/connector.h>
#include <linux/cn_proc.h>
#include <stdlib.h>
#include <errno.h>
struct __attribute__ ((aligned(NLMSG_ALIGNTO))) nlcn_msg {
struct nlmsghdr nl_hdr;
@javiermon
javiermon / detect_endianness.c
Last active December 26, 2015 21:49
Detect endianness at runtime
/*
$ printf '\1' | od -dAn
Little Endian: 1
Big Endian: 256
*/
#include <inttypes.h>
int main(int argc, char ** argv){
volatile uint32_t i=0x01234567;
@javiermon
javiermon / timedsocket.c
Last active December 21, 2015 19:59
timing of socket sys calls
/*
$ LANG=C gcc -g -Wall -Werror socket.c -o socket
$ ./socket 50.116.14.9 0
START
2013-08-27 21:04:47.762757
socket()
2013-08-27 21:04:47.762859
Error : Connect Failed Connection refused
2013-08-27 21:04:47.956695
@javiermon
javiermon / LICENSE
Last active July 8, 2024 06:36
get default gateway
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname