I have a small problem with my RAW-Socket. I have to capture packets in a network to modify them. For this I have to add special data, like timestamps. Everything works fine, but I have a problem witht the MTU (Linux).
If some of the application of the upper layers generates packets close to the MTU, I can not add my data. So I decide to downsize the MTU of the systems. So i got smaller packets and it is possible to ad my data. But when I try to sendout my packets with my RAW-Socket, it is not working.
I found (by google, in older Stackoverflow threads and in the linux manpages) that the option IP_MTU_DISCOVER could help. But when I use it with setsockopt, nothing changes.
if ((s = socket(AF_PACKET, SOCK_RAW, ETH_P_ALL)) < 0) {
printf("Error: could not open socket\n");
return -1;
}
char socket_mtu = IP_PMTUDISC_DONT;
setsockopt(s,IPPROTO_IP,IP_MTU_DISCOVER,socket_mtu, 1);
Maybe it is important. The downsizing of the MTU was done, because when I add my own data, the resulting packet would not be greater then 1500 + ETH-Header. My problem is, to make Raw-Sockets ignore the local MTU of my Linux-System.
- Is IP_MTU_DISCOVER the right way to ignore the value set in MTU?
- IS IP_MTU_DISCOVER realy usable with my RAW-SOCKET?
- Are there any other ways to decrement the segement size of the protocols on layer 3 and higher?
I read, that sendto() returns EMSGSIZE (=90) when the size is too big. So I have done the following test.
int k = sendto(s, frame.buffer, frame_len, 0,
(struct sockaddr*)&saddrll, sizeof(saddrll));
printf("K:%i\n", k);
After calling sendto() "k" contains "-1". But if it depends on the packet size, shouldn't it be "90"??
When I set the size of the packet I like to send smaller then the MTU, it works fine.... A little bit strange.
Any help would be nice :-)
Kind regards, Andreas