Re: Stumped on IPv6 ping in c language with PF_PACKET/SOCK_DGRAM
- From: Richard Kettlewell <rjk@xxxxxxxxxxxxxxx>
- Date: Wed, 02 Nov 2011 20:05:43 +0000
pdbuchan@xxxxxxxxx writes:
This is a question I posted on linuxquestions.org, but no takers so
far, so I thought I'd widen the audience to newsgroups.
I'm trying to write a c program on Ubuntu to send an ICMP echo request
over IPv6. I'm using 6to4/sit0 to do IPv6 as my ISP doesn't support it
yet. I'm monitoring sit0 with Wireshark.
I can use the ping6 which comes with Ubuntu and successfully ping6
ipv6.google.com and on Wireshark see the IPv6 echo request and reply
on sit0. Basde on this test, I believe I should be able to see the
traffic from my program by monitoring sit0 with Wireshark.
I've used PF_PACKET and SOCK_DGRAM because I don't want to have to
specify the MAC addresses. I do want to specify source and destination
IP addresses. I understand that SOCK_PACKET is "strongly" deprecated,
so I'm trying not to use it.
My program compiles and runs without errors,
I don't believe that. Or rather, I believe it doesn't report any
errors, but that's because your code does not check for them, rather
than because none occur.
but nothing shows up on Wireshark on sit0. In fact, if I ask Wireshark
to monitor all interfaces, I still see no IPv6 traffic.
You have at least two bugs:
(i) The destination address for AF_PACKET needs to be a sockaddr_ll.
(ii) In various places you pass the size of a pointer rather than the
size of the object pointed to.
A few other remarks:
interface = (char *) malloc (10 * sizeof (char));
char (and unsigned char) always have size 1, by definition. There
is no point whatsoever in multiplying by sizeof(char).
malloc() returns "void *" which can be implicitly converted to a pointer
to any object type. Including the cast adds nothing and can actually
hide problems.
Moreover there is actually no point in most of the memory allocation
you're doing. For the strings, just use the string literal. For packet
assembly, the use of malloc() does get you alignment, though a union
could be used to achieve this too. It's really the pointless use of
malloc that has led you into (ii) above.
memset (payload, 0, sizeof (payload));
memset (interface, 0, 10);
memset (src, 0, 39);
memset (target, 0, 80);
These are pointless.
free (interface);
free (src);
free (target);
free (payload);
free (packet);
return (EXIT_SUCCESS);
There is no point calling free() just before exiting. The OS will clean
up for you.
--
http://www.greenend.org.uk/rjk/
.
- Follow-Ups:
- Re: Stumped on IPv6 ping in c language with PF_PACKET/SOCK_DGRAM
- From: Jorgen Grahn
- Re: Stumped on IPv6 ping in c language with PF_PACKET/SOCK_DGRAM
- From: pdbuchan
- Re: Stumped on IPv6 ping in c language with PF_PACKET/SOCK_DGRAM
- References:
- Stumped on IPv6 ping in c language with PF_PACKET/SOCK_DGRAM
- From: pdbuchan
- Stumped on IPv6 ping in c language with PF_PACKET/SOCK_DGRAM
- Prev by Date: Re: Re (2): ? Too many connections from your IP address ?
- Next by Date: Re: Real time IP flow monitor for Home network
- Previous by thread: Re: Stumped on IPv6 ping in c language with PF_PACKET/SOCK_DGRAM
- Next by thread: Re: Stumped on IPv6 ping in c language with PF_PACKET/SOCK_DGRAM
- Index(es):
Relevant Pages
|