What is the difference between sending IP packets (from user space) to a tun device and using a raw socket?
In order to tunnel IP packets through user space. Why should I use one method over another?
raw socket:
s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
send(s, ip_pkt, len, 0);
tun device:
struct ifreq ifr;
fd = open("/dev/net/tun", O_RDWR);
ifr.ifr_flags = IFF_TUN;
ioctl(fd, TUNSETIFF, (void *) &ifr)
send(s, ip_pkt, len, 0);
source
share