[erlang-questions] UDP Headers
Wed Jul 9 00:25:49 CEST 2014
Thank you for your help, Michael. I’ll give these a test in the morning and will let you know.
On 8 Jul 2014, at 23:20, Michael Santos <michael.santos@REDACTED> wrote:
> On Tue, Jul 08, 2014 at 10:53:18PM +0100, Lee Sylvester wrote:
>> Hi Michael,
>> Thanks for responding. I was actually just looking through your repositories to see if you had written something to work with this.
>> What I’d like to do is to be able to set the DF or TTL flags. What would you suggest for such things?
> Raw sockets would be overkill for this. Have a look at the raw option
> to inet:setopts/2. There's an example in the docs for inet of setting
> TCP_LINGER2 on a TCP socket:
> The values will depend on the OS. So for setting the TTL, on linux/x86_64,
> maybe something like:
> setsockopt(send_socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
> % IPPROTO_IP = 0
> % IP_TTL = 2
> % TTL = 64
> DF is interesting. There's a good discussion about the DF bit here:
> So on a linux system, maybe this would work:
> int val = IP_PMTUDISC_DO;
> setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val));
> % IPPROTO = 0
> % IP_MTU_DISCOVER = 10
> % IP_PMTUDISC_DO = 2
> I haven't tested if these work so let us know if you run into problems
> and I'll try to come up with some working code!
>>> On Tue, Jul 08, 2014 at 07:04:12PM +0100, Lee Sylvester wrote:
>>>> Hey guys,
>>>> 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?
>>> It depends which header needs to be changed:
>>> * for UDP (source/destination port, length, checksum), the simplest
>>> method is to receive and resend the packet
>>> * for IPv4/IPv6, some of the headers may be able to be influenced by setting
>>> socket options. For example, by using inet:setopts/2 or by using
>>> setsockopt(2) from an NIF.
>>> * otherwise, there's the raw socket interface.
>>> For IPv4, the socket can be opened in raw mode and passed back into
>>> For IPv6 headers, if the headers can be changed, you generally have to
>>> use sendmsg(2)/recvmsg(2) which means using a port or an NIF.
>>> * for ethernet, it will depend on the OS: PF_PACKET for linux, BPF for
>>> the BSDs
>>> * another option is routing the packets through a tun/tap device and
>>> having some erlang code re-write the headers
>>> erlang-questions mailing list
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions