Skip to content

Commit

Permalink
a couple patches
Browse files Browse the repository at this point in the history
Incorporated Mario and Dmitry's patches.  See the ChangeLog

darcs-hash:20061010213746-28bda-1874bbfb40a1ffb92516d57782302ab09eedc368.gz
  • Loading branch information
fugalh committed Oct 10, 2006
1 parent a9b9fbb commit 7d8eb31
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 35 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
@@ -1,3 +1,5 @@
Hans Fugal wrote it.
Von Fugal patched it.
Leonard Ritter (paniq) made it sound cool.
Mario Lang added filter expressions.
Dmitry Baikov added suid and privilege dropping, and got rid of the evil mutex.
28 changes: 22 additions & 6 deletions ChangeLog
@@ -1,11 +1,27 @@
2006-10-10 Dmitry Baikov <dsbaikov@gmail.com>

* make hearnet suid and drop privileges right after libpcap
initialization.
* Mutex in jack_process is a very bad thing. Moreover, it seems
there's no need for it, as voice->active field serves as a mutex.

N.B. It's good enough I think, but I wonder if we might need some
sort of memory barrier, as noted in the comments. -- Hans

2005-09-30 Mario Lang <mlang@delysid.org>

* Added filter expression support, so now you can say
./hearnet eth0 "udp port 53"
or whatever kind of filter expression you can think of. Very nice for
listening in on just specific traffic patterns!

2005-07-26 Leonard Ritter <paniq|paniq-org>

* changed code so that it uses 32-voice polyphony and plays bridges /
chromatic orders.

as an effect, you get very harmonic sounds if packet sizes on a
site are the same, and quite weird stuff if packet sizes vary.

* changed code so that it uses 32-voice polyphony and plays bridges /
chromatic orders.

as an effect, you get very harmonic sounds if packet sizes on a
site are the same, and quite weird stuff if packet sizes vary.

2004-11-12 Hans Fugal <hans@fugal.net>

Expand Down
9 changes: 8 additions & 1 deletion Makefile
@@ -1,13 +1,20 @@
CFLAGS+=-g
LDFLAGS+=`pkg-config --cflags --libs jack` -lpcap
version=0.0.4
version=0.0.9

all: hearnet grain.raw
-sudo make suid

%.raw: %.wav
sox $< -r 44800 -s -w $@
clean:
rm -f hearnet *.o core*

suid: hearnet
chown root $<
chmod u+s $<

dist: all
darcs dist -d hearnet-$(version)

.PHONY: suid dist all clean
28 changes: 22 additions & 6 deletions README
@@ -1,17 +1,33 @@
hearnet - listen to your network

Requirements:
libpcap
libjack
- libpcap
- libjack

This is how I run hearnet:
$ sudo jackd -d alsa &
$ sudo ./hearnet &
Synopsis:
make
sudo make suid
# start jack if necessary
./hearnet

Details:

hearnet now drops priveleges when run with the suid bit set, which means
you can hook it into your regular non-root jackd, and run it as a normal
user.

You can specify a filter expression (a la tcpdump), e.g.:

./hearnet eth0 udp port 53

Very nice for listening to just one kind of traffic. Try this for an
accompaniment to your VOIP conversation:

./hearnet eth0 udp port sip

License:

Copyright (C) 2003-2005 Hans Fugal <hans@fugal.net>
Copyright (C) 2003-2006 Hans Fugal <hans@fugal.net>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
61 changes: 39 additions & 22 deletions hearnet.cpp
Expand Up @@ -21,6 +21,7 @@
#include <math.h>
#include <memory.h>
#include <time.h>
#include <string>

/* macros */
/// length of grain in samples
Expand All @@ -31,7 +32,6 @@
#define MAX_VOICES 16

/* data */
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
jack_port_t *output_port;
jack_nframes_t srate;

Expand Down Expand Up @@ -75,8 +75,6 @@ int process (jack_nframes_t nframes, void *arg)/*{{{*/
{
jack_default_audio_sample_t *out = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port, nframes);

pthread_mutex_lock(&mutex);

memset(out, 0, sizeof(jack_default_audio_sample_t)*nframes);

for (int index = 0; index != MAX_VOICES; index++)
Expand Down Expand Up @@ -114,8 +112,6 @@ int process (jack_nframes_t nframes, void *arg)/*{{{*/
}
}

pthread_mutex_unlock(&mutex);

return 0;
}/*}}}*/
/** jack callback to set sample rate */
Expand All @@ -138,8 +134,6 @@ void shutdown(void *arg)/*{{{*/
/** packet handler called by pcap_dispatch in main() */
void packet_handler(u_char * args, const struct pcap_pkthdr *pcap_hdr, const u_char * p)/*{{{*/
{
pthread_mutex_lock(&mutex);

voice* new_voice = get_free_voice();
if (new_voice)
{
Expand All @@ -153,17 +147,21 @@ void packet_handler(u_char * args, const struct pcap_pkthdr *pcap_hdr, const u_c
new_voice->decaylength = (rand()%100 + 100) / 1000.0f;
new_voice->attack = 0.0f;
new_voice->attacklength = (rand()%20 + 1) / 1000.0f; // 10ms
new_voice->active = true;
// Since we took out the mutex, we depend on this last
// assignment not happening out-of-order. I don't know of a
// portable memory barrier, so we'll just let it float. I
// doubt it will be a noticeable problem, but if it is then
// figure out some way to put a barrier here.
new_voice->active = true;
}
pthread_mutex_unlock(&mutex);

}/*}}}*/

void usage(void)/*{{{*/
{
fprintf(stderr,
"\n"
"usage: hearnet [interface]\n"
"usage: hearnet [interface [filter-expression]]\n"
"Default interface is eth0.\n"
);
exit(1);
Expand All @@ -178,6 +176,37 @@ int main(int argc, char **argv)/*{{{*/

if (argc > 1)
dev = argv[1];

// libpcap stuff /*{{{*/
pcap_t *hdl_pcap;
char perrbuf[PCAP_ERRBUF_SIZE];
hdl_pcap = pcap_open_live(dev, BUFSIZ, 0, 0, perrbuf);
if (hdl_pcap == NULL)
{
fprintf(stderr,"pcap_open_live; %s\n", perrbuf);
usage();
}

if (argc > 2) {
bpf_program bpfprog;
std::string s;
for (int i=2; i<argc; i++)
s += std::string(argv[i]) + std::string(" ");
char *cstr = (char*)malloc(s.size()+1);
strncpy(cstr,s.c_str(),s.size()+1);

if (pcap_compile(hdl_pcap, &bpfprog, cstr, 1, 0XFFFFFFFF) != -1) {
pcap_setfilter(hdl_pcap, &bpfprog);
} else {
printf("Error compiling filter: %s\n", pcap_geterr(hdl_pcap));
exit(1);
}
}

seteuid(getuid());

/*}}}*/


snprintf(client_name, sizeof(client_name), "hearnet %s", dev);
// jack stuff {{{
Expand Down Expand Up @@ -219,18 +248,6 @@ int main(int argc, char **argv)/*{{{*/
init_voices();


// libpcap stuff /*{{{*/
pcap_t *hdl_pcap;
char perrbuf[PCAP_ERRBUF_SIZE];
hdl_pcap = pcap_open_live(dev, BUFSIZ, 0, 0, perrbuf);
if (hdl_pcap == NULL)
{
fprintf(stderr,"pcap_open_live; %s\n", perrbuf);
usage();
}

/*}}}*/

timeval tv_start;
gettimeofday(&tv_start,0);
srand(tv_start.tv_sec);
Expand Down

0 comments on commit 7d8eb31

Please sign in to comment.