Setting IP TTL for a UDP (mdns) - setsockopt equiv?

I am sending out MDNS packages and those should ideally have an ip.ttl=1. On linux I would

int ttl = 1;
setsockopt(s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));

but spark_wiring_udp does not seem to expose anything to let me do that. Neither can I find suitable api in the socket_hal.c for the photon.

Any ideas?

Build and transmit the mdns packet yourself. We in the embedded world rarely have the luxury of libraries that do all the things, you just need to build the parts that you need.


https://tools.ietf.org/html/rfc6762#section-18

I do build the mdns packet myself, but I don’t build the IP headers myself, since then I would need some lowlevel access sending them.

Maybe I’m mistaken, but doesn’t the mdns packet go into the UDP payload?
( EDIT: and the TTL is part of the mdns packet ? )

That is why I wrote IP TTL. I know it is confusing. The TTL for the mdns service announcement is part of the udp packet and I can control that. The IP TTL is the number of hops for the packet. Since mdns packets should not be routed one needs to set the ttl in the ip header to 1.

Ah, that might get tricky then. The lower level network stuff is part of the WiFi stack that’s not open source at the moment. If you feel like making that deep dive, look into WICED.

1 Like

See this thread for a working-on-the-older-Spark-Core mDNS.

You don't have easy access to either the TTL (hop-count) or the ICMP Time Exceeded reply messages in this stack.