848d8761   
   From: philip+usenet@paeps.cx   
      
   SpreadTooThin wrote:   
   > I think this is like an arp request...   
      
   Yes. So it will only work for IPs on your local network.   
      
   > What I'm looking for is unix source code of a method to get the mac address   
   > of a computer given its IP / host name.   
      
   Depending on the Unix you're using, you may need to fight the kernel to be   
   able to do this. It may be tempting to try using a raw socket on the   
   interface with an address on the same network as the one you're interested in,   
   but you may find that the kernel will eat the answers instead of sending them   
   up the socket.   
      
   First you will need to find an interface on the same network as the IP you are   
   interested in. The SIOCGIFCONF and SIOCGIFNETMASK ioctls are probably what   
   you want. Example code can probably be found in any old arp implementation.   
      
   On a BSDish system -- or another system which implements BPF -- the easiest   
   way to send your ARP requests and get the answers will probably be to use the   
   BPF.   
      
   Sending your request will be a simple matter of creating an Ethernet header   
   and sticking an ARP behind it. Take a look at struct ether_header and struct   
   ether_arp. You should just be able to write that to your BPF descriptor.   
      
   Getting the replies will be a bit more interesting. A filter like this should   
   catch them: (not tested)   
      
    struct bpf_insn insns[] = {   
    BPF_STMT(BPF_LD|BPF_H|BPF_ABS, 12),   
    BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, ETHERTYPE_ARP, 0, 3),   
    BPF_STMT(BPF_LD|BPF_H|BPF_ABS, 20),   
    BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, ARPOP_REPLY, 0, 1),   
    BPF_STMT(BPF_RET|BPF_K, sizeof(struct ether_arp) +   
    sizeof(struct ether_header)),   
    BPF_STMT(BPF_RET|BPF_K, 0),   
    };   
      
   Good luck. :-)   
      
    - Philip   
      
   --   
   Philip Paeps Please don't email any replies   
   philip@paeps.cx I follow the newsgroup.   
      
    Nanny could get a statue to cry on her shoulder and say what it really   
    thought about pigeons.   
    -- (Terry Pratchett, Maskerade)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|