summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <cfchris6@ts2server.com>2010-06-15 11:52:34 (GMT)
committerChristian Franke <cfchris6@ts2server.com>2010-06-15 11:52:34 (GMT)
commit27155336554df1161ce705f753b0505111dc9553 (patch)
tree41e0d11ed8ed593ac4d67165fdea1496746abee0
parentf697e468503e70756475985333fd10a425cadf71 (diff)
tagged some code as debugging only
-rw-r--r--arpd.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/arpd.c b/arpd.c
index 55b041d..4495213 100644
--- a/arpd.c
+++ b/arpd.c
@@ -23,6 +23,16 @@
#define IP_ALEN 4
+#ifndef DEBUG
+#define DEBUG 0
+#endif
+
+#if DEBUG
+#define debug_printf(a) printf(a)
+#else
+#define debug_printf(a)
+#endif
+
union ether_arp_ip {
unsigned char raw[32768];
struct __attribute__((packed)) {
@@ -54,7 +64,6 @@ union ether_arp_ip {
#define hdr_arp_tha hdr.arp.ar_tha
#define hdr_arp_tpa hdr.arp.ar_tpa
-
static int arp_socket = 0;
static char* ifname = NULL;
static unsigned ifindex = 0;
@@ -64,7 +73,9 @@ static int addr_count = 0;
static void open_socket();
static void get_hwaddr();
+#if DEBUG
static void print_hwaddr(const char*, const uint8_t*, uint8_t);
+#endif
static void main_loop();
int main(int,char**);
@@ -122,6 +133,7 @@ static void get_hwaddr()
memcpy(ifaddr, request.ifr_hwaddr.sa_data, ETH_ALEN);
}
+#if DEBUG
static void print_hwaddr(const char*prompt,
const uint8_t*buffer,
uint8_t size)
@@ -132,6 +144,7 @@ static void print_hwaddr(const char*prompt,
}
printf("\n");
}
+#endif
static void main_loop()
{
@@ -178,13 +191,13 @@ static void main_loop()
if (!found)
continue;
- fprintf(stderr, "Received ARP request.\n");
-
+ debug_printf("Received ARP request.\n");
+#if DEBUG
print_hwaddr("Src hw-addr is", recvbuffer.hdr_arp_sha, ETH_ALEN);
print_hwaddr("Src protocol addr is",recvbuffer.hdr_arp_spa, IP_ALEN);
print_hwaddr("Dest hw-addr is", recvbuffer.hdr_arp_tha, ETH_ALEN);
print_hwaddr("Dest protocol addr is",recvbuffer.hdr_arp_tpa,IP_ALEN);
-
+#endif
memcpy(sendbuffer.hdr_eth_dhost, recvbuffer.hdr_eth_shost, ETH_ALEN);
memcpy(sendbuffer.hdr_eth_shost, ifaddr, ETH_ALEN);
sendbuffer.hdr_eth_type = htons(ETHERTYPE_ARP);
@@ -207,6 +220,7 @@ static void main_loop()
int main(int argc, char **argv)
{
+ debug_printf("Built with debug code.\n");
if (argc < 3) {
fprintf(stderr, "Usage: %s <ifname> <ip> [...]\n", argv[0]);
exit(EXIT_FAILURE);
@@ -224,15 +238,18 @@ int main(int argc, char **argv)
}
}
- fprintf(stderr, "Opening socket... ");
+ debug_printf("Opening socket... ");
open_socket();
- fprintf(stderr, "got it.\n");
- fprintf(stderr, "Getting hardware address... ");
+ debug_printf("done.\n");
+
+ debug_printf("Getting hardware_address...");
get_hwaddr();
- fprintf(stderr, "got it.\n");
- print_hwaddr("Hardware Address is", ifaddr, ETH_ALEN);
- fprintf(stderr, "\n");
+ debug_printf("done.\n");
+#if DEBUG
+ print_hwaddr("It is", ifaddr, ETH_ALEN);
+#endif
+ printf("Everything seems to be in order. Starting main loop.\n");
main_loop();
close(arp_socket);