Hi,
that function should work, and if it throws errors in checking the address either you found a bug, or you opened the wrong socket type (e.g., a IPv4RawSocket instead of an Ipv6RawSocket).
However, that function is not very used. It purpose is to send a packet with an arbitrary payload, in case of headers it's better to sue another approach - purely because in this way you can easily print the headers.
If you look at Ping6::Send, the operations sequence is:
1) Decide the output address and interface - this is necessary in case you want to ping another host using a link-local address and you have more than one interface.
2) Build the packet payload - in this case it's an ICMP packet, so we just use an Icmpv6Header.
3) Perform a magical trick - add another header between the ICMP header and the IP header.
4) Send the packet.
You're interested into points 3 and 4.
Also, note that the socket is an Ipv6RawSocket. It will add JUST the IP header, and nothing more. Moreover, you have to set manually the IP "Protocol" field, i.e., the next header type.
Point 3: why it's a magical trick.
Normally you'd send a packet to the socket and it will add the header to the packet you're sending. Since it's a Ipv6RawSocket, it will set the Protocol field to the value you have set when you opened the socket.
In ping.cc, the "protocol" is set at line 113:
m_socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_ICMPV6));
because we know that we'r going to send an ICMP later on.
If you want to add a Loose Routing Extension header, this is not anymore true. You need to change the Protocol. Line 222:
moreover, you build a new routing header (the lines above the 222) and you add them to the packet.
At this point, the packet will contain your ICMP header and the Extension header routing header. The socket will add the IP header and the trick is done.
Point 4 is "simply" sending a packet to a destination, line 225:
m_socket->SendTo (p, 0, Inet6SocketAddress (m_peerAddress, 0));
Hope this helps,
T.
PS. sorry if I didn't point out before... but there's a big thing to consider: if you're writing a kind of hop-by-hop extension, you need to consider the presence of *others* HbH extensions....
Basically what you want to define isn't an extension, it's an option.
The files you need (then) are:
src/internet/model/ipv6-option.cc
src/internet/model/ipv6-option.h
src/internet/model/ipv6-option-demux.cc
src/internet/model/ipv6-option-demux.h
src/internet/model/ipv6-option-header.cc
src/internet/model/ipv6-option-header.h
The logic is the very same. When an HbH extension is found, its options are processed.
Sadly, there's no way to easily *create* an HbH extension with its options. Basically this part of code is to be done.
The nice part is that it's something I'd very much like to include in ns-3, so if anyone has proposals, I'll be happy to review 'em.
Cheers,
T.