Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pcap.h>
- #include <libnet.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdint.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include "pcap_structs.h"
- //OTHER FIELDS W LIBNET AND PCAP
- pcap_t *pcap, *pcap_sender;
- char pcap_errbuf[PCAP_ERRBUF_SIZE];
- char libnet_errbuf[LIBNET_ERRBUF_SIZE];
- const unsigned char *packet;
- struct pcap_pkthdr header;
- libnet_t *l;
- struct libnet_link_int *network;
- //LIBNET TAG FIELDS
- libnet_ptag_t eth_tag, ip_tag, tcp_tag, udp_tag;
- //OTHER FIELDS
- char filename[100];
- char *type_of_packet;
- //DECLARE STRUCTS
- const struct sniff_ethernet *ethernet;
- const struct sniff_ip *ip;
- const struct sniff_tcp *tcp;
- const struct sniff_udp *udp;
- const char *payload;
- ////////////////////////
- void hex_view(unsigned char *packet){
- printf("\n\nHEX VIEW: ");
- int i;
- i = 0;
- while(i != 76){
- if(i%8 == 0){
- printf(" ");
- }
- if(i%16 == 0){
- printf("\n");
- }
- printf("%x ", packet[i]);
- i++;
- }
- printf("\n\n#################\n");
- }
- unsigned char* add_to_new_packet(const unsigned char *packet){
- unsigned char *new_packet = NULL;
- int i;
- i = 17;
- while(i != 76){
- new_packet[i-17] = packet[i];
- i++;
- }
- return new_packet;
- }
- int main(){
- l = libnet_init(LIBNET_RAW4_ADV, "eth0", libnet_errbuf);
- //
- pcap = pcap_open_offline((char*)"c.pcap", pcap_errbuf);
- pcap_sender = pcap_open_live((char*)"eth0", BUFSIZ, 1, 1000, pcap_errbuf);
- packet = pcap_next(pcap, &header);
- hex_view(packet);
- //pcap_sendpacket(pcap_sender, packet, 76);
- //pcap_inject(pcap_sender, packet,1);
- //new packet
- int i;
- unsigned char new_packet[76-16];
- for(i=0; i<76-16; i++){
- new_packet[i] = packet[i+16];
- if(i%8 == 0){
- printf(" ");
- }
- if(i%16 == 0){
- printf("\n");
- }
- printf("%x ", packet[i]);
- }
- printf("\nNEWPACKET ");
- hex_view(new_packet);
- //pcap_inject(pcap_sender, new_packet, 76 - 16);
- //pcap_sendpacket(pcap_sender, new_packet, 76 - 16);
- libnet_adv_write_raw_ipv4(l, new_packet, 76 - 16);
- printf("\n%s\n%s", libnet_geterror(l), pcap_geterr(pcap_sender));
- libnet_destroy(l);
- //
- //unsigned char *new_packet =
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement