Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build TunEndPoint as part of inet #29

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/inet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ CPP_Files = \
InetUtils.cpp \
IPAddress.cpp \
InetInterface.cpp \
RawEndPoint.cpp
RawEndPoint.cpp \
TunEndPoint.cpp

libnet.a: $(CPP_Objects)
ar rvs $@ $^
Expand Down
9 changes: 9 additions & 0 deletions src/inet/TunEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <stdio.h>

#include <core/CHIPEncoding.h>
#include <core/CHIPTunnelConfig.h>
#include <support/CodeUtils.h>

#include "arpa-inet-compatibility.h"
Expand Down Expand Up @@ -671,17 +672,21 @@ INET_ERROR TunEndPoint::TunDevOpen (const char *intfName)

memset(&ifr, 0, sizeof(ifr));

#if HAVE_LINUX_IF_TUN_H
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
#endif

if (*intfName)
{
strncpy(ifr.ifr_name, intfName, sizeof(ifr.ifr_name) - 1);
}

#if HAVE_LINUX_IF_TUN_H
if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0)
{
ExitNow(ret = chip::System::MapErrorPOSIX(errno));
}
#endif

//Verify name
memset(&ifr, 0, sizeof(ifr));
Expand Down Expand Up @@ -724,7 +729,11 @@ void TunEndPoint::TunDevClose (void)
int TunEndPoint::TunGetInterface (int fd,
struct ::ifreq *ifr)
{
#if HAVE_LINUX_IF_TUN_H
return ioctl(fd, TUNGETIFF, (void*)ifr);
#else
return -1;
#endif
}

/* Read packets from TUN device in Linux */
Expand Down