diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/b-scan/tmp/src/arpg.c | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/b-scan/tmp/src/arpg.c')
| -rw-r--r-- | other/b-scan/tmp/src/arpg.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/other/b-scan/tmp/src/arpg.c b/other/b-scan/tmp/src/arpg.c new file mode 100644 index 0000000..0c8a620 --- /dev/null +++ b/other/b-scan/tmp/src/arpg.c | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | /* | ||
| 2 | * bscan arp routine | ||
| 3 | */ | ||
| 4 | #include <bscan/arpg.h> | ||
| 5 | #include <bscan/snarf.h> | ||
| 6 | #include <libnet.h> | ||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 | void | ||
| 11 | prepare_libnet (struct _libnet *lnet) | ||
| 12 | { | ||
| 13 | |||
| 14 | if (lnet->device == NULL) | ||
| 15 | { | ||
| 16 | struct sockaddr_in sin; | ||
| 17 | if (libnet_select_device (&sin, &lnet->device, lnet->err_buf) == -1) | ||
| 18 | libnet_error (LIBNET_ERR_FATAL, | ||
| 19 | "libnet_select_device failed: %s\n", lnet->err_buf); | ||
| 20 | } | ||
| 21 | |||
| 22 | if ( | ||
| 23 | (lnet->network = | ||
| 24 | libnet_open_link_interface (lnet->device, lnet->err_buf)) == NULL) | ||
| 25 | libnet_error (LIBNET_ERR_FATAL, | ||
| 26 | "libnet_open_link_interface '%s': %s\n", lnet->device, | ||
| 27 | lnet->err_buf); | ||
| 28 | |||
| 29 | |||
| 30 | lnet->packet_size = 60; /* min ethernet frame length -4 CRC */ | ||
| 31 | if (libnet_init_packet (lnet->packet_size, &lnet->packet) == -1) | ||
| 32 | libnet_error (LIBNET_ERR_FATAL, "libnet_init_packet failed\n"); | ||
| 33 | |||
| 34 | } | ||
| 35 | |||
| 36 | /* | ||
| 37 | * play arp-god: sends out arp-reply | ||
| 38 | * return: same as libnet_write_link_layer | ||
| 39 | * -1 on failure or bytes written | ||
| 40 | */ | ||
| 41 | int | ||
| 42 | play_arpg (struct _libnet *lnet, u_char spf_sip[4], u_char spf_smac[6], | ||
| 43 | u_char spf_dip[4], u_char spf_dmac[6]) | ||
| 44 | { | ||
| 45 | int c; | ||
| 46 | |||
| 47 | #ifdef DEBUG | ||
| 48 | printf ("sending out arp\n"); | ||
| 49 | #endif | ||
| 50 | libnet_build_ethernet (spf_dmac, | ||
| 51 | spf_smac, ETHERTYPE_ARP, NULL, 0, lnet->packet); | ||
| 52 | |||
| 53 | libnet_build_arp (ARPHRD_ETHER, ETHERTYPE_IP, /* arp for which protocol ? */ | ||
| 54 | 6, /* hardware addr. length */ | ||
| 55 | 4, /* protocol addr. length */ | ||
| 56 | ARPOP_REPLY, spf_smac, spf_sip, spf_dmac, spf_dip, NULL, /* packet payload */ | ||
| 57 | 0, /* length of payload */ | ||
| 58 | lnet->packet + LIBNET_ETH_H); | ||
| 59 | |||
| 60 | c = | ||
| 61 | libnet_write_link_layer (lnet->network, lnet->device, lnet->packet, | ||
| 62 | lnet->packet_size); | ||
| 63 | if (c < lnet->packet_size) | ||
| 64 | { | ||
| 65 | libnet_error (LN_ERR_WARNING, | ||
| 66 | "libnet_write_link_layer only wrote %d bytes\n", c); | ||
| 67 | } | ||
| 68 | #ifdef DEBUG | ||
| 69 | else | ||
| 70 | { | ||
| 71 | printf ("construction and injection completed, wrote all %d bytes\n", | ||
| 72 | c); | ||
| 73 | } | ||
| 74 | #endif | ||
| 75 | |||
| 76 | return (c); | ||
| 77 | } | ||
| 78 | |||
