ethertap.cc (12055:945e851d846b) | ethertap.cc (12056:1ad5b3161819) |
---|---|
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 24 unchanged lines hidden (view full) --- 33 */ 34 35#include "dev/net/ethertap.hh" 36 37#if defined(__OpenBSD__) || defined(__APPLE__) 38#include <sys/param.h> 39 40#endif | 1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 24 unchanged lines hidden (view full) --- 33 */ 34 35#include "dev/net/ethertap.hh" 36 37#if defined(__OpenBSD__) || defined(__APPLE__) 38#include <sys/param.h> 39 40#endif |
41 42#if USE_TUNTAP && defined(__linux__) 43#if 1 // Hide from the style checker since these have to be out of order. 44#include <sys/socket.h> // Has to be included before if.h for some reason. 45 46#endif 47 48#include <linux/if.h> 49#include <linux/if_tun.h> 50 51#endif 52 53#include <fcntl.h> |
|
41#include <netinet/in.h> | 54#include <netinet/in.h> |
55#include <sys/ioctl.h> |
|
42#include <unistd.h> 43 | 56#include <unistd.h> 57 |
58#include <cstring> |
|
44#include <deque> 45#include <string> 46 47#include "base/misc.hh" 48#include "base/pollevent.hh" 49#include "base/socket.hh" 50#include "base/trace.hh" 51#include "debug/Ethernet.hh" --- 320 unchanged lines hidden (view full) --- 372 uint32_t frame_len = htonl(len); 373 ssize_t ret = write(socket, &frame_len, sizeof(frame_len)); 374 if (ret != sizeof(frame_len)) 375 return false; 376 return write(socket, data, len) == len; 377} 378 379 | 59#include <deque> 60#include <string> 61 62#include "base/misc.hh" 63#include "base/pollevent.hh" 64#include "base/socket.hh" 65#include "base/trace.hh" 66#include "debug/Ethernet.hh" --- 320 unchanged lines hidden (view full) --- 387 uint32_t frame_len = htonl(len); 388 ssize_t ret = write(socket, &frame_len, sizeof(frame_len)); 389 if (ret != sizeof(frame_len)) 390 return false; 391 return write(socket, data, len) == len; 392} 393 394 |
395#if USE_TUNTAP 396 397EtherTap::EtherTap(const Params *p) : EtherTapBase(p) 398{ 399 int fd = open(p->tun_clone_device.c_str(), O_RDWR); 400 if (fd < 0) 401 panic("Couldn't open %s.\n", p->tun_clone_device); 402 403 struct ifreq ifr; 404 memset(&ifr, 0, sizeof(ifr)); 405 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; 406 strncpy(ifr.ifr_name, p->tap_device_name.c_str(), IFNAMSIZ); 407 408 if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) 409 panic("Failed to access tap device %s.\n", ifr.ifr_name); 410 // fd now refers to the tap device. 411 tap = fd; 412 pollFd(tap); 413} 414 415EtherTap::~EtherTap() 416{ 417 stopPolling(); 418 close(tap); 419 tap = -1; 420} 421 422void 423EtherTap::recvReal(int revent) 424{ 425 if (revent & POLLERR) 426 panic("Error polling for tap data.\n"); 427 428 if (!(revent & POLLIN)) 429 return; 430 431 ssize_t ret = read(tap, buffer, buflen); 432 if (ret < 0) 433 panic("Failed to read from tap device.\n"); 434 435 sendSimulated(buffer, ret); 436} 437 438bool 439EtherTap::sendReal(const void *data, size_t len) 440{ 441 if (write(tap, data, len) != len) 442 panic("Failed to write data to tap device.\n"); 443 return true; 444} 445 446EtherTap * 447EtherTapParams::create() 448{ 449 return new EtherTap(this); 450} 451 452#endif 453 |
|
380EtherTapStub * 381EtherTapStubParams::create() 382{ 383 return new EtherTapStub(this); 384} | 454EtherTapStub * 455EtherTapStubParams::create() 456{ 457 return new EtherTapStub(this); 458} |