本文整理汇总了C++中print_packet函数的典型用法代码示例。如果您正苦于以下问题:C++ print_packet函数的具体用法?C++ print_packet怎么用?C++ print_packet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_packet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: print_packets
void print_packets(std::list<std::shared_ptr<parse4880::PGPPacket>> packets,
int level) {
for (auto i = packets.begin(); i != packets.end(); i++) {
print_packet(**i, level);
}
}
开发者ID:LachlanGunn,项目名称:parse4880,代码行数:7,代码来源:main.cpp
示例17: handle_packet
/* handle an incoming packet, acking it if it is a data packet for us
* returns the message length > 0 if this was a valid data message from a peer.
* if it gets a valid key, returns -1 (details below)
* Otherwise returns 0 and does not fill in any of the following results.
*
* if it is a data or ack, it is saved in the xchat log
* if it is a valid data message from a peer or a broadcaster,
* fills in verified and broadcast
* fills in contact, message (to point to malloc'd buffers, must be freed)
* if not broadcast, fills in desc (also malloc'd), sent (if not null)
* and duplicate.
* if verified and not broadcast, fills in kset.
* the data message (if any) is null-terminated
*
* if kcontact and ksecret1 are not NULL, assumes we are also looking
* for key exchange messages sent to us matching either of ksecret1 or
* (if not NULL) ksecret2. If such a key is found, returns -1.
* there are two ways of calling this:
* - if the user specified the peer's secret, first send initial key,
* then call handle_packet with our secret in ksecret1 and our
* peer's secret in ksecret2.
* - otherwise, put our secret in ksecret1, make ksecret2 and kaddr NULL,
* and handle_packet is ready to receive a key.
* In either case, if a matching key is received, it is saved and a
* response is sent (if a response is a duplicate, it does no harm).
* kmax_hops specifies the maximum hop count of incoming acceptable keys,
* and the hop count used in sending the key.
*
* if subscription is not null, listens for a reply containing a key
* matching the subscription, returning -2 if a match is found.
*/
int handle_packet (int sock, char * packet, int psize,
char ** contact, keyset * kset,
char ** message, char ** desc,
int * verified, time_t * sent,
int * duplicate, int * broadcast,
char * kcontact, char * ksecret1, char * ksecret2,
int kmax_hops,
char * subscription,
unsigned char * addr, int nbits)
{
if (! is_valid_message (packet, psize))
return 0;
struct allnet_header * hp = (struct allnet_header *) packet;
int hsize = ALLNET_SIZE (hp->transport);
if (psize < hsize)
return 0;
#ifdef DEBUG_PRINT
if (hp->hops > 0) /* not my own packet */
print_packet (packet, psize, "xcommon received", 1);
#endif /* DEBUG_PRINT */
if (hp->message_type == ALLNET_TYPE_ACK) {
handle_ack (sock, packet, psize, hsize);
return 0;
}
if (hp->message_type == ALLNET_TYPE_CLEAR) { /* a broadcast packet */
if ((subscription != NULL) && (addr != NULL)) {
int sub = handle_sub (sock, hp, packet + hsize, psize - hsize,
subscription, addr, nbits);
#ifdef DEBUG_PRINT
printf ("handle_sub (%d, %p, %p, %d, %s, %p, %d) ==> %d\n",
sock, hp, packet + hsize, psize - hsize, subscription,
addr, nbits, sub);
#endif /* DEBUG_PRINT */
if (sub > 0) /* received a key in response to our subscription */
return sub;
}
#ifdef DEBUG_PRINT
else
printf ("subscription %p, addr %p, did not call handle_sub\n",
subscription, addr);
#endif /* DEBUG_PRINT */
return handle_clear (hp, packet + hsize, psize - hsize,
contact, message, verified, broadcast);
}
if (hp->message_type == ALLNET_TYPE_DATA) /* an encrypted data packet */
return handle_data (sock, hp, packet + hsize, psize - hsize,
contact, kset, message, desc, verified, sent,
duplicate, broadcast);
if (hp->message_type == ALLNET_TYPE_KEY_XCHG)
return handle_key (sock, hp, packet + hsize, psize - hsize,
kcontact, ksecret1, ksecret2, kmax_hops);
return 0;
}
开发者ID:abrauchli,项目名称:allnet,代码行数:91,代码来源:xcommon.c
示例18: main
void main(void) {
volatile packet_t *p;
volatile uint8_t t=20;
uint8_t chan;
char c;
gpio_data(0);
gpio_pad_dir_set( 1ULL << LED );
/* read from the data register instead of the pad */
/* this is needed because the led clamps the voltage low */
gpio_data_sel( 1ULL << LED);
/* trim the reference osc. to 24MHz */
trim_xtal();
uart_init(UART1, 115200);
vreg_init();
maca_init();
/* sets up tx_on, should be a board specific item */
*GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
gpio_pad_dir_set( 1ULL << 44 );
set_power(0x0f); /* 0dbm */
chan = 0;
set_channel(chan); /* channel 11 */
*MACA_MACPANID = 0xaaaa;
*MACA_MAC16ADDR = 0x1111;
*MACA_TXACKDELAY = 68; /* 68 puts the tx ack at about the correct spot */
set_prm_mode(AUTOACK);
print_welcome("rftest-rx");
while(1) {
/* call check_maca() periodically --- this works around */
/* a few lockup conditions */
check_maca();
if((p = rx_packet())) {
/* print and free the packet */
printf("autoack-rx --- ");
print_packet(p);
maca_free_packet(p);
}
if(uart1_can_get()) {
c = uart1_getc();
if(c == 'z') t++;
if(c == 'x') t--;
*MACA_TXACKDELAY = t;
printf("tx ack delay: %d\n\r", t);
}
}
}
开发者ID:13416795,项目名称:contiki,代码行数:59,代码来源:autoack-rx.c
示例19: server_send_packet
static bool server_send_packet(Client *c, Packet *pkt) {
print_packet("server-send:", pkt);
if (send_packet(c->socket, pkt))
return true;
debug("FAILED\n");
c->state = STATE_DISCONNECTED;
return false;
}
开发者ID:eworm-de,项目名称:abduco,代码行数:8,代码来源:server.c
示例20: read_from_file
void read_from_file (FILE *fp) {
uint8_t cmdbuf[MAXCMD];
uint8_t sz = 0;
uint8_t response[MAXCMD];
char line[MAXLINECMD];
char *p;
while (fgets (line, MAXLINECMD, fp))
{
p = line;
sz = 0;
while (*p && sz < MAXCMD)
{
if (*p == ' ') {
p++;
continue;
}
if (*p == '\n' || *p == '\r') {
break;
}
if (isxdigit(*p) && isxdigit(p[1])) {
sscanf(p, "%02x", (unsigned int *)&cmdbuf[sz]);
sz++;
p += 2;
} else {
break;
}
}
if (sz > 0)
{
if (optsendpackets && cmdbuf[0] == 0x09)
{
print_packet(cmdbuf, sz);
send_raw_packet(watch, sz, cmdbuf, response);
print_packet(response, response[1] + 2);
} else {
// we're not going to send anything to the watch, just print it
print_packet(cmdbuf, sz);
}
}
}
}
开发者ID:lgrangeia,项目名称:ttwatch,代码行数:45,代码来源:ttdiag.c
注:本文中的print_packet函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论