当前位置: 首页>>代码示例>>C++>>正文


C++ print_packet函数代码示例

本文整理汇总了C++中print_packet函数的典型用法代码示例。如果您正苦于以下问题:C++ print_packet函数的具体用法?C++ print_packet怎么用?C++ print_packet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了print_packet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: send_packet

int send_packet( const packet *p, const char *why )
{
    int ret;
    mbedtls_net_context *dst = p->dst;

    /* insert corrupted ApplicationData record? */
    if( opt.bad_ad &&
        strcmp( p->type, "ApplicationData" ) == 0 )
    {
        unsigned char buf[MAX_MSG_SIZE];
        memcpy( buf, p->buf, p->len );

        if( p->len <= 13 )
        {
            mbedtls_printf( "  ! can't corrupt empty AD record" );
        }
        else
        {
            ++buf[13];
            print_packet( p, "corrupted" );
        }

        if( ( ret = dispatch_data( dst, buf, p->len ) ) <= 0 )
        {
            mbedtls_printf( "  ! dispatch returned %d\n", ret );
            return( ret );
        }
    }

    print_packet( p, why );
    if( ( ret = dispatch_data( dst, p->buf, p->len ) ) <= 0 )
    {
        mbedtls_printf( "  ! dispatch returned %d\n", ret );
        return( ret );
    }

    /* Don't duplicate Application Data, only handshake covered */
    if( opt.duplicate != 0 &&
        strcmp( p->type, "ApplicationData" ) != 0 &&
        rand() % opt.duplicate == 0 )
    {
        print_packet( p, "duplicated" );

        if( ( ret = dispatch_data( dst, p->buf, p->len ) ) <= 0 )
        {
            mbedtls_printf( "  ! dispatch returned %d\n", ret );
            return( ret );
        }
    }

    return( 0 );
}
开发者ID:nodish,项目名称:openthread,代码行数:52,代码来源:udp_proxy.c

示例2: main

int main() {
    struct packet p;
    init_packet(&p);
    print_packet(&p);
    tag_client_send(&p);
    print_packet(&p);
    tag_server_recv(&p);
    print_packet(&p);
    tag_server_send(&p);
    print_packet(&p);
    tag_client_recv(&p);
    print_packet(&p);
    return 0;
}
开发者ID:uranix,项目名称:yantp,代码行数:14,代码来源:test.c

示例3: client_send

static int client_send (uint8_t *data, uint32_t *count)
{
    memcpy(send_buffer.data, data, *count);
    send_buffer.len = *count;

    print_packet(" REQUEST: ", send_buffer.data, send_buffer.len);

    server_process_message(send_buffer.data, send_buffer.len,
                           recv_buffer.data, &recv_buffer.len);

    print_packet("RESPONSE: ", recv_buffer.data, recv_buffer.len);

    return 0;
}
开发者ID:brunoseivam,项目名称:libbsmp,代码行数:14,代码来源:client.c

示例4: main

int main(int argc, char **argv)
{
  if (argc != 2)
  {
    printf("No Argument Specified\n");
    return 1;
  }
  char *endptr = argv[1];
  int number = strtol(argv[1], &endptr, 10);
  if (endptr == argv[1] || number < 0 )
  {
    printf("Invalid Argument\n");
    return 1;
  }
  FILE *fp = fopen( CONTROLLER_DEV, "r+b");
  if ( fp == NULL )
  {
    printf("Controller Does Not Exist\n");
    return 1;
  }
  controller control;
  fwrite( &number, 4, 1, fp );
  for (int i = 0; i < number; i++)
  {
    fread(&control.place_holder, 4, 1, fp);
    print_packet(control);
  }
  fclose(fp);
  //free(control);
  return 0;
}
开发者ID:YXuewei,项目名称:Code-I-Have-Down,代码行数:31,代码来源:logger.c

示例5: process_packet

void process_packet(u_char *args, const struct pcap_pkthdr *header,
		const u_char *packet)
{
	const struct sniff_ethernet *ether;	/* The ethernet header */
	const struct sniff_ip *ip;		/* The IP header */
	const struct sniff_tcp *tcp;		/* The TCP header */
	const char *payload;			/* Packet payload. */

	u_int size_ip;	/* IP Header length */
	u_int size_tcp; /* TCP Header length */

	ether = (struct sniff_ethernet*)(packet); 
	ip = (struct sniff_ip*)(packet + SIZE_ETHERNET);
	size_ip = IP_HL(ip) * 4;
	if(size_ip < 20) {
		printf("\t* Invalid IP header length: %u bytes\n", size_ip);
		return;
	}

	tcp = (struct sniff_tcp*)(packet + SIZE_ETHERNET + size_ip);
	size_tcp = TH_OFF(tcp) * 4;
	if(size_tcp < 20) {
		printf("\t*Invalid TCP header length: %u bytes\n", size_tcp);

	}

	payload = (u_char*)(packet + SIZE_ETHERNET + size_ip + size_tcp);

	print_packet(ether,ip,tcp);
}
开发者ID:rhanham,项目名称:packet-sniffles,代码行数:30,代码来源:main.c

示例6: eth_parse

// Parse the ethernet headers, and return the payload position (0 on error).
uint32_t eth_parse(struct pcap_pkthdr *header, uint8_t *packet,
                   eth_info * eth, config * conf) {
    uint32_t pos = 0;

    if (header->len < 14) {
        fprintf(stderr, "Truncated Packet(eth)\n");
        return 0;
    }

    while (pos < 6) {
        eth->dstmac[pos] = packet[pos];
        eth->srcmac[pos] = packet[pos+6];
        pos++;
    }
    pos = pos + 6;
   
    // Skip the extra 2 byte field inserted in "Linux Cooked" captures.
    if (conf->datalink == DLT_LINUX_SLL) {
        pos = pos + 2;
    }

    // Skip VLAN tagging 
    if (packet[pos] == 0x81 && packet[pos+1] == 0) pos = pos + 4;

    eth->ethtype = (packet[pos] << 8) + packet[pos+1];
    pos = pos + 2;

    SHOW_RAW(
        printf("\neth ");
        print_packet(header->len, packet, 0, pos, 18);
    )
开发者ID:MikeAT,项目名称:dns_parse,代码行数:32,代码来源:network.c

示例7: open_file

int open_file(const char *path)
{
    char errbuf[PCAP_ERRBUF_SIZE];
    int packet_count = 0;
    pcap_t *file;

    struct pcap_pkthdr h;

    file = pcap_open_offline(path, errbuf);

    if (!file)
    {
        printf("Error: pcap_open_offline(): %s %s %d.\n", errbuf, __FILE__, __LINE__);
        return ERROR;
    }
    u_char *packet;
    while ((packet = (u_int8_t *) pcap_next(file, &h)) != NULL)
    {
        print_packet(&h, packet);
        packet_count++;
    }

    printf("%d paquetes en el archivo %s.\n", packet_count, path);

    return OK;
}
开发者ID:padsof-uam,项目名称:redes,代码行数:26,代码来源:main.c

示例8: send_ack

/* send an ack for the given message and message ID */
static void send_ack (int sock, struct allnet_header * hp,
                      unsigned char * message_ack,
                      int send_resend_request, char * contact, keyset kset)
{
  if ((hp->transport & ALLNET_TRANSPORT_ACK_REQ) == 0) {
printf ("packet not requesting an ack, no ack sent\n");
    return;
  }
  int size;
  struct allnet_header * ackp =
    create_ack (hp, message_ack, NULL, ADDRESS_BITS, &size);
  if (ackp == NULL)
    return;
  /* also save in the (very likely) event that we receive our own ack */
  currently_sent_ack = (currently_sent_ack + 1) % NUM_ACKS;
  memcpy (recently_sent_acks [currently_sent_ack], message_ack,
          MESSAGE_ID_SIZE);
#ifdef DEBUG_PRINT
  print_packet ((char *) ackp, size, "sending ack", 1);
#endif /* DEBUG_PRINT */
  send_pipe_message_free (sock, (char *) ackp, size, ALLNET_PRIORITY_LOCAL);
/* after sending the ack, see if we can get any outstanding
 * messages from the peer */
  if (send_resend_request)
    request_and_resend (sock, contact, kset);
}
开发者ID:abrauchli,项目名称:allnet,代码行数:27,代码来源:xcommon.c

示例9: main

int main(int argc, char** argv) {
  if (argc < 2) {
    std::cerr << "USAGE: parsepgp <file>" << std::endl;
    return 1;
  }

  std::ifstream pgp_file;
  pgp_file.open(argv[1]); // Flawfinder: ignore (give the user what they want)

  std::stringstream str_stream;
  str_stream << pgp_file.rdbuf();

  try {
    std::string file_contents = str_stream.str();
    parse4880::parse(
        parse4880::ustring(file_contents.begin(), file_contents.end()),
        [](std::shared_ptr<parse4880::PGPPacket> packet) -> bool {
          print_packet(*packet, 0);
          return true;
        });
  }
  catch(const parse4880::parse4880_error& e) {
    fprintf(stderr, "Parse error:\n\t%s\n", e.what());
    return 1;
  }
}
开发者ID:LachlanGunn,项目名称:parse4880,代码行数:26,代码来源:main.cpp

示例10: l2tp_sync_ppp_handle_frame_from_tunnel

/**********************************************************************
* %FUNCTION: handle_frame_from_tunnel
* %ARGUMENTS:
*  ses -- l2tp session
*  buf -- received PPP frame
*  len -- length of frame
* %RETURNS:
*  Nothing
* %DESCRIPTION:
*  Shoots the frame to PPP's pty
***********************************************************************/
void l2tp_sync_ppp_handle_frame_from_tunnel(l2tp_session *ses, unsigned char *buf, size_t len)
{
    int n;

	d_dbg("l2tp_sync_ppp_handle_frame_from_tunnel >>>\n");
	
    //+++ michael_lee: (2012.06.15 11:56:55)
    // this will cause kernel skb unalign at ppp_synctty.c ppp_sync_input function. remove it.
    //--- michael_lee
#if 0
    /* Add framing bytes */
    *--buf = 0x03;
    *--buf = 0xFF;
    len += 2;
#endif
#if 0
	print_packet(2, buf, len, "l2tp_sync_ppp_handle_from_from_tunnel");
#endif

	//+++ fix by siyou. 2011/1/6 11:08¤W¤È
		//marco, add 20 ms sleep here, or in some situation, two packets will combine as one packet
		//which will affect the state machine and we will not reply chap response		
		//usleep(20000);
	//---

    /* TODO: Add error checking */
	if (ses->pty_fd < 0) {
		d_dbg("Attempt to write %d bytes to non existent fd.", len);
	} else {
		n = write(ses->pty_fd, buf, len);
	}
	d_dbg("l2tp_sync_ppp_handle_frame_from_tunnel <<<\n");
}
开发者ID:jhbsz,项目名称:DIR-850L_A1,代码行数:44,代码来源:sync-pppd.c

示例11: send_whohas_packet_to_all

// send WHOHAS to all peers
void send_whohas_packet_to_all(struct packet* packets, int packet_count, int socket, struct sockaddr* dst_addr){
  int i = 0;
  for(i=0;i<packet_count;i++){
  	print_packet(&packets[i]);
    send_packet(packets[i], socket, dst_addr);
  }
}
开发者ID:thuhujin,项目名称:Bittorrent-with-Congestion-Control,代码行数:8,代码来源:network.c

示例12: l2tp_sync_ppp_handle_frame_to_tunnel

/**********************************************************************
* %FUNCTION: handle_frame_to_tunnel
* %ARGUMENTS:
*  ses -- l2tp session
* %RETURNS:
*  Nothing
* %DESCRIPTION:
*  Handles readability on PTY; shoots PPP frame over tunnel
***********************************************************************/
void l2tp_sync_ppp_handle_frame_to_tunnel(l2tp_session * ses)
{
	static unsigned char buf[4096+EXTRA_HEADER_ROOM];
	unsigned char * payload;
	int n;
	int iters = 5;

	d_dbg("%s >>>\n" , __FUNCTION__);
	
	/* It seems to be better to read in a loop than to go
	 * back to select loop.  However, don't loop forever, or
	 * we could have a DoS potential */
	payload = buf + EXTRA_HEADER_ROOM;

	while (iters--)
	{	/* EXTRA_HEADER_ROOM bytes extra space for l2tp header */
		n = read(ses->pty_fd, payload, sizeof(buf)-EXTRA_HEADER_ROOM);
		/* TODO: Check this.... */
		if (n <= 2) break;
		if (!ses) continue;

		/* Chop off framing bytes */
#if 0
		print_packet(2, payload, n, "l2tp_sync_ppp_handle_from_to_tunnel");
#endif
		if (payload[0] == 0xff && payload[1] == 0x03)
		{
			payload += 2;
			n -= 2;
		}
		l2tp_dgram_send_ppp_frame(ses, payload, n);
	}

	d_dbg("l2tp_sync_ppp_handle_from_to_tunnel <<<\n");
}
开发者ID:jhbsz,项目名称:DIR-850L_A1,代码行数:44,代码来源:sync-pppd.c

示例13: send_packet

void send_packet(apacket *p, atransport *t)
{
    unsigned char *x;
    unsigned sum;
    unsigned count;

    p->msg.magic = p->msg.command ^ 0xffffffff;

    count = p->msg.data_length;
    x = (unsigned char *) p->data;
    sum = 0;
    while(count-- > 0){
        sum += *x++;
    }
    p->msg.data_check = sum;

    print_packet("send", p);

    if (t == NULL) {
        D("Transport is null \n");
        // Zap errno because print_packet() and other stuff have errno effect.
        errno = 0;
        fatal_errno("Transport is null");
    }

    if(write_packet(t->transport_socket, t->serial, &p)){
        fatal_errno("cannot enqueue packet on transport socket");
    }
}
开发者ID:ajsb85,项目名称:libadb.js,代码行数:29,代码来源:transport.cpp

示例14: cs8900a_output

static uint8
cs8900a_output (struct device_desc *dev, uint8 * buf, uint16 packet_len)
{
	struct net_device *net_dev = (struct net_device *) dev->dev;
	struct net_cs8900a_io *io = (struct net_cs8900a_io *) dev->data;
	int len;

	//printf("%s: packet_len:%d\n", __FUNCTION__, packet_len);
#if 0
	print_packet (buf, packet_len);
#endif
	if ((len = net_dev->net_write (net_dev, buf, packet_len)) == -1) {
		fprintf (stderr, "write to tapif error in skyeye-ne2k.c\n");
		return -1;
	}
	io->ctrl_st[CtrlStNum (PP_TxEvent)] |= 0x100;
	io->ctrl_st[CtrlStNum (PP_BusST)] |= Rdy4TxNOW;

	if (io->ctrl_st[CtrlStNum (PP_BusCTL)] & EnableRQ) {
		set_time (io->index, packet_len);
		io->need_update = 1;
		net_cs8900a_set_update_intr (dev);
	}
	return 0;
}
开发者ID:Jarvishappy,项目名称:tsinghua,代码行数:25,代码来源:dev_net_cs8900a.c

示例15: plb_send

/*---------------------------------------------------------------------------*/
static void
plb_send(mac_callback_t sent, void *ptr)
{
  PRINTF("plb_send\n");

  if ( packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == 0 )	//data
   {
 	  PRINTF("plb_send : DATA\n");
 	  send_req = 1;
 	  sent_callback = sent;
 	  sent_ptr = ptr;
 	 //packetbuf_clear_hdr();
 	  temp_len=packetbuf_datalen();
 	  packetbuf_copyto(dataptr_temp);
 	  print_packet(dataptr_temp,packetbuf_totlen());//JJH3
   }
   //kdw sync
   else if ( packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == 1 ) //sync
   {
 		sent_callback = sent;
 		sent_ptr = ptr;
 		plb_send_sync_start();
   }
   else // error
   {
 	  mac_call_sent_callback(sent, ptr, MAC_TX_ERR, 1); //error   fill this
   }

  return;
}
开发者ID:deawoo,项目名称:contiki-2.7-plb,代码行数:31,代码来源:plb_backup_0218.c


注:本文中的print_packet函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。