summaryrefslogtreecommitdiff
path: root/util/tap
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2003-10-26 22:40:03 -0500
committerNathan Binkert <binkertn@umich.edu>2003-10-26 22:40:03 -0500
commit91293e02d2cf227a8cbeb4f4bc5aaed5cc86bac4 (patch)
treebf0d0931d8b33ff45eccb87ee80c50a0a81f54bf /util/tap
parent34adf92749a10970aaa3138912ebeab50973d24d (diff)
downloadgem5-91293e02d2cf227a8cbeb4f4bc5aaed5cc86bac4.tar.xz
Make the tap work work again
util/tap/Makefile: Make this stuff compile again util/tap/tap.cc: clean up some of the error messages --HG-- extra : convert_revision : 4543d946b48c9e07bf19b812db6466f80ed6b851
Diffstat (limited to 'util/tap')
-rw-r--r--util/tap/Makefile12
-rw-r--r--util/tap/tap.cc27
2 files changed, 22 insertions, 17 deletions
diff --git a/util/tap/Makefile b/util/tap/Makefile
index c7078158b..2618a5210 100644
--- a/util/tap/Makefile
+++ b/util/tap/Makefile
@@ -33,14 +33,12 @@ CXX= g++
CURDIR?= $(shell /bin/pwd)
SRCDIR?= .
+M5_SRCDIR?= $(SRCDIR)/../..
-BASE_SRCDIR?= $(SRCDIR)/../../base
-SIM_SRCDIR?= $(SRCDIR)/../../sim
+vpath % $(M5_SRCDIR)/base
+vpath % $(M5_SRCDIR)/sim
-vpath % $(BASE_SRCDIR)
-vpath % $(SIM_SRCDIR)
-
-INCLDIRS= -I. -I$(BASE_SRCDIR) -I$(SIM_SRCDIR) -I- -I/usr/local/include
+INCLDIRS= -I. -I$(M5_SRCDIR) -I- -I/usr/local/include
CCFLAGS= -g -O0 -MMD $(INCLDIRS)
default: m5tap
@@ -48,6 +46,8 @@ default: m5tap
m5tap: tap.o cprintf.o
$(CXX) $(LFLAGS) -o $@ $^ -lpcap -L/usr/local/lib -ldnet
+install: m5tap
+ $(SUDO) install -o root -m 555 m5tap /usr/local/bin
clean:
@rm -f m5tap *.o *.d *~ .#*
diff --git a/util/tap/tap.cc b/util/tap/tap.cc
index 9c13051ca..7121ebcbb 100644
--- a/util/tap/tap.cc
+++ b/util/tap/tap.cc
@@ -71,12 +71,12 @@ usage()
int verbose = 0;
#define DPRINTF(args...) do { \
- if (verbose > 1) \
+ if (verbose >= 1) \
cprintf(args); \
} while (0)
#define DDUMP(args...) do { \
- if (verbose > 2) \
+ if (verbose >= 2) \
dump((const u_char *)args); \
} while (0)
@@ -126,13 +126,13 @@ Socket(int reuse)
{
int fd = ::socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0)
- panic("Can't create socket!");
+ panic("Can't create socket!\n");
if (reuse) {
int i = 1;
if (::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&i,
sizeof(i)) < 0)
- panic("setsockopt() SO_REUSEADDR failed!");
+ panic("setsockopt() SO_REUSEADDR failed!\n");
}
return fd;
@@ -148,10 +148,10 @@ Listen(int fd, int port)
sockaddr.sin_port = htons(port);
int ret = ::bind(fd, (struct sockaddr *)&sockaddr, sizeof (sockaddr));
if (ret == -1)
- panic("bind() failed!");
+ panic("bind() failed!\n");
if (::listen(fd, 1) == -1)
- panic("listen() failed!");
+ panic("listen() failed!\n");
}
// Open a connection. Accept will block, so if you don't want it to,
@@ -163,7 +163,7 @@ Accept(int fd, bool nodelay)
socklen_t slen = sizeof (sockaddr);
int sfd = ::accept(fd, (struct sockaddr *)&sockaddr, &slen);
if (sfd == -1)
- panic("accept() failed!");
+ panic("accept() failed!\n");
if (nodelay) {
int i = 1;
@@ -188,7 +188,7 @@ Connect(int fd, const string &host, int port)
sockaddr.sin_port = htons(port);
if (::connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) != 0)
- panic("could not connect to %s on port %d", host, port);
+ panic("could not connect to %s on port %d\n", host, port);
DPRINTF("connected to %s on port %d\n", host, port);
}
@@ -269,13 +269,14 @@ main(int argc, char *argv[])
}
char errbuf[PCAP_ERRBUF_SIZE];
+ memset(errbuf, 0, sizeof errbuf);
pcap_t *pcap = pcap_open_live(device, 1500, 1, -1, errbuf);
if (pcap == NULL)
panic("pcap_open_live failed: %s\n", errbuf);
bpf_program program;
bpf_u_int32 localnet, netmask;
- if (!pcap_lookupnet(device, &localnet, &netmask, errbuf))
+ if (pcap_lookupnet(device, &localnet, &netmask, errbuf) == -1)
panic("pcap_lookupnet failed: %s\n", errbuf);
if (pcap_compile(pcap, &program, filter, 1, netmask) == -1)
@@ -285,6 +286,8 @@ main(int argc, char *argv[])
panic("pcap_setfilter failed\n");
eth_t *ethernet = eth_open(device);
+ if (!ethernet)
+ panic("cannot open the ethernet device for writing\n");
pollfd pfds[3];
pfds[0].fd = Socket(true);
@@ -312,6 +315,7 @@ main(int argc, char *argv[])
int32_t buffer_offset = 0;
int32_t data_len = 0;
+ DPRINTF("Begin poll loop\n");
while (!quit) {
int ret = ::poll(pfds, npfds, INFTIM);
if (ret < 0)
@@ -392,14 +396,15 @@ main(int argc, char *argv[])
if (listening)
npfds--;
- else
+ else {
+ DPRINTF("Calling it quits because of poll error\n");
quit = true;
+ }
}
if (client_pfd)
client_pfd->revents = 0;
}
-
}
delete [] buffer;