Skip to content

Instantly share code, notes, and snippets.

View compor's full-sized avatar

Chris Vasiladiotis compor

  • University of Edinburgh
  • Edinburgh, Scotland, UK
  • 03:11 (UTC +01:00)
View GitHub Profile
@compor
compor / weird goto function return
Created March 28, 2014 10:39
weird C goto label (to its own body) as function return address
#include <stdio.h>
void *
f(void) {
a:
printf("here!\n");
return &&a;
}
int
@compor
compor / dso_name_detect.awk
Created June 4, 2014 08:51
detects Linux DSO name forms and associates versioned suffix names with a single base name for a library
# need to use --posix or --re-interval
$0 ~ /^lib[^.]+\.so(.[0-9]+){0,3}$/ {
n = split($0, a, ".")
dso_basename = a[1];
suffix = ""
for(i = 2; i <= n; i++) {
suffix = suffix"."a[i]
}
@compor
compor / convert_fname_lowercase.sh
Created June 4, 2014 09:04
convert all file names in the current directory to lower case
#!/bin/sh
# convert all file names in the current directory to lower case
# only operates on plain files--does not change the name of directories
# will ask for verification before overwriting an existing file
for x in `ls`
do
if [ ! -f $x ]; then
continue
fi
@compor
compor / detect_endianess
Created June 4, 2014 10:12
detects machine endianess
#include <stdio.h>
int main(int argc, char* argv[]) {
int i = 1;
/* endianess dependent result */
if(*(char *) &i == 0)
fprintf( stderr, "little-endian\n" );
else
@compor
compor / column_correlate.sh
Created June 4, 2014 12:53
associates 2 columns of data using the first one's elements as key
#!/bin/bash
# parses an unsorted document with 2 columns :
#
# ip date
#
# where same ip's might appear multiple times and even the exact same ip date pair
# and outputs
#
# ip | # of occurences | list of dates of occurences
@compor
compor / c_linux_tcpd_api_example.c
Created February 25, 2013 14:40
c linux tcpd api example
/*
simple usage of the tcpd/tcp wrapper API
a full-fledged program would probalby call hosts_access() upon accepting a new
connection and if denied it would close()
the established connection with FIN,ACK or most preferably RST
build with :
gcc -c tcpd_test.c
# capture SYN/ACK flagged packets
# tcp[13] is the byte location of TCP flags (URG,ACK,PSH,RST,SYN,FIN)
#
# mnemonic
#
# Unskilled 32
# Attackers 16
# Pester 8
# Real 4
# Security 2
@compor
compor / LineBreakButton.cpp
Created February 25, 2013 14:46
breaks up qpushbutton text in to multiple lines
// header
#include <qobject.h>
#include <qwidget.h>
#include <qpushbutton.h>
class LineBreakButton : public QPushButton {
Q_OBJECT
public:
@compor
compor / bash_sort_filezila_log.sh
Created February 25, 2013 14:47
sort filezilla server log entries by session id
#!/bin/bash
#
# entry example
#
# (1579051) 10/16/2009 0:02:13 AM - (not logged in) (192.168.1.11)> USER chris
#
# sort -k1n fzs-2009-10-16.log
# does not work properly because when the session id and timestamp are the same
# it goes on and tries to sort based on the message
@compor
compor / bash_iperf_mcast_source_sink.sh
Created February 25, 2013 14:49
multicast traffic source/sink with iperf
# multicast group 239.1.1.1 on port 4321
# multicast listener/sink with read buffer of 512 bytes
iperf -s -u -B 239.1.1.1 -i 1 -l 512 -p 4321
# multicast transmitter/source with write buffer of 512 bytes
# fill up bandwidth of 80Kb/s