--- /dev/null
+#!/usr/bin/newlisp
+#
+# Open a raw socket to sniff an interface; output to stdout
+
+(signal 2 (fn (x) (exit 0)))
+
+(context 'LIBC6)
+(constant 'library "/lib/x86_64-linux-gnu/libc.so.6")
+(import library "ioctl" "int" "int" "long" "void*" )
+(import library "perror" "void" "char*" )
+(import library "fdopen" "void*" "int" "char*" )
+(import library "setbuf" "void" "void*" "void*" )
+(import library "ntohs" "int" "int" )
+(import library "htons" "int" "int" )
+(import library "inet_addr" "void*" "void*")
+(import library "socket" "int" "int" "int" "int")
+(import library "setsockopt" "int" "int" "int" "int" "void*" "int")
+(import library "perror" "void" "char*")
+(setf bind-socket (import library "bind" "int" "int" "void*" "int"))
+
+(define (die)
+ (perror (join (map string (args)) " "))
+ (exit 1))
+
+(letex ((AF_INET 2)
+ (SOCK_RAW 10)
+ (IPPROTO_RAW (htons 0x0800))
+ (SOL_SOCKET 1)
+ (SO_BINDTODEVICE 25)
+ (SO_BROADCAST 6)
+ (SIZEOF_struct_sockaddr 16)
+ )
+ (define (raw-socket)
+ (socket AF_INET SOCK_RAW IPPROTO_RAW))
+
+ (define (bind-to-device FD IFACE)
+ (when (!= (setsockopt FD SOL_SOCKET SO_BINDTODEVICE IFACE (length IFACE)))
+ (die "setsockopt bind"))
+ (when (!= (setsockopt FD SOL_SOCKET SO_BROADCAST (pack "lu" 1) 4))
+ (die "setsockopt broadcast"))
+ 0)
+
+ ) ; end letex
+
+(context MAIN)
+
+(setf IFACE (main-args -1) FD (LIBC6:raw-socket) )
+
+(when (< FD)
+ (LIBC6:die "socket"))
+
+(when (!= (LIBC6:bind-to-device FD IFACE))
+ (LIBC6:die "bind-to-device"))
+
+(LIBC6:setbuf (LIBC6:fdopen 1 "w") 0)
+
+(while (> (setf N (read FD BUFFER 2048)) 0)
+ (write 1 BUFFER))
+
+(exit 0)