checking bootp packet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <libusb.h> | |
#include <linux/ip.h> | |
#include <unistd.h> | |
#include <sys/stat.h> | |
#include "rndis.h" | |
#include "ether2.h" | |
#include "ipv4.h" | |
#include "udp.h" | |
#include "bootp.h" | |
#include "tftp.h" | |
#include "arp.h" | |
#include "utils.h" | |
int main(int UNUSED argc, const char UNUSED * argv[]) { | |
int actual; | |
int result; | |
int r; | |
ssize_t fullSize = sizeof(bootp_packet) + sizeof(udp_t) + | |
sizeof(struct iphdr) + sizeof(struct ethhdr) + | |
sizeof(rndis_hdr); | |
ssize_t rndisSize = sizeof(rndis_hdr); | |
ssize_t etherSize = sizeof(struct ethhdr); | |
ssize_t arpSize = sizeof(arp_hdr); | |
ssize_t ipSize = sizeof(struct iphdr); | |
ssize_t udpSize = sizeof(udp_t); | |
ssize_t bootpSize = sizeof(bootp_packet); | |
ssize_t tftpSize = sizeof(tftp_data); | |
unsigned char *data = (unsigned char*)calloc(1, 1000); | |
unsigned char *buffer = (unsigned char*)malloc(450 * | |
sizeof(unsigned char)); | |
FILE *send; | |
libusb_device **devs = NULL; | |
libusb_device_handle *dev_handle = NULL; | |
libusb_context *ctx = NULL; | |
r = libusb_init(&ctx); | |
if (r < 0) { | |
printf("Init error!\n"); | |
exit(1); | |
} | |
libusb_set_debug(ctx, 3); | |
while (dev_handle == NULL) { | |
r = libusb_get_device_list(ctx, &devs); | |
if (r < 0) { | |
printf("Cannot get device list.\n"); | |
} | |
dev_handle = libusb_open_device_with_vid_pid(ctx, | |
ROMVID, ROMPID); | |
libusb_free_device_list(devs, 1); | |
} | |
if (libusb_kernel_driver_active(dev_handle, 0) == 1) { | |
libusb_detach_kernel_driver(dev_handle, 0); | |
} | |
r = libusb_claim_interface(dev_handle, 1); | |
if (r < 0) { | |
printf("Cannot Claim Interface!\n"); | |
exit(1); | |
} | |
r = libusb_bulk_transfer(dev_handle, (129 | LIBUSB_ENDPOINT_IN), | |
buffer, 450, &actual, 0); | |
rndis_hdr *rndis = (rndis_hdr*)calloc(1, rndisSize); | |
make_rndis(rndis, fullSize - rndisSize); | |
struct ethhdr *ether = (struct ethhdr*)(buffer+rndisSize); | |
struct ethhdr *eth2 = (struct ethhdr*)calloc(1, etherSize); | |
make_ether2(eth2, ether->h_source, (unsigned char*)my_hwaddr); | |
//test | |
printf("h_source "); | |
for(int i=0; i<6; i++){ | |
printf("%d-", ether->h_source[i]); | |
} | |
printf("\n h_dest "); | |
for(int i=0; i<6; i++){ | |
printf("%d-", ether->h_dest[i]); | |
} | |
printf("\n h_proto "); | |
printf("%d \n", ether->h_proto); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ravi@ravi-Lenovo-G50-45:~/beagle/BBBlfs-orig/bin$ sudo ./usb_flasher | |
h_source 160-246-253-138-233-26- | |
h_dest 255-255-255-255-255-255- | |
h_proto 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment