Skip to content

Commit

Permalink
""
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Lightfoot committed May 28, 2002
1 parent 8055b8f commit 526d8ee
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 35 deletions.
6 changes: 5 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Changelog for driftnet
$Id: CHANGES,v 1.8 2002/05/27 16:59:44 chris Exp $
$Id: CHANGES,v 1.9 2002/05/28 20:19:09 chris Exp $

0.1.5

Expand All @@ -15,6 +15,10 @@ driftnet as a back-end for some other program. It is now possible to compile
a back-end only version of driftnet without any X11 support by using the
NO_DISPLAY_WINDOW option at compile time.

Added the -s option to extract MPEG audio data from network streams, along with
a ghastly mess of threads and pipes to allow driftnet to play the data to play
through mpg123 or similar.

Changed some things to make driftnet a bit more portable to non-Linux systems.

0.1.4
Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# Copyright (c) 2001 Chris Lightfoot. All rights reserved.
# Email: [email protected]; WWW: http://www.ex-parrot.com/~chris/
#
# $Id: Makefile,v 1.16 2002/05/28 00:23:55 chris Exp $
# $Id: Makefile,v 1.17 2002/05/28 20:19:09 chris Exp $
#

# Driftnet version. Do not alter.
VERSION = 0.1.5pre1
VERSION = 0.1.5pre2

# Compiler to use.
#CC = gcc
Expand All @@ -26,8 +26,8 @@ CFLAGS += -I/usr/include/pcap
# Required on Linux to get BSDish definitions of the TCP/IP structs.
CFLAGS += -D_BSD_SOURCE

# We always need the pcap library.
LDLIBS += -lpcap
# We always need the pcap and pthread libraries.
LDLIBS += -lpcap -lpthread

# Optional C compiler and linker flags. Typical driftnet builds have support
# for displaying captured images in an X window, and need the following flags:
Expand All @@ -43,7 +43,8 @@ LDLIBS += -ljpeg -lungif `gtk-config --libs`
SUBDIRS =

TXTS = README TODO COPYING CHANGES CREDITS driftnet.1 driftnet.1.in
SRCS = audio.c mpeghdr.c gif.c img.c jpeg.c png.c driftnet.c image.c display.c
SRCS = audio.c mpeghdr.c gif.c img.c jpeg.c png.c driftnet.c image.c \
display.c playaudio.c
HDRS = img.h driftnet.h mpeghdr.h
BINS = driftnet

Expand Down
8 changes: 5 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TODO for driftnet
$Id: TODO,v 1.5 2002/05/27 16:59:44 chris Exp $
$Id: TODO,v 1.6 2002/05/28 20:19:09 chris Exp $

* PNG files.

Expand All @@ -12,11 +12,13 @@ $Id: TODO,v 1.5 2002/05/27 16:59:44 chris Exp $
truncated in a really bad way. An alternative is to store more state for
JPEG files, and do special parsing when we know a connection has closed.

* Drop privileges after starting up pcap.

* More portability / bug fixes.

* Web-based version. Server push? Feedback problems.

* `Bogus image' problem after running for a while?

* Safe(r) setuid operation.

* Drop privileges after starting up pcap.

6 changes: 3 additions & 3 deletions driftnet.1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
.\" Copyright (c) 2002 Chris Lightfoot. All rights reserved.
.\" Email: [email protected]; WWW: http://www.ex-parrot.com/~chris/
.\"
.\" $Id: driftnet.1,v 1.5 2002/05/28 00:23:55 chris Exp $
.\" $Id: driftnet.1,v 1.6 2002/05/28 20:19:09 chris Exp $
.\"

.SH NAME
Expand Down Expand Up @@ -83,9 +83,9 @@ syntax. User filter code is evaluated as `tcp and (\fIfilter code\fP)'.
Chris Lightfoot <[email protected]>

.SH VERSION
\fBDriftnet\fP, version0.1.5pre1.
\fBDriftnet\fP, version 0.1.5pre1.
.br
$Id: driftnet.1,v 1.5 2002/05/28 00:23:55 chris Exp $
$Id: driftnet.1,v 1.6 2002/05/28 20:19:09 chris Exp $

.SH COPYING
This program is free software; you can redistribute it and/or modify
Expand Down
6 changes: 3 additions & 3 deletions driftnet.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.\" Copyright (c) 2002 Chris Lightfoot. All rights reserved.
.\" Email: [email protected]; WWW: http://www.ex-parrot.com/~chris/
.\"
.\" $Id: driftnet.1.in,v 1.1 2002/05/27 16:59:44 chris Exp $
.\" $Id: driftnet.1.in,v 1.2 2002/05/28 20:19:09 chris Exp $
.\"

.SH NAME
Expand Down Expand Up @@ -82,9 +82,9 @@ syntax. User filter code is evaluated as `tcp and (\fIfilter code\fP)'.
Chris Lightfoot <[email protected]>

.SH VERSION
\fBDriftnet\fP, version@@@VERSION@@@.
\fBDriftnet\fP, version @@@VERSION@@@.
.br
$Id: driftnet.1.in,v 1.1 2002/05/27 16:59:44 chris Exp $
$Id: driftnet.1.in,v 1.2 2002/05/28 20:19:09 chris Exp $

.SH COPYING
This program is free software; you can redistribute it and/or modify
Expand Down
58 changes: 38 additions & 20 deletions driftnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

static const char rcsid[] = "$Id: driftnet.c,v 1.15 2002/05/28 00:23:55 chris Exp $";
static const char rcsid[] = "$Id: driftnet.c,v 1.16 2002/05/28 20:19:09 chris Exp $";

#undef NDEBUG

Expand Down Expand Up @@ -42,7 +42,6 @@ int max_images;

/* audio stuff. */
int extract_audio;
char *audio_mpeg_player = "mpg123";

/* ugh. */
pcap_t *pc;
Expand All @@ -63,6 +62,10 @@ int dpychld_fd;
int dodisplay(int argc, char *argv[]);
#endif /* !NO_DISPLAY_WINDOW */

/* playaudio.c */
void do_mpeg_player(void);
void mpeg_submit_chunk(const unsigned char *data, const size_t len);

/* count_temporary_files:
* How many of our files remain in the temporary directory? We do this a
* maximum of once every five seconds. */
Expand All @@ -78,7 +81,7 @@ static int count_temporary_files(void) {
while ((de = readdir(d))) {
char *p;
p = strrchr(de->d_name, '.');
if (p && (strncmp(de->d_name, "driftnet-", 9) == 0 && (strcmp(p, ".jpg") == 0 || strcmp(p, ".gif") == 0)))
if (p && (strncmp(de->d_name, "driftnet-", 9) == 0 && (strcmp(p, ".jpg") == 0 || strcmp(p, ".gif") == 0 || strcmp(p, ".mp3") == 0)))
++num;
}
closedir(d);
Expand All @@ -105,7 +108,7 @@ void clean_temporary_directory(void) {
while ((de = readdir(d))) {
char *p;
p = strrchr(de->d_name, '.');
if (!tmpdir_specified || (p && strncmp(de->d_name, "driftnet-", 9) == 0 && (strcmp(p, ".jpg") == 0 || strcmp(p, ".gif") == 0))) {
if (!tmpdir_specified || (p && strncmp(de->d_name, "driftnet-", 9) == 0 && (strcmp(p, ".jpg") == 0 || strcmp(p, ".gif") == 0) || strcmp(p, ".mp3") == 0)) {
sprintf(s, "%s/%s", tmpdir, de->d_name);
unlink(s);
}
Expand Down Expand Up @@ -243,14 +246,22 @@ void connection_harvest_audio(connection c) {
ptr = find_mpeg_stream(ptr, c->len - (ptr - c->data), &audio, &alen);

if (audio) {
char buf[PATH_MAX + 1];
int fd;
sprintf(buf, "%s/driftnet-%d.%d.mp3", tmpdir, (int)time(NULL), rand());
fd = open(buf, O_WRONLY|O_CREAT|O_EXCL, 0644);
write(fd, audio, alen);
close(fd);
/* image_notify(ilen, buf);*/
fprintf(stderr, "audio %s\n", buf);
if (!adjunct) {
/* Try to play audio. */
if (verbose)
fprintf(stderr, PROGNAME": got %d bytes of MPEG audio\n", alen);
mpeg_submit_chunk(audio, alen);
} else {
/* Save it in a file. */
char buf[PATH_MAX + 1];
int fd;
sprintf(buf, "%s/driftnet-%d.%d.mp3", tmpdir, (int)time(NULL), rand());
fd = open(buf, O_WRONLY|O_CREAT|O_EXCL, 0644);
write(fd, audio, alen);
close(fd);
fprintf(stderr, PROGNAME": saved %d bytes of MPEG audio in %s\n", alen, buf);
printf("%s\n", buf);
}
}
}

Expand Down Expand Up @@ -294,6 +305,7 @@ void sweep_connections() {
if ((now - c->last) > TIMEOUT) {
/* get any last images out of this one */
connection_harvest_images(c);
if (extract_audio) connection_harvest_audio(c);
connection_delete(c);
*C = NULL;
}
Expand Down Expand Up @@ -397,9 +409,10 @@ void usage(FILE *fp) {
" -s Attempt to extract streamed audio data from the network,\n"
" in addition to images. At present this supports MPEG data\n"
" only.\n"
/*" -S Extract streamed audio but not images.\n"*/
" -M command Use the given command to play MPEG audio data extracted\n"
" with the -s option; the name of a file to play will be\n"
" appended to the command line. Default: `mpg123'\n"
" with the -s option; this should process MPEG frames\n"
" supplied on standard input. Default: `mpg123 -'.\n"
" -v Verbose operation.\n"
" -a Adjunct mode: do not display images on screen, but save\n"
" them to a temporary directory and announce their names on\n"
Expand Down Expand Up @@ -444,7 +457,7 @@ void terminate_on_signal(int s) {
_exit(0);
} else {
close(dpychld_fd);
pcap_close(pc);
if (pc) pcap_close(pc);
_exit(0);
}
#endif /* NO_DISPLAY_WINDOW */
Expand All @@ -458,7 +471,7 @@ void setup_signals(void) {
int ignore_signals[] = {SIGPIPE, 0};
/* Signals which mean we should quit, killing the display child if
* applicable. */
int terminate_signals[] = {SIGTERM, SIGINT, SIGSEGV, SIGBUS, SIGCHLD, 0};
int terminate_signals[] = {SIGTERM, SIGINT, /*SIGSEGV,*/ SIGBUS, SIGCHLD, 0};
struct sigaction sa;

sa.sa_flags = SA_RESTART;
Expand Down Expand Up @@ -500,7 +513,8 @@ int main(int argc, char *argv[]) {
const unsigned char *pkt;
int pkt_offset;
int c;
extern char *savedimgpfx; /* in display.c */
extern char *savedimgpfx; /* in display.c */
extern char *audio_mpeg_player; /* in playaudio.c */
int newpfx = 0;
int mpeg_player_specified = 0;

Expand Down Expand Up @@ -630,7 +644,6 @@ int main(int argc, char *argv[]) {
filterexpr = calloc(l, 1);
strcpy(filterexpr, "tcp and (");
for (a = argv + optind; *a; ++a) {
printf("*a = %s\n", *a);
strcat(filterexpr, *a);
if (*(a + 1)) strcat(filterexpr, " ");
}
Expand All @@ -640,11 +653,16 @@ int main(int argc, char *argv[]) {
if (verbose)
fprintf(stderr, PROGNAME": using filter expression `%s'\n", filterexpr);

setup_signals();

if (verbose && newpfx && !adjunct)
fprintf(stderr, PROGNAME": using saved image prefix `%s'\n", savedimgpfx);

setup_signals();

/* Start up the audio player, if required. */
if (extract_audio && !adjunct)
do_mpeg_player();

#ifndef NO_DISPLAY_WINDOW
/* Possibly fork to start the display child process */
if (!adjunct) {
Expand Down Expand Up @@ -673,6 +691,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr, PROGNAME": operating in adjunct mode\n");
#endif /* !NO_DISPLAY_WINDOW */


/* Start up pcap. */
pc = pcap_open_live(interface, 262144, promisc, 1, ebuf);
if (!pc) {
Expand Down Expand Up @@ -702,7 +721,6 @@ int main(int argc, char *argv[]) {
if (verbose)
fprintf(stderr, PROGNAME": link-level header length is %d bytes\n", pkt_offset);


slotsused = 0;
slotsalloc = 64;
slots = (connection*)calloc(slotsalloc, sizeof(connection));
Expand Down

0 comments on commit 526d8ee

Please sign in to comment.