It would be great if IOCTLs could be used to send arp requests... I need to obtain the MAC address of a workstation on the local subnet given it's IP (the way arp works). IOCTL appears to allow you to query the arp cache but not actually send arp request... Should I just form the headers myself and send a request in my program and listen for the reply?
EDIT:
I suppose no need for this thread anymore... I was able to get that part sorted by coming up with the following code:
void recv_arp(char * dst_ip, int sock_des){
unsigned char pdu[ETH_DATA_LEN];
struct ethhdr * ethptr;
struct arphdr * arpptr;
struct in_addr addr;
if(inet_pton(AF_INET, dst_ip, &addr) != 1)
prog_err("recv_arp", true);
while(true){
recvfrom(sock_des, pdu, ETH_DATA_LEN, 0, NULL, NULL);
ethptr = (struct ethhdr *)pdu;
arpptr = (struct arphdr *)(pdu + ETH_HLEN);
if(ethptr->h_proto == htons(ETHERTYPE_ARP) && arpptr->ar_op == htons(ARPOP_REPLY)){
printf("This is an ARP datagram\n");
if(!memcmp(arpptr->__ar_sip, &addr, PRO_HLEN)){
printf("This is our reply\n");
}
}
}
}
It works in listening for the reply and I can pull the MAC Address from it.