<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Thank you for your help, Michael. I’ll give these a test in the morning and will let you know.<div><br></div><div>Regards,</div><div>Lee</div><div><br></div><div><br><div><div>On 8 Jul 2014, at 23:20, Michael Santos <<a href="mailto:michael.santos@gmail.com">michael.santos@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Tue, Jul 08, 2014 at 10:53:18PM +0100, Lee Sylvester wrote:<br><blockquote type="cite">Hi Michael,<br><br>Thanks for responding. I was actually just looking through your repositories to see if you had written something to work with this.<br><br>What I’d like to do is to be able to set the DF or TTL flags. What would you suggest for such things?<br></blockquote><br>Raw sockets would be overkill for this. Have a look at the raw option<br>to inet:setopts/2. There's an example in the docs for inet of setting<br>TCP_LINGER2 on a TCP socket:<br><br> inet:setopts(Sock,[{raw,6,8,<<30:32/native>>}])<br><br>The values will depend on the OS. So for setting the TTL, on linux/x86_64,<br>maybe something like:<br><br> setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));<br><br> % IPPROTO_IP = 0<br> % IP_TTL = 2<br> % TTL = 64<br> inet:setopts(Sock,[{raw,0,2,<<64:32/native>>}])<br><br>DF is interesting. There's a good discussion about the DF bit here:<br><br> <a href="http://stackoverflow.com/questions/973439/how-to-set-the-dont-fragment-df-flag-on-a-socket">http://stackoverflow.com/questions/973439/how-to-set-the-dont-fragment-df-flag-on-a-socket</a><br><br>So on a linux system, maybe this would work:<br><br> int val = IP_PMTUDISC_DO;<br> setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val));<br><br> % IPPROTO = 0<br> % IP_MTU_DISCOVER = 10<br> % IP_PMTUDISC_DO = 2<br> inet:setopts(Sock,[{raw,0,10,<<2:32/native>>}])<br><br>I haven't tested if these work so let us know if you run into problems<br>and I'll try to come up with some working code!<br><br><blockquote type="cite"><blockquote type="cite">On Tue, Jul 08, 2014 at 07:04:12PM +0100, Lee Sylvester wrote:<br><blockquote type="cite">Hey guys,<br><br>So, I’m using gen_udp for a server I’m building, but I really need to be able to update the headers of incoming packets. Does anyone know how I can do this with gen_udp without having to resort to using raw sockets?<br></blockquote><br>It depends which header needs to be changed:<br><br>* for UDP (source/destination port, length, checksum), the simplest<br>method is to receive and resend the packet<br><br>* for IPv4/IPv6, some of the headers may be able to be influenced by setting<br>socket options. For example, by using inet:setopts/2 or by using<br>setsockopt(2) from an NIF.<br><br>* otherwise, there's the raw socket interface.<br><br>For IPv4, the socket can be opened in raw mode and passed back into<br>gen_udp.<br><br>For IPv6 headers, if the headers can be changed, you generally have to<br>use sendmsg(2)/recvmsg(2) which means using a port or an NIF.<br><br>* for ethernet, it will depend on the OS: PF_PACKET for linux, BPF for<br>the BSDs<br><br>* another option is routing the packets through a tun/tap device and<br>having some erlang code re-write the headers<br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote><br></blockquote>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a></div></blockquote></div><br></div></body></html>