1
0

TAPWrapper_root_test.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "interface/tuntap/TUNInterface.h"
  16. #include "memory/Allocator.h"
  17. #include "memory/MallocAllocator.h"
  18. #include "util/log/Log.h"
  19. #include "util/log/FileWriterLog.h"
  20. #include "util/platform/netdev/NetDev.h"
  21. #include "test/RootTest.h"
  22. #include "interface/tuntap/test/TUNTools.h"
  23. #include "interface/tuntap/TAPWrapper.h"
  24. #include "interface/tuntap/NDPServer.h"
  25. int main(int argc, char** argv)
  26. {
  27. struct Allocator* alloc = MallocAllocator_new(1<<20);
  28. struct EventBase* base = EventBase_new(alloc);
  29. struct Log* log = FileWriterLog_new(stdout, alloc);
  30. struct Sockaddr* addrA = Sockaddr_fromBytes(TUNTools_testIP6AddrA, Sockaddr_AF_INET6, alloc);
  31. struct Sockaddr* addrB = Sockaddr_fromBytes(TUNTools_testIP6AddrB, Sockaddr_AF_INET6, alloc);
  32. char assignedIfName[TUNInterface_IFNAMSIZ];
  33. struct Iface* tap = TUNInterface_new(NULL, assignedIfName, 1, base, log, NULL, alloc);
  34. struct TAPWrapper* tapWrapper = TAPWrapper_new(tap, log, alloc);
  35. // Now setup the NDP server so the tun will work correctly.
  36. struct NDPServer* ndp = NDPServer_new(&tapWrapper->internal, log, TAPWrapper_LOCAL_MAC, alloc);
  37. ndp->advertisePrefix[0] = 0xfd;
  38. ndp->prefixLen = 8;
  39. NetDev_addAddress(assignedIfName, addrA, 126, log, NULL);
  40. TUNTools_echoTest(addrA, addrB, TUNTools_genericIP6Echo, &ndp->internal, base, log, alloc);
  41. Allocator_free(alloc);
  42. return 0;
  43. }