private void SendICMPNeighborSolicitation(IPAddress ipaQuery, IPAddress ipaSource) { if (ipaQuery.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6) { throw new InvalidOperationException("Cannot send an ICMP Neighbor Solicitation for a non IPv6 address."); } ICMPv6Frame icmpFrame = new ICMPv6Frame(); icmpFrame.ICMPv6Type = ICMPv6Type.NeighborSolicitation; icmpFrame.ICMPCode = 0; NeighborSolicitation icmpDiscoveryMessage = new NeighborSolicitation(); icmpDiscoveryMessage.TargetAddress = ipaQuery; NeighborDiscoveryOption icmpDiscoveryOption = new NeighborDiscoveryOption(); icmpDiscoveryOption.OptionType = ICMP.V6.NeighborDiscoveryOptionType.SourceLinkLayerAddress; icmpDiscoveryOption.OptionData = this.PrimaryMACAddress.AddressBytes; IPv6Frame ipFrame = new IPv6Frame(); ipFrame.SourceAddress = ipaSource; ipFrame.DestinationAddress = IPAddressAnalysis.GetSolicitedNodeMulticastAddress(ipaQuery); ipFrame.NextHeader = IPProtocol.IPv6_ICMP; EthernetFrame ethFrame = new EthernetFrame(); ethFrame.Destination = MACAddress.MulticastFromIPv6Address(ipaQuery); ethFrame.Source = PrimaryMACAddress; ethFrame.EtherType = EtherType.IPv6; ethFrame.EncapsulatedFrame = ipFrame; ipFrame.EncapsulatedFrame = icmpFrame; icmpFrame.EncapsulatedFrame = icmpDiscoveryMessage; icmpDiscoveryMessage.EncapsulatedFrame = icmpDiscoveryOption; icmpFrame.Checksum = icmpFrame.CalculateChecksum(ipFrame.GetPseudoHeader()); this.Send(ethFrame); }
private void SendICMPNeighborAdvertisment(IPAddress ipaDestination, IPAddress ipaSource) { if (ipaDestination.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6) { throw new InvalidOperationException("Cannot send an ICMP Neighbor Advertisement for a non IPv6 address."); } ICMPv6Frame icmpFrame = new ICMPv6Frame(); icmpFrame.ICMPv6Type = ICMPv6Type.NeighborAdvertisement; icmpFrame.ICMPCode = 0; NeighborAdvertisment icmpDiscoveryMessage = new NeighborAdvertisment(); icmpDiscoveryMessage.SolicitedFlag = true; icmpDiscoveryMessage.OverrideFlag = true; icmpDiscoveryMessage.TargetAddress = ipaSource; NeighborDiscoveryOption icmpDiscoveryOption = new NeighborDiscoveryOption(); icmpDiscoveryOption.OptionType = ICMP.V6.NeighborDiscoveryOptionType.TargetLinkLayerAddress; icmpDiscoveryOption.OptionData = this.PrimaryMACAddress.AddressBytes; IPv6Frame ipFrame = new IPv6Frame(); ipFrame.SourceAddress = ipaSource; ipFrame.DestinationAddress = ipaDestination; ipFrame.NextHeader = IPProtocol.IPv6_ICMP; ipFrame.EncapsulatedFrame = icmpFrame; icmpFrame.EncapsulatedFrame = icmpDiscoveryMessage; icmpDiscoveryMessage.EncapsulatedFrame = icmpDiscoveryOption; icmpFrame.Checksum = icmpFrame.CalculateChecksum(ipFrame.GetPseudoHeader()); this.Send(ipFrame, ipaDestination); }