summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <cfchris6@ts2server.com>2010-06-15 11:26:58 (GMT)
committerChristian Franke <cfchris6@ts2server.com>2010-06-15 11:26:58 (GMT)
commit724a8a216f79b281fb8c7d18f95721429924279d (patch)
tree4b9e794148c9b3a9313f957dc38920c10634dd8e
parent4acc4620ad3eeeb3312c1b52f23748134894f69e (diff)
Only answer specific addresses
-rw-r--r--arpd.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/arpd.c b/arpd.c
index b6ad7f6..3da2e2a 100644
--- a/arpd.c
+++ b/arpd.c
@@ -59,6 +59,9 @@ static int arp_socket = 0;
static char* ifname = NULL;
static unsigned ifindex = 0;
static uint8_t ifaddr[ETH_ALEN];
+static struct in_addr *addresses = NULL;
+static int addr_count = 0;
+
static void open_socket();
static void get_hwaddr();
static void print_hwaddr(const char*, const uint8_t*, uint8_t);
@@ -136,6 +139,7 @@ static void main_loop()
socklen_t lla_size;
union ether_arp_ip recvbuffer,sendbuffer;
ssize_t red;
+ short found;
while (1) {
memset(&lla, 0, sizeof(lla));
@@ -168,6 +172,17 @@ static void main_loop()
continue;
}
+ found = 0;
+ for (int i = 0; i < addr_count; i++) {
+ if (!memcmp(recvbuffer.hdr_arp_tpa, &(addresses[i].s_addr),
+ IP_ALEN)) {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ continue;
+
fprintf(stderr, "Received ARP request.\n");
print_hwaddr("Src hw-addr is", recvbuffer.hdr_arp_sha, ETH_ALEN);
@@ -189,9 +204,7 @@ static void main_loop()
memcpy(sendbuffer.hdr_arp_tpa, recvbuffer.hdr_arp_spa, IP_ALEN);
if (send(arp_socket, sendbuffer.raw, sizeof(sendbuffer.hdr), 0)
- == sizeof(sendbuffer.hdr)) {
- fprintf(stderr, "Answer sent successfully.\n");
- } else {
+ != sizeof(sendbuffer.hdr)) {
perror("Error sending the answer");
}
}
@@ -199,12 +212,23 @@ static void main_loop()
int main(int argc, char **argv)
{
- if (argc != 2) {
- fprintf(stderr, "Usage: %s <ifname>\n", argv[0]);
+ if (argc < 3) {
+ fprintf(stderr, "Usage: %s <ifname> <ip> [...]\n", argv[0]);
exit(EXIT_FAILURE);
}
ifname = argv[1];
+ addr_count = argc - 2;
+ addresses = malloc(addr_count*sizeof(struct in_addr));
+ for (int i = 0; i < addr_count; i++) {
+ if (inet_pton(AF_INET, argv[2 + i], &addresses[i]) < 1) {
+ fprintf(stderr,
+ "An error occured while parsing the IP `%s'.\n",
+ argv[2 + i]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
fprintf(stderr, "Opening socket... ");
open_socket();
fprintf(stderr, "got it.\n");