static int pcapint_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) { int err; if (trace_get_link_type(packet) == TRACE_TYPE_NONDATA) return 0; if (!OUTPUT.trace.pcap) { OUTPUT.trace.pcap = (pcap_t *)pcap_open_live( libtrace->uridata,65536,0,0,NULL); } #ifdef HAVE_PCAP_INJECT err=pcap_inject(OUTPUT.trace.pcap, packet->payload, trace_get_capture_length(packet)); if (err!=(int)trace_get_capture_length(packet)) err=-1; #else #ifdef HAVE_PCAP_SENDPACKET err=pcap_sendpacket(OUTPUT.trace.pcap, packet->payload, trace_get_capture_length(packet)); #else trace_set_err(packet->trace,TRACE_ERR_UNSUPPORTED,"writing is not supported on this platform"); return -1; #endif #endif return err; }
/* Authenticate ourselves with the AP */ void authenticate() { const void *radio_tap = NULL, *dot11_frame = NULL, *management_frame = NULL, *packet = NULL; size_t radio_tap_len = 0, dot11_frame_len = 0, management_frame_len = 0, packet_len = 0; radio_tap = build_radio_tap_header(&radio_tap_len); dot11_frame = build_dot11_frame_header(FC_AUTHENTICATE, &dot11_frame_len); management_frame = build_authentication_management_frame(&management_frame_len); packet_len = radio_tap_len + dot11_frame_len + management_frame_len; if(radio_tap && dot11_frame && management_frame) { packet = malloc(packet_len); if(packet) { memset((void *) packet, 0, packet_len); memcpy((void *) packet, radio_tap, radio_tap_len); memcpy((void *) ((char *) packet+radio_tap_len), dot11_frame, dot11_frame_len); memcpy((void *) ((char *) packet+radio_tap_len+dot11_frame_len), management_frame, management_frame_len); pcap_inject(get_handle(), packet, packet_len); free((void *) packet); } } if(radio_tap) free((void *) radio_tap); if(dot11_frame) free((void *) dot11_frame); if(management_frame) free((void *) management_frame); return; }
int packet_socket_writev(struct packet_socket *psock, const struct iovec *iov, int iovcnt) { /* Copy the ethernet header and IP datagram into a single buffer, * since that's all the pcap API supports. TODO: optimize this. */ u8 *buf = NULL, *p = NULL; int len = 0, i = 0; /* Calculate how much space we need. */ for (i = 0; i < iovcnt; ++i) len += iov[i].iov_len; buf = malloc(len); /* Copy into the linear buffer. */ p = buf; for (i = 0; i < iovcnt; ++i) { memcpy(p, iov[i].iov_base, iov[i].iov_len); p += iov[i].iov_len; } DEBUGP("calling pcap_inject with %d bytes\n", len); if (pcap_inject(psock->pcap_out, buf, len) != len) die_pcap_perror(psock->pcap_out, "pcap_inject"); free(buf); return STATUS_OK; }
void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) { int size = (int) header->len; int seq = -1; int i; int ret; if (verify_packet_chk((u_char*)packet, size, ROUTE_ON_RELIABLE) == 0) { struct rlhdr* rlh = (struct rlhdr*)(packet + ETH_HLEN + sizeof(struct rthdr)); seq = ntohs(rlh->seq); fprintf(stdout, "Received sequence %d\n", seq); checkArray[seq] = 1; for (i = 0; i < TEST_SEQ_CNT; i++) { if (checkArray[i] != 1) { return; } } printf("ALL test segments received.\n"); int pktlen = generate_openflow_test_packet(packetOut, 128, 9999, source, dest); if ((ret = pcap_inject(handle_sniffed, packetOut, pktlen)) < 0){ fprintf(stderr, "Fail to inject packet\n"); // exit(1); } exit(1); } //print_data(stdout, (u_char*)packet, size); }
/** * Forward data from hijacker * */ static ssize_t forward_from_hijacker ( struct hijack *hijack, int fd ) { char buf[SNAPLEN]; ssize_t len; /* Read packet from hijacker */ len = read ( fd, buf, sizeof ( buf ) ); if ( len < 0 ) { logmsg ( LOG_ERR, "read from hijacker failed: %s\n", strerror ( errno ) ); return -1; } if ( len == 0 ) return 0; /* Set up filter if not already in place */ if ( ! hijack->filtered ) { if ( hijack_filter ( hijack, buf, len ) == 0 ) hijack->filtered = 1; } /* Transmit packet to network */ if ( pcap_inject ( hijack->pcap, buf, len ) != len ) { logmsg ( LOG_ERR, "write to hijacked port failed: %s\n", pcap_geterr ( hijack->pcap ) ); return -1; } hijack->tx_count++; return len; };
void captop_handler(u_char *user, const struct pcap_pkthdr *h, const u_char *payload) { auto that = reinterpret_cast<capthread *>(user); if (unlikely(global::stop.load(std::memory_order_relaxed))) return; if (likely(that != nullptr)) { if (that->in) { that->atomic_stat.in_count.fetch_add(1, std::memory_order_relaxed); that->atomic_stat.in_band.fetch_add(h->len, std::memory_order_relaxed); } if (that->out) { int ret = pcap_inject(that->out, payload, h->caplen); if (ret != -1) { that->atomic_stat.out_count.fetch_add(1, std::memory_order_relaxed); that->atomic_stat.out_band.fetch_add(h->len, std::memory_order_relaxed); } else { that->atomic_stat.fail.fetch_add(1, std::memory_order_relaxed); } } if (unlikely(that->dumper != nullptr)) pcap_dump(reinterpret_cast<u_char *>(that->dumper), h, payload); } }
/* Deauthenticate ourselves from the AP */ void deauthenticate() { const void *radio_tap = NULL, *dot11_frame = NULL, *packet = NULL; size_t radio_tap_len = 0, dot11_frame_len = 0, packet_len = 0; radio_tap = build_radio_tap_header(&radio_tap_len); dot11_frame = build_dot11_frame_header(FC_DEAUTHENTICATE, &dot11_frame_len); packet_len = radio_tap_len + dot11_frame_len + DEAUTH_REASON_CODE_SIZE; if(radio_tap && dot11_frame) { packet = malloc(packet_len); if(packet) { memset((void *) packet, 0, packet_len); memcpy((void *) packet, radio_tap, radio_tap_len); memcpy((void *) ((char *) packet+radio_tap_len), dot11_frame, dot11_frame_len); memcpy((void *) ((char *) packet+radio_tap_len+dot11_frame_len), DEAUTH_REASON_CODE, DEAUTH_REASON_CODE_SIZE); pcap_inject(get_handle(), packet, packet_len); free((void *) packet); } } if(radio_tap) free((void *) radio_tap); if(dot11_frame) free((void *) dot11_frame); return; }
int tunemu_write(int ppp_sockfd, char *buffer, int length) { allocate_data_buffer(length + 4); data_buffer[0] = 0x02; data_buffer[1] = 0x00; data_buffer[2] = 0x00; data_buffer[3] = 0x00; memcpy(data_buffer + 4, buffer, length); if (pcap == NULL) { tun_error("pcap not open"); return -1; } length = pcap_inject(pcap, data_buffer, length + 4); if (length < 0) { tun_error("injecting packet: %s", pcap_geterr(pcap)); return length; } tun_noerror(); length -= 4; if (length < 0) return 0; return length; }
int wifi_inject(char *frameToSend,int frameLength) { static int count =1 ; PRINT_DEBUG("wifi_inject has been called"); // Add the mac header then send it unsigned char *frame; frame = (unsigned char *)malloc(frameLength + SIZE_ETHERNET); //todo:check if this cannot be allocated once to 1500B // src = 00:1c:bf:87:1a:fd //dest Alex = 0x00,0x1c,0xbf,0x86,0xd2,0xda char dest[]={0x00,0x1c,0xbf,0x87,0x1a,0xfd}; char src[]={0x00,0x1c,0xbf,0x87,0x1a,0xfd}; memcpy(((struct sniff_ethernet *)frame)->ether_dhost,dest,ETHER_ADDR_LEN); memcpy(((struct sniff_ethernet *)frame)->ether_shost,src,ETHER_ADDR_LEN); ((struct sniff_ethernet *)frame)->ether_type=htons(0x0800); memcpy(frame+SIZE_ETHERNET,frameToSend,frameLength); if (pcap_inject ( inject_handle, frame,frameLength + SIZE_ETHERNET) == -1) PRINT_DEBUG("Failed to inject the packet"); PRINT_DEBUG("\n Message #%d has been injected",count); count++; //free(frameToSend); return(1); }
int pcap_send(struct pcap_conn *conn, char *buf, int size) { int ret; if (!conn || !conn->desc || !buf || size <= 0) return -EINVAL; ret = pcap_inject(conn->desc, buf, size); return ret; }
bool MF_Segmentor::sendAck(MF_ChunkInfo *ci, MF_DeviceInfo *di) { MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendAck send ack packet for given chunk"); u_char buffer[65536];// large enough for any size of bitmap memset((void *) buffer, 0xff, 65536); struct hop_data *hop; unsigned int pktCount = ci->getChunkPktCnt(); struct csyn_ack *ack; ack = (struct csyn_ack *) MF_PacketSupport::getHopHeaderPtr(buffer); ack->type = htonl(CSYN_ACK_PKT); ack->hop_ID = htonl((unsigned int) (ci->getHopID())); ack->chk_pkt_count = htonl(pktCount); unsigned int i = 0; unsigned int j = 0; int ret; if (ci->isDelivered()) {// last ack get lost for (i = 0; i < (pktCount - 1) / 8 + 1; i++) { ack->bitmap[i] = 0xff; } } else { vector <u_char *> *pList = ci->getPacketList(); for (i = 0; i < pktCount; i++) { hop = (struct hop_data *) MF_PacketSupport::getHopHeaderPtr((*pList)[i]); if (hop->pld_size == 0) { //did not get the packet yet *(ack->bitmap + (i / 8)) &= (0xfe << (i % 8)); j++; } } } unsigned int z; //TODO remove the harcoded value char tempBitmap[512]; for (z = 0; (z < (pktCount - 1) / 8 + 1) && z<512; z++) { sprintf(tempBitmap + z, "%x",ack->bitmap[z]); } MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendAck sent bitmap: %s", tempBitmap); MF_IPProto::fillHeader(buffer, ETH_HEADER_SIZE, CSYN_SIZE + ((pktCount - 1) / 8 + 1), di->getSIP().c_str(), di->getAPIP().c_str()); MF_EtherProto::fillHeader(buffer, 0, di->getSMAC().c_str(), di->getAPMAC().c_str()); if ((ret = pcap_inject(mPcapHandle, (void *) buffer, ETH_HEADER_SIZE + IP_HEADER_SIZE + CSYN_SIZE + ((pktCount - 1) / 8 + 1))) < 0) { MF_Log::mf_log(MF_ERROR, "MF_Segmentor:sendAck pcap_inject() error, errno=%d", errno); return false; } MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendAck Sent CSYN-ACK hop_ID=%d, recvd/lost/total %d/%d/%d if = %s", ntohl(ack->hop_ID), pktCount-j, j, pktCount, di->getName().c_str()); //OML #ifdef __OML__ di->increaseOutBytesByInt(ETH_HEADER_SIZE + IP_HEADER_SIZE + CSYN_SIZE + ((pktCount - 1) / 8 + 1)); di->increaseOutPackets(); #endif if (j == 0) { //get all the packets return true; } return false; }
int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto, const u8 *buf, size_t len) { if (!l2->l2_hdr) { int ret; struct l2_ethhdr *eth = os_malloc(sizeof(*eth) + len); if (eth == NULL) return -1; os_memcpy(eth->h_dest, dst_addr, ETH_ALEN); os_memcpy(eth->h_source, l2->own_addr, ETH_ALEN); eth->h_proto = htons(proto); os_memcpy(eth + 1, buf, len); ret = pcap_inject(l2->pcap, (u8 *) eth, len + sizeof(*eth)); os_free(eth); return ret; } else return pcap_inject(l2->pcap, buf, len); }
int packetrelay(pcap_t *pcd, char *dev, u_char *packet, u_char *g_ip, u_char *t_ip, u_char *s_mac, u_char *t_mac, u_char *g_mac){ struct ether_header *etheh; struct ip *iph; u_char tip[IPSIZE], sip[IPSIZE]; u_char *cp = packet; etheh = (struct ether_header *)cp; if(etheh == NULL) return 0; cp += sizeof(struct ether_header); if(etheh->ether_type == ntohs(ETHERTYPE_IP)){ iph = (struct ip*)cp; inet_ntop(AF_INET, &iph->ip_dst, tip, sizeof(tip)); inet_ntop(AF_INET, &iph->ip_src, sip, sizeof(sip)); if(!strcmp(sip, t_ip)){ memcpy(etheh->ether_dhost, g_mac, MACASIZE); memcpy(etheh->ether_shost, s_mac, MACASIZE); pcap_inject(pcd, packet, sizeof(struct ether_header) + ntohs(iph->ip_len)); } else if(!strcmp(tip, t_ip) && !memcmp(etheh->ether_shost, g_mac, MACASIZE)){ memcpy(etheh->ether_shost, s_mac, MACASIZE); memcpy(etheh->ether_dhost, t_mac, MACASIZE); pcap_inject(pcd, packet, sizeof(struct ether_header) + ntohs(iph->ip_len)); } } else if (etheh->ether_type == ntohs(ETHERTYPE_ARP)){ struct ether_arp *arph; cp = (struct ether_arp*)cp; inet_ntop(AF_INET, &arph->arp_tpa, tip, sizeof(tip)); inet_ntop(AF_INET, &arph->arp_spa, sip, sizeof(sip)); if((!strcmp(sip, t_ip) && !strcmp(tip, g_ip)) || (!strcmp(sip, g_ip) && !strcmp(tip, t_ip))){ if((sendarprep(pcd ,dev, packet, g_ip, s_mac, t_ip, t_mac)) ==-1) { pcap_perror(pcd,0); pcap_close(pcd); exit(1); }; if((sendarprep(pcd, dev, packet, t_ip, s_mac, g_ip, g_mac)) ==-1) { pcap_perror(pcd,0); pcap_close(pcd); exit(1); }; } } }
int dt_simulate_send(pcap_t *p, const void *buf, size_t size) { int bytesSend; /* send packet */ bytesSend = pcap_inject(p, buf, size); if (bytesSend != size) { fprintf(stderr, "WARNING: pcap_inject\n"); } return bytesSend; }
void inject_command(pcap_t *fp, gcry_cipher_hd_t * hd,char * dst_mac, char * command, int len, unsigned long * seqnum){ char pkt[1000]; u_char buf[1024]; u_char iv[GCRY_IVLEN]={0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}; len+=SEQ_LEN; char pkt_len[6]; char type[] = { 0x00,0x00,0x0d,0x00,0x04,0x80,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x00,0x11,0x00,0x00,0x05, 'I', 'N', 'T', 'C', 'P',0x01,0x04,0x82,0x84,0x8b,0x96,0x03,0x01,0x0c,0x04,0x06,0x01,0x02,0x00,0x00,0x00,0x00,0x05,0x04,0x00,0x01,0x00,0x00,0xdd,0x18,0x00,0x50,0xf2,0x01,0x01, 0x00,0x00,0x50,0xf2,0x04,0x01,0x00,0x00,0x50,0xf2,0x04,0x01,0x00,0x00,0x50,0xf2,0x02,0x00,0x00}; u_int tlen=len+MAC_LEN+CHECKSUM_LEN+GCRY_IVLEN; random_vector(iv,GCRY_IVLEN); memcpy(&pkt[0],dst_mac,MAC_LEN); memcpy(&pkt[MAC_LEN],iv,GCRY_IVLEN); gcry_cipher_setiv(*hd,iv, GCRY_IVLEN); char cmdseq[1000]; memcpy(cmdseq,command,len); u_int ac=0; (*seqnum)++; if(*seqnum>0xFFFFFFFF){*seqnum=0x01;} for(ac=0;ac<SEQ_LEN;ac++){ cmdseq[len-1-ac]=(char)((*seqnum)>>(ac*8)); } gcry_cipher_encrypt(*hd, &pkt[GCRY_IVLEN+MAC_LEN],len , cmdseq, len); u_int chk=checksum(pkt,tlen); u_char chkarr[CHECKSUM_LEN]; chkarr[0]=(chk>>8); chkarr[1]=chk&0x00FF; memcpy(&pkt[GCRY_IVLEN+MAC_LEN+len], chkarr,CHECKSUM_LEN); memcpy(buf, type, sizeof(type)); memcpy(buf+sizeof(type), pkt, tlen); #ifndef MANDO_ABORDO print_vector(pkt,tlen); #endif for(ac=0;ac<BEACONS_PER_REQUEST;ac++){ int inj=pcap_inject(fp,buf, sizeof(type)+sizeof(pkt_len)+tlen); #ifndef MANDO_ABORDO printf("\r\n INJ %i",inj); #endif } }
/* * tap_callback * * This function is called every times a package is received through the * (optional) tap device. It retransmits the package to all connected devices. */ void tap_callback(void) { int len, i; len = read(tapFD, buffer, sizeof(buffer)); if (len > 0) { for (i = 0; i < deviceCount; i++) { pcap_inject(devices[i], buffer, len); } } }
static void epcap_send(EPCAP_STATE *ep) { const int fd = STDIN_FILENO; ssize_t n = 0; unsigned char buf[SNAPLEN] = {0}; u_int16_t len = 0; for ( ; ; ) { if (child_exited) return; n = read_exact(fd, buf, sizeof(len)); if (n != sizeof(len)) { VERBOSE(1, "epcap_send: header len != %lu: %ld", (unsigned long)sizeof(len), (long)n); return; } len = (buf[0] << 8) | buf[1]; VERBOSE(2, "epcap_send: packet len = %u", len); if (len >= sizeof(buf)) return; n = read_exact(fd, buf, len); if (n != len) { VERBOSE(1, "epcap_send: len = %u, read = %ld", len, (long)n); return; } if (ep->opt & EPCAP_OPT_INJECT) { n = pcap_inject(ep->p, buf, len); if (n < 0) { VERBOSE(0, "epcap_send: %s", pcap_geterr(ep->p)); return; } else if (n != len) { VERBOSE(1, "epcap_send: len = %u, sent = %ld", len, (long)n); } } else { VERBOSE(2, "epcap_send: ignoring: len = %u", len); } } }
void pb_transmit_packet(pcap_t *ppcap, int seq_nr, uint8_t *packet_transmit_buffer, int packet_header_len, const uint8_t *packet_data, int packet_length) { //add header outside of FEC wifi_packet_header_t *wph = (wifi_packet_header_t *)(packet_transmit_buffer + packet_header_len); wph->sequence_number = seq_nr; //copy data memcpy(packet_transmit_buffer + packet_header_len + sizeof(wifi_packet_header_t), packet_data, packet_length); int plen = packet_length + packet_header_len + sizeof(wifi_packet_header_t); int r = pcap_inject(ppcap, packet_transmit_buffer, plen); if (r != plen) { pcap_perror(ppcap, "Trouble injecting packet"); exit(1); } }
static mrb_value mrb_capture_inject(mrb_state *mrb, mrb_value self) { struct capture_object *cap; const char *data; mrb_int len, n; cap = (struct capture_object *)mrb_get_datatype(mrb, self, &mrb_pcap_type); if (!cap) return mrb_nil_value(); mrb_get_args(mrb, "s", &data, &len); n = pcap_inject(cap->pcap, data, (size_t)len); return mrb_fixnum_value(n); }
/* * All transmissions are handled here to ensure that the receive timer * is always started immediately after a packet is transmitted. */ int send_packet(const void *packet, size_t len) { int ret_val = 0; if(pcap_inject(get_handle(), packet, len) == len) { ret_val = 1; } start_timer(); return ret_val; }
int tapemu_inject(char *buffer,unsigned short size) { if(pcap_ppp) { int len=pcap_inject(pcap_ppp, buffer-2, size+2); if(len<0) { msg (M_INFO,"Problem sending packet (%s)",pcap_geterr(pcap_ppp)); } return len; } else { return 0; } }
void send_test_packet(pcap_t* handle, int testno, int packetsize, int source, int dest) { printf("==========> Test %d: generating packets of %d bytes...\n", testno, packetsize); int pktlen = generate_test_packet(packetOut, packetsize, testno, source, dest); print_rl_packet(stdout, packetOut, pktlen); //encrypt((const u_char *)packetOut, packetOut_e, &schedule1, pktlen); int ret = 0; if ((ret = pcap_inject(handle, packetOut_e, pktlen)) < 0){ fprintf(stderr, "Fail to inject packet\n"); // exit(1); } printf( "DONE\n"); usleep(50); //sleep(1); }
/* Does what it says */ void send_probe_request(unsigned char *bssid, char *essid) { const void *probe = NULL; size_t probe_size = 0; probe = build_wps_probe_request(bssid, essid, &probe_size); if(probe) { pcap_inject(get_handle(), probe, probe_size); free((void *) probe); } return; }
// Send a packet void EthPutPacket(ETH *e, void *data, UINT size) { int s, ret; // Validate arguments if (e == NULL || data == NULL) { return; } if (size < 14 || size > MAX_PACKET_SIZE) { Free(data); return; } if (e->Tap != NULL) { #ifndef NO_VLAN // tap mode VLanPutPacket(e->Tap, data, size); #endif // NO_VLAN return; } s = e->Socket; if (s == INVALID_SOCKET) { Free(data); return; } // Send to device #ifdef BRIDGE_PCAP ret = pcap_inject(e->Pcap, data, size); if( ret == -1 ){ #ifdef _DEBUG pcap_perror(e->Pcap, "inject"); #endif // _DEBUG Debug("EthPutPacket: ret:%d size:%d\n", ret, size); } #else // BRIDGE_PCAP ret = write(s, data, size); if (ret<0) { Debug("EthPutPacket: ret:%d errno:%d size:%d\n", ret, errno, size); } #endif //BRIDGE_PCAP Free(data); }
bool NetworkInterface::writePacket(const u_char *bytes, size_t length) { if(!m_pHandler) { std::cerr << "Can't write packet! Interface wasn't initialized!" << std::endl; return false; } if(pcap_inject(m_pHandler, bytes, length) == -1) { std::cerr << "Unable to write packet! Details: " << pcap_geterr(m_pHandler) << std::endl; return false; } return true; }
unsigned int MF_Segmentor::sendData(MFSendingChunk &sendingChunk, MF_DeviceInfo *di) { MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendData send data chunk"); int ret = 0; struct hop_data *hop; vector <u_char *> *pList = sendingChunk.chunkInfo->getPacketList(); //Transmits only the max amount of allowed packets unsigned int maxPackets = MAX_OSTD - w_ostd; unsigned int min = maxPackets > sendingChunk.nonAckedPackets.size() ? sendingChunk.nonAckedPackets.size() : maxPackets; unsigned int index; MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendData sending %u packets given window size %u for hop_ID=%u", min, w_ostd, sendingChunk.csynSeqNum); unsigned int total_bytes = 0; for (unsigned int i = 0; i < min; i++) { hop = (struct hop_data *) MF_PacketSupport::getHopHeaderPtr((*pList)[i]); index = sendingChunk.nonAckedPackets.front(); sendingChunk.nonAckedPackets.pop(); //cout << "Sending packet " << index << endl; ret = pcap_inject(mPcapHandle, (void *) ((*pList)[index]), MF_PacketSupport::LOW_HEADER_LEN + ntohl(hop->pld_size)); if (ret < 0) { MF_Log::mf_log(MF_ERROR, "MF_Segmentor::sendData(): pcap_inject() error, errno=%d", errno); } total_bytes += MF_PacketSupport::LOW_HEADER_LEN + ntohl(hop->pld_size); } #ifdef __OML__ di->increaseOutPacketsByInt(min); di->increaseOutBytesByInt(total_bytes); di->sendOMLUpdate(); #endif MF_Log::mf_log(MF_DEBUG, "MF_Segmentor::sendData(): Sent %u packets. hop_ID=%u", min, sendingChunk.chunkInfo->getHopID()); //MF_Log::mf_log_time("MF_Segmentor:procSend SEND_CSYN INIT chunk %lu interface %d", sendingChunk.chunkInfo->getChunkID(), di->getID()); if(sendingChunk.nonAckedPackets.size() == 0){ //cout << "Sent out all packets for chunk " << sendingChunk.csynSeqNum << endl; MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendData send all packets for hop_ID=%u",sendingChunk.csynSeqNum); sendCsyn(sendingChunk.chunkInfo, di); sendingChunk.isCsynSent = true; unsigned int *tempInt = (unsigned int*)calloc(1, sizeof(unsigned int)); *tempInt = sendingChunk.csynSeqNum; sendingChunk.TOID = _system->getTimeoutManager()->AddTimeout(this, (void *)(tempInt), (long int)timeTimout); if(sendingChunk.csynSeqNum == pendingChunk && isPending){ isPending = false; } } else { //cout << "Missing chunks for chunk " << sendingChunk.csynSeqNum << " will have to wait for availability in window" << endl; MF_Log::mf_log(MF_DEBUG, "MF_Segmentor:sendData hop_ID=%u partially sent",sendingChunk.csynSeqNum); isPending = true; pendingChunk = sendingChunk.csynSeqNum; } return min; }
int tc_pcap_send(unsigned char *frame, size_t len) { int send_len; char pcap_errbuf[PCAP_ERRBUF_SIZE]; pcap_errbuf[0]='\0'; send_len = pcap_inject(pcap, frame, len); if (send_len == -1) { return TC_ERROR; } return TC_OK; }
int main() { char pcap_errbuf[PCAP_ERRBUF_SIZE]; pcap_errbuf[0]='\0'; pcap_t* pcap=pcap_open_live("eth2", 96, 0, 0, pcap_errbuf); if (pcap_errbuf[0]!='\0') { fprintf(stderr,"%s",pcap_errbuf); } if (!pcap) { return 1; } if (pcap_inject(pcap,&frameForwardEthernetFrames,sizeof(frameForwardEthernetFrames))==-1) { pcap_perror(pcap,0); } pcap_close(pcap); }
static int lpcap_inject(lua_State* L) { pcap_t* cap = checkpcap(L); size_t datasz = 0; const char* data = luaL_checklstring(L, 2, &datasz); int sent = pcap_inject(cap, data, datasz); if (sent < 0) { return pusherr(L, cap); } lua_pushinteger(L, sent); return 1; }
void SendStructToServer(warpnetControllerGroup* theGroupStruct, void *theStruct) { unsigned char structID; void* structPtr; int structLen = 0; int rv; structPtr = theStruct; structID = *( (unsigned char *)theStruct); void* txPktPtr; switch(structID) { case STRUCTID_LOGPARAMS_ACK: structLen = sizeof(warpnetAck); structPtr = theStruct; break; default: printf("SendStructToServer: Unknown structID! (0x%x)\n", structID); break; } if(structLen > 0) { txEthPktHdr.ethType = WARPNET_ETHTYPE_NODE2SVR; txEthPktHdr.pktLength = sizeof(warpnetEthernetPktHeader) + sizeof(warpnetControllerGroup) + structLen; txEthPktHdr.numStructs = 1; txEthPktHdr.seqNum = 0; txPktPtr = &txEthPktBuf; memcpy(txPktPtr, &txEthPktHdr, sizeof(warpnetEthernetPktHeader)); memcpy(txPktPtr+sizeof(warpnetEthernetPktHeader), theGroupStruct, sizeof(warpnetControllerGroup)); memcpy(txPktPtr+sizeof(warpnetEthernetPktHeader)+sizeof(warpnetControllerGroup), structPtr, structLen); rv = pcap_inject(pcap_handle, (void *)txPktPtr, (txEthPktHdr.pktLength) ); if(rv < 0){ pcap_perror(pcap_handle, ""); printf("Error on pcap_inject!\n"); } } return; }