Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read packet by packet from linux tun/tap

I have connected to an existing Tap device using

fd = open(...)

Now i want to read from it packet by packet. if i use

read(fd,buffer,sizeof(buffer));

I wont read exactly 1 packet.

How can i read exactly 1 packet? Is there some kind of header that says the packet length or in the worst case i will have to parse the packet and figure the length myself?

like image 648
yonigo Avatar asked Aug 27 '13 09:08

yonigo


Video Answer


1 Answers

I was wrong about the way read() reads bytes from a tap device. It turns out when I use read() it reads exactly 1 frame, (or n bytes if n is smaller then frame size)

like image 159
yonigo Avatar answered Oct 06 '22 08:10

yonigo