broadcast packets sent from tap interface not received
Solved it by using proper checksum and proper byte order for tot_len for ip header
iph->tot_len = (htons)sizeof (struct iphdr) + sizeof (struct udphdr) + strlen(data);
iph->id = htons (54321); //Id of this packet
iph->check = htons(csum ((unsigned short *) datagram,sizeof(struct ip_hdr)));
**where csum is a common function to calculate checksum.
from a different machine packet was received because kernel's network stack was recalculating iph->tot_len and the ip checksum. so the packet was properly formed.
with my tun interface after correcting the checksum and byteorder of tot_len packet was received by the application.
Tap device in linux not properly passing ARP/IP packets?
I regret that this was unrelated to the way tap/tun devices work in Linux. In fact, this mechanism will work.
The issue was in that I was using "send" and "recv" to talk to the raw tap device. Wireshark can't tell the difference, but the Linux OS will refuse to use the data coming from the socket.
Use this guy's example: http://www.cis.syr.edu/~wedu/seed/Labs/VPN/files/simpletun.c
iOS Network Extension error creating TUN/TAP interface SIOCGIFMTU failed: device not configured
Okay I managed to solve this on my own. I created a Packet Tunnel Network Extension and in my PacketTunnelProvider class came the problems. It did not crash so setting up the debugger in that class was not worth it. I ran my target and started my app and set several NSLogs in the functions so I could see in the device's console what was happening. My problem was that I tried to set a nil value in a dictionary for a key thus terminating the extension. That crash message can easily be seen in the console.
The problem was when extending PacketTunnelProvider
with OpenVPNAdapterDelegate
in the function to configure the tunnel
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings?, completionHandler: @escaping (OpenVPNAdapterPacketFlow?) -> Void) {
networkSettings?.dnsSettings?.matchDomains = [""];
}
Previously I had networkSettings.dnsSettings?.matchDomains = [""];
so networkSettings
was unwrapped and it was nil
making it crash the extension and the tunnel not being able to get connected.
How to connect a tap interface to the internet?
The tap device is only a virtual ethernet interface - what you send on it, you can read it back on a device file (/dev/tap
), and what you write into this device, you get as incoming packet on tap0
.
What you can do:
You can do this by netlink or raw sockets. Essentially, it is a special socket type, you can send and receive raw ethernet packets on it.
You can bridge
tap0
andwlan0
into abr0
bridge with thebrctl
command. Wifi and ethernet interfaces can not be bridged together (they are different on the ethernet level, a 802.11 packet is meaningless on 802.3 and vice versa).
Probably you can not create a well-working tcp implementation below a hundred kB of C code. It is because tcp is only simple on the user level.
Related Topics
Perf: Strange Relation Between Software Events
How to Make Sudo Save The Password
Possible to Assign a New Ip Address on Every Http Request
How to Use 'Catdoc' to Display Dock File Encoded in Utf-8
How to Create a File of Size More Than 2Gb in Linux/Unix
How to Compare The Size of Two Directories
Rename Multiple Files - Linux/Ubuntu
A Wrong Size of "Len" Calculated by $ - Symbol with Fasm Equ
Search Ip from a Text File in .Csv Log File, If Found Add New Column Next to It
Ssh - Help Understanding Proxy Command
How to Set Just Year with Linux Date Command
Why This Shell Won't Work If It's Called from Rc.Local But Ssh
Implementation of Function Execve (Unistd.H)
Copy Failed: Stat /Var/Lib/Docker/Tmp/Docker-Builder700869788/Private: No Such File or Directory