In Erlang, it is very simple to send UDP
packet, that is to use gen_udp:open()
to create a socket, then use gen_udp:send()
to send out the data.
However, by default, the Linux TCP/IP
stack will set the don't fragment (DF)flag in IP header if the size of IP packet doesn't exceed the MTU size. If the size exceeds the MTU
size, the UDP
packet will be fragmented.
Is there some way to not set DF flag for UDP
packet only?
I know in C language, the following code could be used to clear the DF flag. But i couldn't find a way in Erlang.
int optval=0;
if(-1 == setsockopt(sockfd,IPPROTO_IP,IP_MTU_DISCOVER,&optval,sizeof(optval))) {
printf("Error: setsockopt %d\n",errno);
exit(1);
}
Thanks
i found the solution after i posted this question :-(...:-)...
The solution is to set socket raw option by using
inet:setopts()
like what is done in C language, but the difference is that you need to know the definition ofIPPROTO_IP
andIP_MTU_DISCOVER
.The value of
IPPROTO_IP
is 0, defined in netinet/in.h The value ofIP_MTU_DISCOVER
is 10, defined in linux/in.hBelow is example. inet:setopts(Socket,[{raw,0,10,<<0:32/native>>}]).
I have tested it using small program, it is working.
You can find detail help for
inet:setopts
on erlang man page: http://www.erlang.org/doc/man/inet.htmlThanks.