[Winpcap-users] Getting a MAC Address
Guy Harris
guy at alum.mit.edu
Sun Jan 27 22:33:23 GMT 2008
:: [F]usion[S]tream :: -- Gmail wrote:
> I'm trying to send a UDP packet via IPv4 to an IP Address which is a
> router which port forwards to a computer.
Then the scenario I described fits your situation exactly.
If that router is on your local network segment, you can send directly
to it; you would have to send an ARP request to determine its MAC address.
If the router is *not* on your local network segment, you *can't* send
directly to it; you will have to find a router on your local network
segment that can either send the packet to the other router or send it
to yet another router that can....
> But if I don't enter the
> correct MAC address of the target device (winpcap apaprently needs you
> to input the mac address manually),
libpcap/WinPcap's packet-sending API is deliberately low-level - you
construct a link-layer packet yourself and send it. That lets you send
packets with arbitrary source and destination addresses; there are
programs that might well want to do that.
libpcap/WinPcap don't impose any restrictions on where the address comes
from; you're not obliged to type it into your program. You could, for
example, construct an ARP packet (with a hardwired broadcast MAC
address) to request the MAC address, and, if you get a reply, copy the
MAC address from the reply to the destination address of packets you send.
libnet:
http://www.packetfactory.net/libnet/
might provide a higher-level API, which might make it easier to send
packets.
However, it still might not handle routing; you might have to figure out
how to get routing information from the OS on which you're writing your
application in order to figure out how to get the packet to its ultimate
destination.
On the other hand, unless you have a compelling reason to use
libpcap/WinPcap to send the packet, rather than just using a UDP socket,
I'd suggest letting Windows' networking stack worry about routing and
ARP, and just use WinSock as your API.
More information about the Winpcap-users
mailing list