• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ dump_packet函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

int
main(int argc, char *argv[])
{
	int			 ch, i, r;
	uint16_t		 type = T_A;
	char			 buf[1024], *host;

	while((ch = getopt(argc, argv, "et:")) !=  -1) {
		switch(ch) {
		case 'e':
			long_err += 1;
			break;
		case 't':
			if ((type = strtotype(optarg)) == 0)
				usage();
			break;
		default:
			usage();
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	for (i = 0; i < argc; i++) {

		if (i)
			printf("\n");

		printf("===> \"%s\"\n", argv[i]);
		host = gethostarg(argv[i]);

		errno = 0;
		h_errno = 0;
		gai_errno = 0;
		rrset_errno = 0;

		r = res_mkquery(QUERY, host, C_IN, type, NULL, 0, NULL, buf, sizeof(buf));
		if (r != -1) {
			dump_packet(buf, r);
			printf(";; MSG SIZE %i\n", r);
		}
		print_errors();
	}

	return (0);
}
开发者ID:Basskrapfen,项目名称:openbsd,代码行数:47,代码来源:res_mkquery.c


示例2: dump_to_file

void dump_to_file(struct dump_file *dump_file, 
                  void *pip, 
                  void *plast)
{
    //open a new dump file
    if (dump_file->win_start.tv_sec == -1 &&
        dump_file->win_start.tv_usec == -1) {
        dump_file->fp = new_dump_file(dump_file);
        dump_file->win_start.tv_sec = current_time.tv_sec;
        dump_file->win_start.tv_usec = current_time.tv_usec;
    }
    else if (slice_win > 0) {
        //check if current dump window is ended
        double diff = elapsed(dump_file->win_start, current_time) / 1000000;
        if (diff >= slice_win) {
#ifdef HAVE_ZLIB
	    if (zlib_dump)
             { 
               gzclose(dump_file->fp);
	     }
	    else
#endif
             { 
	       fflush(dump_file->fp);
               fclose(dump_file->fp);
	     }
            dump_file->seq_num++;

            // compute the current timestamp of dumping window
            // considering that there can be windows without traffic
            // associated
            dump_file->win_start.tv_sec += 
                ((long)diff / slice_win) * slice_win;
            dump_file->fp = new_dump_file(dump_file);
        }
    }

    //dump current packet
    dump_packet(dump_file->fp, pip, plast);

    //if (timestamp.tv_sec == -1) {
    //    fprintf(fp_log, "dump start: %s\n", Timestamp());
    //}
    last_dump_tm = current_time;
    if (first_dump_tm.tv_sec == -1) 
        first_dump_tm = current_time;
}
开发者ID:andreaaraldo,项目名称:mytstat,代码行数:47,代码来源:dump.c


示例3: flush_read

int flush_read(struct astribank_device *astribank)
{
	char		tmpbuf[BUFSIZ];
	int		ret;

	DBG("starting...\n");
	memset(tmpbuf, 0, BUFSIZ);
	ret = recv_usb(astribank, tmpbuf, BUFSIZ, 1);
	if(ret < 0 && ret != -ETIMEDOUT) {
		ERR("ret=%d\n", ret);
		return ret;
	} else if(ret > 0) {
		DBG("Got %d bytes:\n", ret);
		dump_packet(LOG_DEBUG, DBG_MASK, __FUNCTION__, tmpbuf, ret);
	}
	return 0;
}
开发者ID:boylubis,项目名称:ctsoft,代码行数:17,代码来源:astribank_usb.c


示例4: xusb_flushread

int xusb_flushread(struct xusb *xusb)
{
	char		tmpbuf[BUFSIZ];
	int		ret;

	DBG("starting...\n");
	memset(tmpbuf, 0, BUFSIZ);
	ret = xusb_recv(xusb, tmpbuf, BUFSIZ, 1);
	if(ret < 0 && ret != -ETIMEDOUT) {
		ERR("ret=%d\n", ret);
		return ret;
	} else if(ret > 0) {
		DBG("Got %d bytes:\n", ret);
		dump_packet(LOG_DEBUG, DBG_MASK, __FUNCTION__, tmpbuf, ret);
	}
	return 0;
}
开发者ID:YongHoJang,项目名称:dahdi-tools,代码行数:17,代码来源:xusb.c


示例5: recv_usb

int recv_usb(const char *msg, struct my_usb_device *mydev, char *buf, size_t len, int timeout)
{
	int	ret;

	if(mydev->my_ep_in & USB_ENDPOINT_OUT) {
		ERR("recv_usb called with an output endpoint 0x%x\n", mydev->my_ep_in);
		return -EINVAL;
	}
	ret = usb_bulk_read(mydev->handle, mydev->my_ep_in, buf, len, timeout);
	if(ret < 0) {
		ERR("bulk_read from endpoint 0x%x failed: %s\n", mydev->my_ep_in, usb_strerror());
		return ret;
	}
	if(verbose >= LOG_DEBUG)
		dump_packet(msg, buf, ret);
	return ret;
}
开发者ID:commshare,项目名称:squeezeterisk,代码行数:17,代码来源:fpga_load.c


示例6: xusb_recv

int xusb_recv(struct xusb *xusb, char *buf, size_t len, int timeout)
{
	int	ret;

	if(EP_IN(xusb) & USB_ENDPOINT_OUT) {
		ERR("%s called with an output endpoint 0x%x\n", __FUNCTION__, EP_IN(xusb));
		return -EINVAL;
	}
	ret = usb_bulk_read(xusb->handle, EP_IN(xusb), buf, len, timeout);
	if(ret < 0) {
		DBG("bulk_read from endpoint 0x%x failed: (%d) %s\n",
			EP_IN(xusb), ret, usb_strerror());
		memset(buf, 0, len);
		return ret;
	}
	dump_packet(LOG_DEBUG, DBG_MASK, __FUNCTION__, buf, ret);
	return ret;
}
开发者ID:YongHoJang,项目名称:dahdi-tools,代码行数:18,代码来源:xusb.c


示例7: test_rtsp

int test_rtsp(char *url)
{
    int err;
    AVFormatContext *ic = NULL;
    AVInputFormat *fmt = &ff_rtsp_demuxer;
    AVFormatParameters params, *ap = &params;
    AVPacket cur_pkt, *pkt = &cur_pkt;

    memset(ap, 0, sizeof(*ap));

    ic = avformat_alloc_context();
    if(ic == NULL)
        return 0;

    ic->iformat = fmt;
    strcpy(ic->filename, url);

    if (fmt->priv_data_size > 0) {
        ic->priv_data = av_mallocz(fmt->priv_data_size);
        if (!ic->priv_data) {
            return 0;
        }
    } else {
        ic->priv_data = NULL;
    }

    err = ic->iformat->read_header(ic, ap);
    if (err < 0)
        return 0;

    while(1) {
        av_init_packet(pkt);
        //err = ic->iformat->read_packet(ic, pkt);
        err = av_read_packet(ic, pkt);
        if (err < 0)
            return 0;
        printf("stream: %d, len: %d, pts: %lld\n", pkt->stream_index, pkt->size, pkt->pts);
        dump_packet(pkt);
        if (pkt->destruct) pkt->destruct(pkt);
        pkt->data = NULL; pkt->size = 0;
    }

    return 1;
}
开发者ID:FreeSrk,项目名称:omx,代码行数:44,代码来源:test.c


示例8: TRACE

status_t
IPCP::Send(struct mbuf *packet, uint16 protocolNumber)
{
	TRACE("IPCP: Send(0x%X)\n", protocolNumber);
	
	if((protocolNumber == IP_PROTOCOL && State() == PPP_OPENED_STATE)
			|| protocolNumber == IPCP_PROTOCOL) {
#if DEBUG
		dump_packet(packet, "outgoing");
#endif
		Interface().UpdateIdleSince();
		return SendToNext(packet, protocolNumber);
	}
	
	ERROR("IPCP: Send() failed because of wrong state or protocol number!\n");
	
	m_freem(packet);
	return B_ERROR;
}
开发者ID:DonCN,项目名称:haiku,代码行数:19,代码来源:Protocol.cpp


示例9: dump_packet

status_t
IPCP::ReceiveIPPacket(struct mbuf *packet, uint16 protocolNumber)
{
	if(protocolNumber != IP_PROTOCOL || State() != PPP_OPENED_STATE)
		return PPP_UNHANDLED;
	
	// TODO: add VJC support (the packet would be decoded here)
	
	if (gProto[IPPROTO_IP] && gProto[IPPROTO_IP]->pr_input) {
#if DEBUG
		dump_packet(packet, "incoming");
#endif
		Interface().UpdateIdleSince();
		gProto[IPPROTO_IP]->pr_input(packet, 0);
		return B_OK;
	} else {
		ERROR("IPCP: Error: Could not find input function for IP!\n");
		m_freem(packet);
		return B_ERROR;
	}
}
开发者ID:DonCN,项目名称:haiku,代码行数:21,代码来源:Protocol.cpp


示例10: hvsi_recv_response

static void hvsi_recv_response(struct hvsi_struct *hp, uint8_t *packet)
{
	struct hvsi_query_response *resp = (struct hvsi_query_response *)packet;

	switch (hp->state) {
		case HVSI_WAIT_FOR_VER_RESPONSE:
			__set_state(hp, HVSI_WAIT_FOR_VER_QUERY);
			break;
		case HVSI_WAIT_FOR_MCTRL_RESPONSE:
			hp->mctrl = 0;
			if (resp->u.mctrl_word & HVSI_TSDTR)
				hp->mctrl |= TIOCM_DTR;
			if (resp->u.mctrl_word & HVSI_TSCD)
				hp->mctrl |= TIOCM_CD;
			__set_state(hp, HVSI_OPEN);
			break;
		default:
			printk(KERN_ERR "hvsi%i: unexpected query response: ", hp->index);
			dump_packet(packet);
			break;
	}
}
开发者ID:Antonio-Zhou,项目名称:Linux-2.6.11,代码行数:22,代码来源:hvsi.c


示例11: ipt_log_packet

static void
ipt_log_packet(u_int8_t pf,
	       unsigned int hooknum,
	       const struct sk_buff *skb,
	       const struct net_device *in,
	       const struct net_device *out,
	       const struct nf_loginfo *loginfo,
	       const char *prefix)
{
	struct sbuff *m = sb_open();

	if (!loginfo)
		loginfo = &default_loginfo;

	sb_add(m, "<%d>%sIN=%s OUT=%s ", loginfo->u.log.level,
	       prefix,
	       in ? in->name : "",
	       out ? out->name : "");
#ifdef CONFIG_BRIDGE_NETFILTER
	if (skb->nf_bridge) {
		const struct net_device *physindev;
		const struct net_device *physoutdev;

		physindev = skb->nf_bridge->physindev;
		if (physindev && in != physindev)
			sb_add(m, "PHYSIN=%s ", physindev->name);
		physoutdev = skb->nf_bridge->physoutdev;
		if (physoutdev && out != physoutdev)
			sb_add(m, "PHYSOUT=%s ", physoutdev->name);
	}
#endif

	if (in != NULL)
		dump_mac_header(m, loginfo, skb);

	dump_packet(m, loginfo, skb, 0);

	sb_close(m);
}
开发者ID:faux123,项目名称:pantech_vega_racer_2_kernel,代码行数:39,代码来源:ipt_LOG.c


示例12: l2cap_send_connectionless

int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t * buffer, uint16_t len) {
    // printf("l2cap_send_connectionless\n");

    int pb = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;

    // 0 - Connection handle : PB=pb : BC=00
    bt_store_16(packet_buffer, 0, handle | (pb << 12) | (0 << 14));
    // 2 - ACL length
    bt_store_16(packet_buffer, 2,  len + 4);
    // 4 - L2CAP packet length
    bt_store_16(packet_buffer, 4,  len + 0);
    // 6 - L2CAP channel DEST
    bt_store_16(packet_buffer, 6, cid);

    memcpy(&packet_buffer[8], buffer, len);
    hci_dump_packet(HCI_ACL_DATA_PACKET, 0, &packet_buffer[0], len + 8);

    dump_packet(HCI_ACL_DATA_PACKET, packet_buffer, len + 8);
    packet_buffer_len = len + 8;

    return 0;
}
开发者ID:ChangeTsai,项目名称:btstack,代码行数:22,代码来源:mock.c


示例13: ether_do_interrupt

static void ether_do_interrupt(void)
{
	// Call protocol handler for received packets
	EthernetPacket ether_packet;
	uint32 packet = ether_packet.addr();
	ssize_t length;
	for (;;) {

		// Read packet from Ethernet device
		length = dequeue_packet(Mac2HostAddr(packet));
		if (length < 14)
			break;

#if MONITOR
		bug("Receiving Ethernet packet (%d bytes):\n",(int)length);
		dump_packet( Mac2HostAddr(packet), length );
#endif

		// Dispatch packet
		ether_dispatch_packet(packet, length);
	}
}
开发者ID:tycho,项目名称:sheepshaver,代码行数:22,代码来源:ether_windows.cpp


示例14: nl2_send

int nl2_send(int sock, struct sockaddr_in *addr, znl2msg *msg)
{
    int i;
    int len;
    uint32_t* store;
    znl2msg *flipped;

    if (verbose >= 1)
      fprintf(stdout, "%s: sending %d bytes (message #%d %s) to %s:%d\n",
              progname,
              msg->n.znl2msg_len,
              msg->n.znl2msg_seq, type2s(msg->n.znl2msg_type),
              inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));

    /* 
     * Make a copy of msg before byte flipping it. We're preserving the
     * original so that we can compare the request & reply headers.
     */
    len = msg->n.znl2msg_len;
    flipped = malloc(len);
    memcpy(flipped, msg, len);

    /* Endianess/byte ordering */
    store = (uint32_t*) flipped;
    if (flipped->n.znl2msg_type == ZNL2_SYN || flipped->n.znl2msg_type == ZNL2_FIN) {
        for (i = 0; i < (sizeof(znl2msghdr)/4+2); i++)
            store[i] = psdb_pton(store[i]);
    } else {
        for (i = 0; i < (len/4); i++)
            store[i] = psdb_pton(store[i]);
    }

    if (verbose >= 3)
        dump_packet(flipped, len);

    return sendto(sock, flipped, len, 0, (struct sockaddr *)addr,
                  sizeof(struct sockaddr_in));
}
开发者ID:elambert,项目名称:honeycomb,代码行数:38,代码来源:send.c


示例15: do_uncook_loop

void do_uncook_loop(struct anonflow *flow, struct function *flist)
{
	flist_node_t   *fn;
	struct function *next_func;
	struct headers_data *frag_data;

	flow->uncook_ready = 0;

	for (fn = flist_head(flow->client_headers); fn != NULL; fn = flist_next(fn)) {
		anon_pkthdr_t   frag_pkt_head;
		flow->decoded_packet = NULL;

		frag_data = (struct headers_data *)(fn->data);
		//fprintf(stderr,"(%d) frag_data->caplen: %d %d %x\n",ff++,frag_data->caplen,flist_size(flow->headers),frag_data);

		frag_pkt_head.caplen = frag_data->caplen;
		frag_pkt_head.wlen = frag_data->wlen;
		frag_pkt_head.ts.tv_sec = frag_data->ts.tv_sec;
		frag_pkt_head.ts.tv_usec = frag_data->ts.tv_usec;

		next_func = flist->next;

		while (next_func) {
			if (next_func->function_info->
			    process(flow, next_func->internal_data, frag_data->header,
				    &frag_pkt_head) == 0) {
				break;
			}
			next_func = next_func->next;
		}

		if (next_func == NULL && flow->output_type != NONE) {	//Flow reached its end
			dump_packet(flow, frag_data->header, &frag_pkt_head);
		}
	}

	return;
}
开发者ID:abhisoniks,项目名称:anontool-modified,代码行数:38,代码来源:tool.c


示例16: log_data

void log_data( FILE *file )
{
    Huint   size;
    Huint   data[ ETH_MTU_WORD ];
    
    while( 1 )
    {
        memset( data, 0, sizeof(Huint)*size );

        show_operation( oper_win, "Waiting for Header..." );
        box( oper_win, 0, 0 );
        wrefresh( oper_win );
        eth_recv( (Hubyte*)&size, sizeof(Huint) );
        size = ntohl( size );

        show_operation( oper_win, "Waiting for Data..." );
        box( oper_win, 0, 0 );
        wrefresh( oper_win );
        eth_recv( (Hubyte*)data, size*sizeof(Huint) );

        dump_packet( size, data, file );
    }
}
开发者ID:mafzzz,项目名称:heterogeneous_hthreads,代码行数:23,代码来源:pcap.c


示例17: write_packet

static int
write_packet(int  fd, const char* name, apacket** ppacket)
{
    char buff[8];
    if (!name) {
        snprintf(buff, sizeof buff, "fd=%d", fd);
        name = buff;
    }
    VLOG(TRANSPORT) << dump_packet(name, "to remote", *ppacket);
    char* p = reinterpret_cast<char*>(ppacket);  /* we really write the packet address */
    int len = sizeof(apacket*);
    while(len > 0) {
        int r = adb_write(fd, p, len);
        if(r > 0) {
            len -= r;
            p += r;
        } else {
            D("%s: write_packet (fd=%d) error ret=%d: %s", name, fd, r, strerror(errno));
            return -1;
        }
    }
    return 0;
}
开发者ID:sprindy,项目名称:platform_system_core,代码行数:23,代码来源:transport.cpp


示例18: dump_packet

/* One level of recursion won't kill us */
static void dump_packet(const struct nf_loginfo *info,
			const struct sk_buff *skb,
			unsigned int iphoff)
{
	struct iphdr _iph;
	const struct iphdr *ih;
	unsigned int logflags;

	if (info->type == NF_LOG_TYPE_LOG)
		logflags = info->u.log.logflags;
	else
		logflags = NF_LOG_MASK;

	ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
	if (ih == NULL) {
		printk("TRUNCATED");
		return;
	}

	/* Important fields:
	 * TOS, len, DF/MF, fragment offset, TTL, src, dst, options. */
	/* Max length: 40 "SRC=255.255.255.255 DST=255.255.255.255 " */
	printk("SRC=%pI4 DST=%pI4 ",
	       &ih->saddr, &ih->daddr);

	/* Max length: 46 "LEN=65535 TOS=0xFF PREC=0xFF TTL=255 ID=65535 " */
	printk("LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u ",
	       ntohs(ih->tot_len), ih->tos & IPTOS_TOS_MASK,
	       ih->tos & IPTOS_PREC_MASK, ih->ttl, ntohs(ih->id));

	/* Max length: 6 "CE DF MF " */
	if (ntohs(ih->frag_off) & IP_CE)
		printk("CE ");
	if (ntohs(ih->frag_off) & IP_DF)
		printk("DF ");
	if (ntohs(ih->frag_off) & IP_MF)
		printk("MF ");

	/* Max length: 11 "FRAG:65535 " */
	if (ntohs(ih->frag_off) & IP_OFFSET)
		printk("FRAG:%u ", ntohs(ih->frag_off) & IP_OFFSET);

	if ((logflags & IPT_LOG_IPOPT) &&
	    ih->ihl * 4 > sizeof(struct iphdr)) {
		const unsigned char *op;
		unsigned char _opt[4 * 15 - sizeof(struct iphdr)];
		unsigned int i, optsize;

		optsize = ih->ihl * 4 - sizeof(struct iphdr);
		op = skb_header_pointer(skb, iphoff+sizeof(_iph),
					optsize, _opt);
		if (op == NULL) {
			printk("TRUNCATED");
			return;
		}

		/* Max length: 127 "OPT (" 15*4*2chars ") " */
		printk("OPT (");
		for (i = 0; i < optsize; i++)
			printk("%02X", op[i]);
		printk(") ");
	}

	switch (ih->protocol) {
	case IPPROTO_TCP: {
		struct tcphdr _tcph;
		const struct tcphdr *th;

		/* Max length: 10 "PROTO=TCP " */
		printk("PROTO=TCP ");

		if (ntohs(ih->frag_off) & IP_OFFSET)
			break;

		/* Max length: 25 "INCOMPLETE [65535 bytes] " */
		th = skb_header_pointer(skb, iphoff + ih->ihl * 4,
					sizeof(_tcph), &_tcph);
		if (th == NULL) {
			printk("INCOMPLETE [%u bytes] ",
			       skb->len - iphoff - ih->ihl*4);
			break;
		}

		/* Max length: 20 "SPT=65535 DPT=65535 " */
		printk("SPT=%u DPT=%u ",
		       ntohs(th->source), ntohs(th->dest));
		/* Max length: 30 "SEQ=4294967295 ACK=4294967295 " */
		if (logflags & IPT_LOG_TCPSEQ)
			printk("SEQ=%u ACK=%u ",
			       ntohl(th->seq), ntohl(th->ack_seq));
		/* Max length: 13 "WINDOW=65535 " */
		printk("WINDOW=%u ", ntohs(th->window));
		/* Max length: 9 "RES=0x3F " */
		printk("RES=0x%02x ", (u8)(ntohl(tcp_flag_word(th) & TCP_RESERVED_BITS) >> 22));
		/* Max length: 32 "CWR ECE URG ACK PSH RST SYN FIN " */
		if (th->cwr)
			printk("CWR ");
		if (th->ece)
			printk("ECE ");
//.........这里部分代码省略.........
开发者ID:12rafael,项目名称:jellytimekernel,代码行数:101,代码来源:ipt_LOG.c


示例19: main


//.........这里部分代码省略.........
    question->QCLASS = htons(0x0001);

    int packetSize = 0;
    //copy header into packet
    memcpy( packetDNS, header,  sizeof(dnsheader) );
    packetSize += sizeof(dnsheader);

    //copy qname into packet
    int length = strlen(name);
    char* period = NULL;
    *( name + length ) = '.';
    *( name + length + 1 ) = 0;
    while ( (period = strchr(name, '.')) != 0 ) {
        *period = 0;
        length = strlen(name);
        memcpy( packetDNS + packetSize, &length, 1 );
        packetSize++;
        memcpy( packetDNS + packetSize, name, length);
        packetSize += length;
        name = period + 1;
    }

    //copy zero byte at end of qname
    char zeroByte = 0;
    memcpy( packetDNS + packetSize, &zeroByte, 1 );
    packetSize++;

    //copy question into packet
    memcpy( packetDNS + packetSize, question, sizeof(dnsquestion) );
    packetSize += sizeof(dnsquestion);


    // send the DNS request (and call dump_packet with your request)
    dump_packet( packetDNS, packetSize );

    // first, open a UDP socket
    int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

    // next, construct the destination address
    struct sockaddr_in out;
    out.sin_family = AF_INET;
    out.sin_port = htons( (short) port );
    out.sin_addr.s_addr = inet_addr(server);

    if (sendto(sock, packetDNS, packetSize, 0, (struct sockaddr*)&out, sizeof(out)) < 0) {
        printf("Error occured in sendto\n");
        return -1;
    }

    //Clear question buffer to use for answer buffer in the future
    memset( packetDNS, 0, MAX_IP_PACKET_SIZE );
    memset( question, 0, sizeof(dnsquestion) );
    memset( header, 0, sizeof(dnsheader) );
    packetSize = 0;

    // wait for the DNS reply (timeout: 5 seconds)
    struct sockaddr_in in;
    socklen_t in_len;

    // construct the socket set
    fd_set socks;
    FD_ZERO(&socks);
    FD_SET(sock, &socks);

    // construct the timeout
    struct timeval t;
开发者ID:knuevena,项目名称:3600dns,代码行数:67,代码来源:3600dns.c


示例20: parse_packet


//.........这里部分代码省略.........
            return;
    }

    // Only interested in UDP packets
    if (ip_proto == IPPROTO_UDP) {
        // Get UDP header
        udp = (struct udphdr *)((u_char *)(ip4) + ip_hl);
        udp_off = (ip_frag_off) ? 0 : sizeof(struct udphdr);

        // Set packet ports
        sport = htons(udp->uh_sport);
        dport = htons(udp->uh_dport);

        // Get actual payload size
        size_payload -= capinfo.link_hl + ip_hl + udp_off;

#ifdef WITH_IPV6
        if (ip_ver == 6)
            size_payload -= ntohs(ip6->ip6_ctlun.ip6_un1.ip6_un1_plen);
#endif
        // Get payload start
        payload = (u_char *) (udp) + udp_off;

        // Set transport UDP
        transport = CAPTURE_PACKET_SIP_UDP;

    } else if (ip_proto == IPPROTO_TCP) {
        // Get TCP header
        tcp = (struct tcphdr *)((u_char *)(ip4 )+ ip_hl);
        tcp_off = (ip_frag_off) ? 0 : (tcp->th_off * 4);

        // Set packet ports
        sport = htons(tcp->th_sport);
        dport = htons(tcp->th_dport);

        // Get actual payload size
        size_payload -= capinfo.link_hl + ip_hl + tcp_off;

#ifdef WITH_IPV6
        if (ip_ver == 6)
            size_payload -= ntohs(ip6->ip6_ctlun.ip6_un1.ip6_un1_plen);
#endif
        // Get payload start
        payload = (u_char *)(tcp) + tcp_off;

        // Set transport TCP
        transport = CAPTURE_PACKET_SIP_TCP;
    } else {
        // Not handled protocol
        return;
    }

    if ((int32_t)size_payload < 0)
        size_payload = 0;

    // Create a structure for this captured packet
    pkt = capture_packet_create(header, packet, header->caplen);
    capture_packet_set_type(pkt, transport);
    // For TCP and UDP, use payload directly from the packet
    capture_packet_set_payload(pkt, NULL, size_payload);

#ifdef WITH_OPENSSL
    // Check if packet is TLS
    if (capinfo.keyfile && transport == CAPTURE_PACKET_SIP_TCP)
        tls_process_segment(ip4, pkt);
#endif

    // Check if packet is WS or WSS
    if (transport == CAPTURE_PACKET_SIP_TCP)
        capture_ws_check_packet(pkt);

    // We're only interested in packets with payload
    if (capture_packet_get_payload_len(pkt)) {
        // Parse this header and payload
        if (sip_load_message(pkt, ip_src, sport, ip_dst, dport)) {
            // Store this packets in output file
            dump_packet(capinfo.pd, header, packet);
            return;
        }

        // Check if this packet belongs to a RTP stream
        // TODO Store this packet in the stream
        if ((stream = rtp_check_stream(pkt, ip_src, sport, ip_dst, dport))) {
            // We have an RTP packet!
            capture_packet_set_type(pkt, CAPTURE_PACKET_RTP);
            // Store this pacekt if capture rtp is enabled
            if (capinfo.rtp_capture) {
                call_add_rtp_packet(stream_get_call(stream), pkt);
            } else {
                capture_packet_destroy(pkt);
            }
            // Store this packets in output file
            dump_packet(capinfo.pd, header, packet);
            return;
        }
    }

    // Not an interesting packet ...
    capture_packet_destroy(pkt);
}
开发者ID:jungle-boogie,项目名称:sngrep,代码行数:101,代码来源:capture.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ dump_registers函数代码示例发布时间:2022-05-30
下一篇:
C++ dump_node函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap