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
This commit is contained in:
Nathan Binkert 2003-10-26 22:40:03 -05:00
parent 34adf92749
commit 91293e02d2
2 changed files with 22 additions and 17 deletions

View file

@ -33,14 +33,12 @@ CXX= g++
CURDIR?= $(shell /bin/pwd) CURDIR?= $(shell /bin/pwd)
SRCDIR?= . SRCDIR?= .
M5_SRCDIR?= $(SRCDIR)/../..
BASE_SRCDIR?= $(SRCDIR)/../../base vpath % $(M5_SRCDIR)/base
SIM_SRCDIR?= $(SRCDIR)/../../sim vpath % $(M5_SRCDIR)/sim
vpath % $(BASE_SRCDIR) INCLDIRS= -I. -I$(M5_SRCDIR) -I- -I/usr/local/include
vpath % $(SIM_SRCDIR)
INCLDIRS= -I. -I$(BASE_SRCDIR) -I$(SIM_SRCDIR) -I- -I/usr/local/include
CCFLAGS= -g -O0 -MMD $(INCLDIRS) CCFLAGS= -g -O0 -MMD $(INCLDIRS)
default: m5tap default: m5tap
@ -48,6 +46,8 @@ default: m5tap
m5tap: tap.o cprintf.o m5tap: tap.o cprintf.o
$(CXX) $(LFLAGS) -o $@ $^ -lpcap -L/usr/local/lib -ldnet $(CXX) $(LFLAGS) -o $@ $^ -lpcap -L/usr/local/lib -ldnet
install: m5tap
$(SUDO) install -o root -m 555 m5tap /usr/local/bin
clean: clean:
@rm -f m5tap *.o *.d *~ .#* @rm -f m5tap *.o *.d *~ .#*

View file

@ -71,12 +71,12 @@ usage()
int verbose = 0; int verbose = 0;
#define DPRINTF(args...) do { \ #define DPRINTF(args...) do { \
if (verbose > 1) \ if (verbose >= 1) \
cprintf(args); \ cprintf(args); \
} while (0) } while (0)
#define DDUMP(args...) do { \ #define DDUMP(args...) do { \
if (verbose > 2) \ if (verbose >= 2) \
dump((const u_char *)args); \ dump((const u_char *)args); \
} while (0) } while (0)
@ -126,13 +126,13 @@ Socket(int reuse)
{ {
int fd = ::socket(PF_INET, SOCK_STREAM, 0); int fd = ::socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0) if (fd < 0)
panic("Can't create socket!"); panic("Can't create socket!\n");
if (reuse) { if (reuse) {
int i = 1; int i = 1;
if (::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&i, if (::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&i,
sizeof(i)) < 0) sizeof(i)) < 0)
panic("setsockopt() SO_REUSEADDR failed!"); panic("setsockopt() SO_REUSEADDR failed!\n");
} }
return fd; return fd;
@ -148,10 +148,10 @@ Listen(int fd, int port)
sockaddr.sin_port = htons(port); sockaddr.sin_port = htons(port);
int ret = ::bind(fd, (struct sockaddr *)&sockaddr, sizeof (sockaddr)); int ret = ::bind(fd, (struct sockaddr *)&sockaddr, sizeof (sockaddr));
if (ret == -1) if (ret == -1)
panic("bind() failed!"); panic("bind() failed!\n");
if (::listen(fd, 1) == -1) 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, // 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); socklen_t slen = sizeof (sockaddr);
int sfd = ::accept(fd, (struct sockaddr *)&sockaddr, &slen); int sfd = ::accept(fd, (struct sockaddr *)&sockaddr, &slen);
if (sfd == -1) if (sfd == -1)
panic("accept() failed!"); panic("accept() failed!\n");
if (nodelay) { if (nodelay) {
int i = 1; int i = 1;
@ -188,7 +188,7 @@ Connect(int fd, const string &host, int port)
sockaddr.sin_port = htons(port); sockaddr.sin_port = htons(port);
if (::connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) != 0) 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); DPRINTF("connected to %s on port %d\n", host, port);
} }
@ -269,13 +269,14 @@ main(int argc, char *argv[])
} }
char errbuf[PCAP_ERRBUF_SIZE]; char errbuf[PCAP_ERRBUF_SIZE];
memset(errbuf, 0, sizeof errbuf);
pcap_t *pcap = pcap_open_live(device, 1500, 1, -1, errbuf); pcap_t *pcap = pcap_open_live(device, 1500, 1, -1, errbuf);
if (pcap == NULL) if (pcap == NULL)
panic("pcap_open_live failed: %s\n", errbuf); panic("pcap_open_live failed: %s\n", errbuf);
bpf_program program; bpf_program program;
bpf_u_int32 localnet, netmask; 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); panic("pcap_lookupnet failed: %s\n", errbuf);
if (pcap_compile(pcap, &program, filter, 1, netmask) == -1) if (pcap_compile(pcap, &program, filter, 1, netmask) == -1)
@ -285,6 +286,8 @@ main(int argc, char *argv[])
panic("pcap_setfilter failed\n"); panic("pcap_setfilter failed\n");
eth_t *ethernet = eth_open(device); eth_t *ethernet = eth_open(device);
if (!ethernet)
panic("cannot open the ethernet device for writing\n");
pollfd pfds[3]; pollfd pfds[3];
pfds[0].fd = Socket(true); pfds[0].fd = Socket(true);
@ -312,6 +315,7 @@ main(int argc, char *argv[])
int32_t buffer_offset = 0; int32_t buffer_offset = 0;
int32_t data_len = 0; int32_t data_len = 0;
DPRINTF("Begin poll loop\n");
while (!quit) { while (!quit) {
int ret = ::poll(pfds, npfds, INFTIM); int ret = ::poll(pfds, npfds, INFTIM);
if (ret < 0) if (ret < 0)
@ -392,14 +396,15 @@ main(int argc, char *argv[])
if (listening) if (listening)
npfds--; npfds--;
else else {
DPRINTF("Calling it quits because of poll error\n");
quit = true; quit = true;
} }
}
if (client_pfd) if (client_pfd)
client_pfd->revents = 0; client_pfd->revents = 0;
} }
} }
delete [] buffer; delete [] buffer;