• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ARP cache entry for router
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ARP cache entry for router


  • Subject: Re: ARP cache entry for router
  • From: Ryan McGann <email@hidden>
  • Date: Thu, 6 Nov 2003 23:42:53 -0800

Should I go to the trouble of crafting an ARP packet and waiting for the
reply, or is it a "99% safe" assumption that the ARP entry will exist
(assuming the router information is correct in the user's settings)?

Do you really need to send an ARP packet to get the router entered into the
the ARP table? Might it be sufficient to attempt to send an IP packet to
the router, with the result that the OS adds the router to the ARP table as
part of addressing the IP packet?
That's actually how I've implemented it. I was just hoping it would be unecessary.

I would think waiting for a reply is unnecessary.
Waiting is unecessary, though I had to put an arbitrary sleep in there to make sure that the kernel had enough time to get the packet and cache the response.

I asked because doing the same thing for IPv6 isn't quite as simple, and I was hoping that maybe it would be unecessary. I already have the IPv4 ARP code done, but the neighbor discovery code for IPv6 doesn't seem to work....so my next question is:

I'm trying to send a router solicitation packet for IPv6 router discovery, in case the router isn't in the neighbor cache. However, it seems that my sendto call always returns -1 with errno set to 22 (illegal parameter). Here's the code below. Does anybody see anything wrong off the top of their head? I'm pretty new to IPv6, so I'm probably just missing something obvious.

sockaddr_in6 theAllRoutersSockAddr = { sizeof( theAllRoutersSockAddr ), AF_INET6, 0, 0, IN6ADDR_LINKLOCAL_ALLROUTERS_INIT, 0 };
iovec iov[ 2 ];
msghdr smsghdr;
icmp6_hdr *theICMP6Header;
bool success;
int result;
int theSocket;
int theSocketOpt;
int theTotalLength;
char thePacketBuffer[ 1024 ];

theSocket = -1;
success = false;
bzero( thePacketBuffer, sizeof( thePacketBuffer ) );

// Open an IPv6 raw socket we can use to send the NDP packet on
theSocket = socket( AF_INET6, SOCK_RAW, IPPROTO_ICMPV6 );

// Start by making an ICMPv6 header
bzero( thePacketBuffer, sizeof( thePacketBuffer ) );
theICMP6Header = (icmp6_hdr *)thePacketBuffer;
theICMP6Header->icmp6_type = 133; // Router Solicit type
theICMP6Header->icmp6_code = 0;
theICMP6Header->icmp6_cksum = 0;
theICMP6Header->icmp6_id = ntohs( getpid() );
theICMP6Header->icmp6_seq = ntohs( getpid() );

// Set hop limit to 255, and let the kernel compute and set the
// checksum. The ICMPv6 checksum field is located at offset 2 from
// the start of the ICMPv6 header (i.e. the third and forth bytes).
theSocketOpt = 2;
result = setsockopt( theSocket, IPPROTO_IPV6, IPV6_CHECKSUM, &theSocketOpt, sizeof( theSocketOpt ) );

theSocketOpt = 255;
result = setsockopt( theSocket, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &theSocketOpt, sizeof( theSocketOpt ) );

smsghdr.msg_name = (caddr_t)&theAllRoutersSockAddr;
smsghdr.msg_namelen = sizeof( theAllRoutersSockAddr );
memset(&iov, 0, sizeof(iov));
iov[0].iov_base = (caddr_t)thePacketBuffer;
iov[0].iov_len = sizeof( icmp6_hdr );
smsghdr.msg_iov = iov;
smsghdr.msg_iovlen = 1;

result = sendmsg( theSocket, &smsghdr, 0 );
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: ARP cache entry for router
      • From: Ryan McGann <email@hidden>
  • Prev by Date: Re: Proxy Tunneling (via the HTTP CONNECT method)
  • Next by Date: Re: OpenTransport behaviour under X
  • Previous by thread: Re: ARP cache entry for router
  • Next by thread: Re: ARP cache entry for router
  • Index(es):
    • Date
    • Thread