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

C++ IP_V函数代码示例

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

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



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

示例1: sl_if_print

u_int
sl_if_print(const struct pcap_pkthdr *h, const u_char *p)
{
	register u_int caplen = h->caplen;
	register u_int length = h->len;
	register const struct ip *ip;

	if (caplen < SLIP_HDRLEN) {
		printf("[|slip]");
		return (caplen);
	}

	length -= SLIP_HDRLEN;

	ip = (struct ip *)(p + SLIP_HDRLEN);

	if (eflag)
		sliplink_print(p, ip, length);

	switch (IP_V(ip)) {
	case 4:
	        ip_print(gndo, (u_char *)ip, length);
		break;
#ifdef INET6
	case 6:
		ip6_print((u_char *)ip, length);
		break;
#endif
	default:
		printf ("ip v%d", IP_V(ip));
	}

	return (SLIP_HDRLEN);
}
开发者ID:904498910,项目名称:ARO,代码行数:34,代码来源:print-sl.c


示例2: sl_if_print

u_int
sl_if_print(netdissect_options *ndo,
            const struct pcap_pkthdr *h, const u_char *p)
{
	register u_int caplen = h->caplen;
	register u_int length = h->len;
	register const struct ip *ip;

	if (caplen < SLIP_HDRLEN || length < SLIP_HDRLEN) {
		ND_PRINT((ndo, "%s", tstr));
		return (caplen);
	}

	length -= SLIP_HDRLEN;

	ip = (struct ip *)(p + SLIP_HDRLEN);

	if (ndo->ndo_eflag)
		sliplink_print(ndo, p, ip, length);

	switch (IP_V(ip)) {
	case 4:
	        ip_print(ndo, (u_char *)ip, length);
		break;
	case 6:
		ip6_print(ndo, (u_char *)ip, length);
		break;
	default:
		ND_PRINT((ndo, "ip v%d", IP_V(ip)));
	}

	return (SLIP_HDRLEN);
}
开发者ID:Longinus00,项目名称:tcpdump,代码行数:33,代码来源:print-sl.c


示例3: assign_addr_pair

/**
 * Creates an addr_pair from an ip (and tcp/udp) header, swapping src and dst
 * if required
 */
void assign_addr_pair(addr_pair* ap, struct ip* iptr, int flip) {
  unsigned short int src_port = 0;
  unsigned short int dst_port = 0;

  /* Arrange for predictable values. */
  memset(ap, '\0', sizeof(*ap));

  if(IP_V(iptr) == 4) {
    ap->af = AF_INET;
  /* Does this protocol use ports? */
  if(iptr->ip_p == IPPROTO_TCP || iptr->ip_p == IPPROTO_UDP) {
    /* We take a slight liberty here by treating UDP the same as TCP */

    /* Find the TCP/UDP header */
    struct tcphdr* thdr = ((void*)iptr) + IP_HL(iptr) * 4;
    src_port = ntohs(thdr->th_sport);
    dst_port = ntohs(thdr->th_dport);
  }

  if(flip == 0) {
    ap->src = iptr->ip_src;
    ap->src_port = src_port;
    ap->dst = iptr->ip_dst;
    ap->dst_port = dst_port;
  }
  else {
    ap->src = iptr->ip_dst;
    ap->src_port = dst_port;
    ap->dst = iptr->ip_src;
    ap->dst_port = src_port;
  }
  } /* IPv4 */
  else if (IP_V(iptr) == 6) {
    /* IPv6 packet seen. */
    struct ip6_hdr *ip6tr = (struct ip6_hdr *) iptr;

    ap->af = AF_INET6;

    if( (ip6tr->ip6_nxt == IPPROTO_TCP) || (ip6tr->ip6_nxt == IPPROTO_UDP) ) {
      struct tcphdr *thdr = ((void *) ip6tr) + 40;

      src_port = ntohs(thdr->th_sport);
      dst_port = ntohs(thdr->th_dport);
    }

    if(flip == 0) {
      memcpy(&ap->src6, &ip6tr->ip6_src, sizeof(ap->src6));
      ap->src_port = src_port;
      memcpy(&ap->dst6, &ip6tr->ip6_dst, sizeof(ap->dst6));
      ap->dst_port = dst_port;
    }
    else {
      memcpy(&ap->src6, &ip6tr->ip6_dst, sizeof(ap->src6));
      ap->src_port = dst_port;
      memcpy(&ap->dst6, &ip6tr->ip6_src, sizeof(ap->dst6));
      ap->dst_port = src_port;
    }
  }
}
开发者ID:dove0rz,项目名称:iftop-android,代码行数:63,代码来源:iftop.c


示例4: print_nfsaddr

static void
print_nfsaddr(netdissect_options *ndo,
              const u_char *bp, const char *s, const char *d)
{
	const struct ip *ip;
	const struct ip6_hdr *ip6;
	char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];

	srcaddr[0] = dstaddr[0] = '\0';
	switch (IP_V((const struct ip *)bp)) {
	case 4:
		ip = (const struct ip *)bp;
		strlcpy(srcaddr, ipaddr_string(ndo, &ip->ip_src), sizeof(srcaddr));
		strlcpy(dstaddr, ipaddr_string(ndo, &ip->ip_dst), sizeof(dstaddr));
		break;
	case 6:
		ip6 = (const struct ip6_hdr *)bp;
		strlcpy(srcaddr, ip6addr_string(ndo, &ip6->ip6_src),
		    sizeof(srcaddr));
		strlcpy(dstaddr, ip6addr_string(ndo, &ip6->ip6_dst),
		    sizeof(dstaddr));
		break;
	default:
		strlcpy(srcaddr, "?", sizeof(srcaddr));
		strlcpy(dstaddr, "?", sizeof(dstaddr));
		break;
	}

	ND_PRINT("%s.%s > %s.%s: ", srcaddr, s, dstaddr, d);
}
开发者ID:lampmanyao,项目名称:tcpdump,代码行数:30,代码来源:print-nfs.c


示例5: getIpHeader

int getIpHeader (struct ip *ip_b, u_int32_t *proto, u_int16_t *id,
		u_int32_t *len, u_int32_t *src, u_int32_t *dst)
{
	u_int32_t *ip = (u_int32_t *) ip_b;
	u_int32_t off;

	/*
	 * If it's not IPv4, then we're completely lost.
	 */

	if (IP_V (ip_b) != 4) {
		return (-1);
	}

	/*
	 * If this isn't fragment zero of an higher-level "packet",
	 * then it's not something that we're interested in, so dump
	 * it.
	 */

	off = ntohs(ip_b->ip_off);
	if ((off & 0x1fff) != 0) {
		printf("# it's a fragment (offset=%d) of %d\n",
				(off & 0x1fff), ntohs(ip_b->ip_len));
		return (0);
	}

	*proto = ip_b->ip_p;
	*len = ntohs (ip_b->ip_len);
	*src = ntohl (ip [3]);
	*dst = ntohl (ip [4]);
	*id = ntohs (ip_b->ip_id);

	return (IP_HL (ip_b) * 4);
}
开发者ID:yoursunny,项目名称:nfsdump,代码行数:35,代码来源:iprecord.c


示例6: xid_map_find

/*
 * Returns 0 and puts NFSPROC_xxx in proc return and
 * version in vers return, or returns -1 on failure
 */
static int
xid_map_find(const struct sunrpc_msg *rp, const u_char *bp, u_int32_t *proc,
	     u_int32_t *vers)
{
	int i;
	struct xid_map_entry *xmep;
	u_int32_t xid = rp->rm_xid;
	struct ip *ip = (struct ip *)bp;
#ifdef INET6
	struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
#endif
	int cmp;

	/* Start searching from where we last left off */
	i = xid_map_hint;
	do {
		xmep = &xid_map[i];
		cmp = 1;
		if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
			goto nextitem;
		switch (xmep->ipver) {
		case 4:
			if (memcmp(&ip->ip_src, &xmep->server,
				   sizeof(ip->ip_src)) != 0 ||
			    memcmp(&ip->ip_dst, &xmep->client,
				   sizeof(ip->ip_dst)) != 0) {
				cmp = 0;
			}
			break;
#ifdef INET6
		case 6:
			if (memcmp(&ip6->ip6_src, &xmep->server,
				   sizeof(ip6->ip6_src)) != 0 ||
			    memcmp(&ip6->ip6_dst, &xmep->client,
				   sizeof(ip6->ip6_dst)) != 0) {
				cmp = 0;
			}
			break;
#endif
		default:
			cmp = 0;
			break;
		}
		if (cmp) {
			/* match */
			xid_map_hint = i;
			*proc = xmep->proc;
			*vers = xmep->vers;
			return 0;
		}
	nextitem:
		if (++i >= XIDMAPSIZE)
			i = 0;
	} while (i != xid_map_hint);

	/* search failed */
	return (-1);
}
开发者ID:cherry-wb,项目名称:tcpdump,代码行数:62,代码来源:print-nfs.c


示例7: sizeof

u_char* handle_IP
        (u_char *args,const struct pcap_pkthdr* pkthdr,const u_char*
        packet)
{
    const struct my_ip* ip;
    u_int length = pkthdr->len;
    u_int hlen,off,version;
    int i;

    int len;

    /* jump pass the ethernet header */
    ip = (struct my_ip*)(packet + sizeof(struct ether_header));
    length -= sizeof(struct ether_header);

    /* check to see we have a packet of valid length */
    if (length < sizeof(struct my_ip))
    {
        printf("truncated ip %d",length);
        return NULL;
    }

    len     = ntohs(ip->ip_len);
    hlen    = IP_HL(ip); /* header length */
    version = IP_V(ip);/* ip version */

    /* check version */
    if(version != 4)
    {
      fprintf(stdout,"Unknown version %d\n",version);
      return NULL;
    }

    /* check header length */
    if(hlen < 5 )
    {
        fprintf(stdout,"bad-hlen %d \n",hlen);
    }

    /* see if we have as much packet as we should */
    if(length < len)
        printf("\ntruncated IP - %d bytes missing\n",len - length);

    /* Check to see if we have the first fragment */
    off = ntohs(ip->ip_off);
    if((off & 0x1fff) == 0 )/* aka no 1's in first 13 bits */
    {/* print SOURCE DESTINATION hlen version len offset */
        fprintf(stdout,"IP: ");
        fprintf(stdout,"%s ",
                inet_ntoa(ip->ip_src));
        fprintf(stdout,"%s %d %d %d %d\n",
                inet_ntoa(ip->ip_dst),
                hlen,version,len,off);
    }

    return NULL;
}
开发者ID:SIDNEYRDC,项目名称:Sources,代码行数:57,代码来源:disect2.c


示例8: prepare_raw

void prepare_raw(packetinfo *pi)
{
    pi->eth_hlen = 0;
    if (IP_V((ip4_header *)pi->packet) == 4) {
        pi->eth_type = ETHERNET_TYPE_IP;
    }
    else {
        pi->eth_type = ETHERNET_TYPE_IPV6;
    }
}
开发者ID:gavinspearhead,项目名称:passivedns,代码行数:10,代码来源:passivedns.c


示例9: prepare_sll

void prepare_sll(packetinfo *pi)
{
    pi->eth_hlen = SLL_HDR_LEN;

    if (IP_V((ip4_header *)(pi->packet + SLL_HDR_LEN)) == 4) {
        pi->eth_type = ETHERNET_TYPE_IP;
    }
    else {
        pi->eth_type = ETHERNET_TYPE_IPV6;
    }
}
开发者ID:gavinspearhead,项目名称:passivedns,代码行数:11,代码来源:passivedns.c


示例10: parse_http_packet

void parse_http_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *pkt) {
    char *header_line, *req_value;
    int is_request = 0, is_response = 0;

    const struct ip_header *ip;
    const struct tcp_header *tcp;
    const char *data;
    int ip_headlen, tcp_headlen, data_len, family;

    ip = (struct ip_header *) (pkt + link_header_offset);

    switch (IP_V(ip)) {
    case 4:
        family = AF_INET;
        break;
    default:
        return;
    }
    ip_headlen = IP_HL(ip) * 4;
    if (ip_headlen < 20) return;
    if (ip->ip_p != IPPROTO_TCP) return;

    tcp = (struct tcp_header *) ((char *)ip + ip_headlen);
    tcp_headlen = TH_OFF(tcp) * 4;
    if (tcp_headlen< 20) return;

    data = (char *)tcp + tcp_headlen;
    data_len = (header->caplen - (link_header_offset + ip_headlen + tcp_headlen));
    if (data_len <= 0) return;

    if (have_request_method(data)) {
        is_request = 1;
    } else if (strncmp(data, "HTTP/", strlen("HTTP/")) == 0) {
        is_response = 1;
    } else {
        return;
    }

    if (data_len > BUFSIZ) data_len = BUFSIZ;
    memcpy(buf, data, data_len);
    buf[data_len-1] = '\0';

    if (is_request) {
        char *p = strchr(buf, '?');
        if(p) *p = '\0';
        debug_ascii(buf, data_len, "TEST" );
    }
    else if (is_response) {
    }

    return;
}
开发者ID:kuaikuai,项目名称:httpcap,代码行数:52,代码来源:test_cap.c


示例11: xid_map_enter

static int
xid_map_enter(netdissect_options *ndo,
              const struct sunrpc_msg *rp, const u_char *bp)
{
	struct ip *ip = NULL;
#ifdef INET6
	struct ip6_hdr *ip6 = NULL;
#endif
	struct xid_map_entry *xmep;

	if (!ND_TTEST(rp->rm_call.cb_vers))
		return (0);
	switch (IP_V((struct ip *)bp)) {
	case 4:
		ip = (struct ip *)bp;
		break;
#ifdef INET6
	case 6:
		ip6 = (struct ip6_hdr *)bp;
		break;
#endif
	default:
		return (1);
	}

	xmep = &xid_map[xid_map_next];

	if (++xid_map_next >= XIDMAPSIZE)
		xid_map_next = 0;

	UNALIGNED_MEMCPY(&xmep->xid, &rp->rm_xid, sizeof(xmep->xid));
	if (ip) {
		xmep->ipver = 4;
		UNALIGNED_MEMCPY(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
		UNALIGNED_MEMCPY(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
	}
#ifdef INET6
	else if (ip6) {
		xmep->ipver = 6;
		UNALIGNED_MEMCPY(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
		UNALIGNED_MEMCPY(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
	}
#endif
	xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
	xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
	return (1);
}
开发者ID:Longinus00,项目名称:tcpdump,代码行数:47,代码来源:print-nfs.c


示例12: xid_map_enter

static void
xid_map_enter(const struct sunrpc_msg *rp, const u_char *bp)
{
	struct ip *ip = NULL;
#ifdef INET6
	struct ip6_hdr *ip6 = NULL;
#endif
	struct xid_map_entry *xmep;

	switch (IP_V((struct ip *)bp)) {
	case 4:
		ip = (struct ip *)bp;
		break;
#ifdef INET6
	case 6:
		ip6 = (struct ip6_hdr *)bp;
		break;
#endif
	default:
		return;
	}

	xmep = &xid_map[xid_map_next];

	if (++xid_map_next >= XIDMAPSIZE)
		xid_map_next = 0;

	xmep->xid = rp->rm_xid;
	if (ip) {
		xmep->ipver = 4;
		memcpy(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
		memcpy(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
	}
#ifdef INET6
	else if (ip6) {
		xmep->ipver = 6;
		memcpy(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
		memcpy(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
	}
#endif
	xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
	xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
}
开发者ID:0omega,项目名称:platform_external_tcpdump,代码行数:43,代码来源:print-nfs.c


示例13: reaper_rtcp_format

static int
reaper_rtcp_format(const struct ip *ip, int sport, int dport, const char* data, int len)
{
   char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
   char *buffer = reaper_packet_buffer_rtcp;
#ifdef INET6
   if (IP_V(ip) == 6) {
      const struct ip6_hdr *ip6;
      ip6 = (const struct ip6_hdr *)ip;
      buffer += sprintf(reaper_packet_buffer_rtcp, FORMAT,
        reaper_source_mac,
        ip6addr_string(&ip6->ip6_src),
        udpport_string(sport),
        reaper_destination_mac,
        ip6addr_string(&ip6->ip6_dst),
        udpport_string(dport));
   }
   else {
#endif /*INET6*/
      buffer += sprintf(reaper_packet_buffer_rtcp, FORMAT,
         reaper_source_mac,
         ipaddr_string(&ip->ip_src),
         udpport_string(sport),
         reaper_destination_mac,
         ipaddr_string(&ip->ip_dst),
         udpport_string(dport));
#ifdef INET6
   }
#endif /*INET6*/
   fprintf(stderr, "Sending RTCP packet <%s>\n", reaper_packet_buffer_rtcp);
   char *end_buffer = reaper_packet_buffer_rtcp + sizeof(reaper_packet_buffer_rtcp) - 3;
   const char *end_data = data + len;
   while (data < end_data) {
      *(buffer++) = hex[((*data >> 4) & 0xF)];
      *(buffer++) = hex[(*data & 0xF)];
      if (buffer >= end_buffer)
          break;
      ++data;
   }
   *(buffer++) = '\n';
   *(buffer) = '\0';
   return (buffer - reaper_packet_buffer_rtcp);
}
开发者ID:ishmaelen,项目名称:Reaper,代码行数:43,代码来源:reaper.c


示例14: handle_IP

uint16_t handle_IP (u_char *args,const struct pcap_pkthdr* hdr,
      const u_char *packet){
   const struct my_ip *ip;
   u_int length =hdr->len;
   u_int hlen, off, version;
   
   int len;

   ip =(struct my_ip*)(packet+sizeof(struct ether_header));
   length-=sizeof(struct ether_header);

   // if IP hdr is smaller than the normal
   if(length < sizeof(struct my_ip)){
      printf("truncated ip %d",length);
      return -1;
   }

   len =ntohs(ip->ip_len);
   hlen =IP_HL(ip);
   version =IP_V(ip);

   if(version != 4){
      printf("Unknown version\n");
      return -1;
   }

   if(hlen < 5){
      printf("error in IHL\n");
      return -1;
   }

   if(length < len)
      printf("\ntruncated IP - %d bytes missing\n", len-length);
   off =ntohs(ip->ip_off);
   
   printf("IP: ");
   printf("%s ",inet_ntoa(ip->ip_src));
   printf("%s %d %d %d %d\n",inet_ntoa(ip->ip_dst),hlen,version,
         len,off);

   return (uint16_t)ip->ip_p;
}
开发者ID:pablosistemas,项目名称:temp,代码行数:42,代码来源:loopcap.c


示例15: print_nfsaddr

static void
print_nfsaddr(netdissect_options *ndo,
              const u_char *bp, const char *s, const char *d)
{
	struct ip *ip;
#ifdef INET6
	struct ip6_hdr *ip6;
	char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
#else
#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN	16
#endif
	char srcaddr[INET_ADDRSTRLEN], dstaddr[INET_ADDRSTRLEN];
#endif

	srcaddr[0] = dstaddr[0] = '\0';
	switch (IP_V((struct ip *)bp)) {
	case 4:
		ip = (struct ip *)bp;
		strlcpy(srcaddr, ipaddr_string(ndo, &ip->ip_src), sizeof(srcaddr));
		strlcpy(dstaddr, ipaddr_string(ndo, &ip->ip_dst), sizeof(dstaddr));
		break;
#ifdef INET6
	case 6:
		ip6 = (struct ip6_hdr *)bp;
		strlcpy(srcaddr, ip6addr_string(ndo, &ip6->ip6_src),
		    sizeof(srcaddr));
		strlcpy(dstaddr, ip6addr_string(ndo, &ip6->ip6_dst),
		    sizeof(dstaddr));
		break;
#endif
	default:
		strlcpy(srcaddr, "?", sizeof(srcaddr));
		strlcpy(dstaddr, "?", sizeof(dstaddr));
		break;
	}

	ND_PRINT((ndo, "%s.%s > %s.%s: ", srcaddr, s, dstaddr, d));
}
开发者ID:Longinus00,项目名称:tcpdump,代码行数:39,代码来源:print-nfs.c


示例16: reaper_rtp_format

static int
reaper_rtp_format(const struct ip *ip, int sport, int dport, const char* data, int len)
{
    if (reaper_packet_pointer == NULL)
        reaper_packet_pointer = reaper_packet_buffer;
   char *buffer = reaper_packet_pointer;
#ifdef INET6
   if (IP_V(ip) == 6) {
      const struct ip6_hdr *ip6;
      ip6 = (const struct ip6_hdr *)ip;
      buffer += sprintf(buffer, FORMAT,
        reaper_source_mac,
        ip6addr_string(&ip6->ip6_src),
        udpport_string(sport),
        reaper_destination_mac,
        ip6addr_string(&ip6->ip6_dst),
        udpport_string(dport));
   }
   else {
#endif /*INET6*/
      buffer += sprintf(buffer, FORMAT,
         reaper_source_mac,
         ipaddr_string(&ip->ip_src),
         udpport_string(sport),
         reaper_destination_mac,
         ipaddr_string(&ip->ip_dst),
         udpport_string(dport));
#ifdef INET6
   }
#endif /*INET6*/
   short sequenceNumber = ((data[2] & 0xFF) << 8) | (data[3] & 0xFF);
   int timeStamp = ((data[4] & 0xFF) << 24) | ((data[5] & 0xFF) << 16) |
       ((data[6] & 0xFF) << 8) | (data[7] & 0xFF);
   buffer += sprintf(buffer, "%d;%d;%d", sequenceNumber, timeStamp, reaper_time_stamp());
   *(buffer++) = '\n';
   *(buffer) = '\0';
   reaper_packet_pointer = buffer;
   return (buffer - reaper_packet_buffer);
}
开发者ID:ishmaelen,项目名称:Reaper,代码行数:39,代码来源:reaper.c


示例17: mpac_print_ipheader

int mpac_print_ipheader(sniff_cntx* context){
	printf("\n\n---------IP Header Starts----\n\n");

	printf("Version                       : %d \n", IP_V(context->ipHeader));
	printf("Header length                 : %d \n", context->ipHeaderSize);
	printf("Type of service               : %d \n", context->ipHeader->ip_tos);
	printf("Datagram length               : %d \n", context->ipHeader->ip_len);
	printf("Identication no.              : %d \n", context->ipHeader->ip_id);
	printf("Offset                        : %d \n", IP_OFF(context->ipHeader));
	printf("Reserved fragment bit         : %d \n", RF(context->ipHeader));
	printf("Dont fragment bit             : %d \n", DF(context->ipHeader));
	printf("More fragment bit             : %d \n", MF(context->ipHeader));
	printf("Time to live                  : %d \n", context->ipHeader->ip_ttl);
	printf("Protocol                      : %d \n", context->ipHeader->ip_p);
	printf("Checksum                      : %d \n", context->ipHeader->ip_sum);
	printf("Source IP                     : %s\n",inet_ntoa(context->ipHeader->ip_src));
	printf("Destination IP                : %s\n",inet_ntoa(context->ipHeader->ip_dst));



	printf("\n\n---------IP Header Ends----\n\n");

	return 0;
}
开发者ID:vitalyvch,项目名称:MPAC,代码行数:24,代码来源:mpac_sniffer.c


示例18: printIP

void printIP(const struct ip* ip, int verbosite)
{
  char *aux = inet_ntoa(ip->ip_src);
  char *ab = strcpy(malloc(strlen(aux)+1), aux);
  char *bux = inet_ntoa(ip->ip_dst);
  char *cd = strcpy(malloc(strlen(aux)+1), bux);
  printf("**********IP**********\n");
  printf("From IP: %s\nTo: %s\n",ab,cd);
  if(verbosite>1)
  {
    printf("Version: %d\n", IP_V(ip));
    printf("Length: %d\n", ip->ip_len);
    printf("Type de service : %d\n", ip->ip_tos);
    printf("Identification : %d\n", ip->ip_id);
    if(verbosite>2)
    {
      printf("Fragment offset: %d\n", ip->ip_off);
      printf("Time to live: %d\n", ip->ip_ttl);
      printf("Checksum: %d\n", ip->ip_sum);
      printPacket((u_char *) ip, sizeof(struct ip));
    }
  }
  printf("\n");
}
开发者ID:MaximeHeckel,项目名称:trameipanalyser,代码行数:24,代码来源:analyseur.c


示例19: tcp_print

void
tcp_print(netdissect_options *ndo,
          register const u_char *bp, register u_int length,
          register const u_char *bp2, int fragmented)
{
        register const struct tcphdr *tp;
        register const struct ip *ip;
        register u_char flags;
        register u_int hlen;
        register char ch;
        uint16_t sport, dport, win, urp;
        uint32_t seq, ack, thseq, thack;
        u_int utoval;
        uint16_t magic;
        register int rev;
#ifdef INET6
        register const struct ip6_hdr *ip6;
#endif

        tp = (const struct tcphdr *)bp;
        ip = (const struct ip *)bp2;
#ifdef INET6
        if (IP_V(ip) == 6)
                ip6 = (const struct ip6_hdr *)bp2;
        else
                ip6 = NULL;
#endif /*INET6*/
        ch = '\0';
        if (!ND_TTEST(tp->th_dport)) {
                ND_PRINT((ndo, "%s > %s: [|tcp]",
                             ipaddr_string(ndo, &ip->ip_src),
                             ipaddr_string(ndo, &ip->ip_dst)));
                return;
        }

        sport = EXTRACT_16BITS(&tp->th_sport);
        dport = EXTRACT_16BITS(&tp->th_dport);

        hlen = TH_OFF(tp) * 4;

#ifdef INET6
        if (ip6) {
                if (ip6->ip6_nxt == IPPROTO_TCP) {
                        ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                     ip6addr_string(ndo, &ip6->ip6_src),
                                     tcpport_string(ndo, sport),
                                     ip6addr_string(ndo, &ip6->ip6_dst),
                                     tcpport_string(ndo, dport)));
                } else {
                        ND_PRINT((ndo, "%s > %s: ",
                                     tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
                }
        } else
#endif /*INET6*/
        {
                if (ip->ip_p == IPPROTO_TCP) {
                        ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                     ipaddr_string(ndo, &ip->ip_src),
                                     tcpport_string(ndo, sport),
                                     ipaddr_string(ndo, &ip->ip_dst),
                                     tcpport_string(ndo, dport)));
                } else {
                        ND_PRINT((ndo, "%s > %s: ",
                                     tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
                }
        }

        if (hlen < sizeof(*tp)) {
                ND_PRINT((ndo, " tcp %d [bad hdr length %u - too short, < %lu]",
                             length - hlen, hlen, (unsigned long)sizeof(*tp)));
                return;
        }

        ND_TCHECK(*tp);

        seq = EXTRACT_32BITS(&tp->th_seq);
        ack = EXTRACT_32BITS(&tp->th_ack);
        win = EXTRACT_16BITS(&tp->th_win);
        urp = EXTRACT_16BITS(&tp->th_urp);

        if (ndo->ndo_qflag) {
                ND_PRINT((ndo, "tcp %d", length - hlen));
                if (hlen > length) {
                        ND_PRINT((ndo, " [bad hdr length %u - too long, > %u]",
                                     hlen, length));
                }
                return;
        }

        flags = tp->th_flags;
        ND_PRINT((ndo, "Flags [%s]", bittok2str_nosep(tcp_flag_values, "none", flags)));

        if (!ndo->ndo_Sflag && (flags & TH_ACK)) {
                /*
                 * Find (or record) the initial sequence numbers for
                 * this conversation.  (we pick an arbitrary
                 * collating order so there's only one entry for
                 * both directions).
                 */
                rev = 0;
//.........这里部分代码省略.........
开发者ID:lhslll,项目名称:tcpdump,代码行数:101,代码来源:print-tcp.c


示例20: sunrpcrequest_print

void
sunrpcrequest_print(netdissect_options *ndo, register const u_char *bp,
                    register u_int length, register const u_char *bp2)
{
	register const struct sunrpc_msg *rp;
	register const struct ip *ip;
#ifdef INET6
	register const struct ip6_hdr *ip6;
#endif
	u_int32_t x;
	char srcid[20], dstid[20];	/*fits 32bit*/

	rp = (struct sunrpc_msg *)bp;

	if (!ndo->ndo_nflag) {
		snprintf(srcid, sizeof(srcid), "0x%x",
		    EXTRACT_32BITS(&rp->rm_xid));
		strlcpy(dstid, "sunrpc", sizeof(dstid));
	} else {
		snprintf(srcid, sizeof(srcid), "0x%x",
		    EXTRACT_32BITS(&rp->rm_xid));
		snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT);
	}

	switch (IP_V((struct ip *)bp2)) {
	case 4:
		ip = (struct ip *)bp2;
		ND_PRINT((ndo, "%s.%s > %s.%s: %d",
		    ipaddr_string(&ip->ip_src), srcid,
		    ipaddr_string(&ip->ip_dst), dstid, length));
		break;
#ifdef INET6
	case 6:
		ip6 = (struct ip6_hdr *)bp2;
		ND_PRINT((ndo, "%s.%s > %s.%s: %d",
		    ip6addr_string(&ip6->ip6_src), srcid,
		    ip6addr_string(&ip6->ip6_dst), dstid, length));
		break;
#endif
	default:
		ND_PRINT((ndo, "%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length));
		break;
	}

	ND_PRINT((ndo, " %s", tok2str(proc2str, " proc #%u",
	    EXTRACT_32BITS(&rp->rm_call.cb_proc))));
	x = EXTRACT_32BITS(&rp->rm_call.cb_rpcvers);
	if (x != 2)
		ND_PRINT((ndo, " [rpcver %u]", x));

	switch (EXTRACT_32BITS(&rp->rm_call.cb_proc)) {

	case SUNRPC_PMAPPROC_SET:
	case SUNRPC_PMAPPROC_UNSET:
	case SUNRPC_PMAPPROC_GETPORT:
	case SUNRPC_PMAPPROC_CALLIT:
		x = EXTRACT_32BITS(&rp->rm_call.cb_prog);
		if (!ndo->ndo_nflag)
			ND_PRINT((ndo, " %s", progstr(x)));
		else
			ND_PRINT((ndo, " %u", x));
		ND_PRINT((ndo, ".%u", EXTRACT_32BITS(&rp->rm_call.cb_vers)));
		break;
	}
}
开发者ID:raniyuva,项目名称:tcpdump,代码行数:65,代码来源:print-sunrpc.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ IP_VALID函数代码示例发布时间:2022-05-30
下一篇:
C++ IP_INC_STATS_BH函数代码示例发布时间: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