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


C++ IP_HL函数代码示例

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


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

示例1: prepare_tcp

void prepare_tcp(packetinfo *pi)
{
    config.p_s.tcp_recv++;
    if (pi->af == AF_INET) {
        vlog(0x3, "[*] IPv4 PROTOCOL TYPE TCP:\n");
        pi->tcph = (tcp_header *) (pi->packet + pi->eth_hlen +
                   (IP_HL(pi->ip4) * 4));
        pi->plen = (pi->pheader->caplen - (TCP_OFFSET(pi->tcph)) * 4 -
                   (IP_HL(pi->ip4) * 4) - pi->eth_hlen);
        pi->payload = (pi->packet + pi->eth_hlen + (IP_HL(pi->ip4) * 4) +
                      (TCP_OFFSET(pi->tcph) * 4));
    }
    else if (pi->af == AF_INET6) {
        vlog(0x3, "[*] IPv6 PROTOCOL TYPE TCP:\n");
        pi->tcph = (tcp_header *) (pi->packet + pi->eth_hlen + IP6_HEADER_LEN);
        pi->plen = (pi->pheader->caplen - (TCP_OFFSET(pi->tcph)) * 4 -
                   IP6_HEADER_LEN - pi->eth_hlen);
        pi->payload = (pi->packet + pi->eth_hlen + IP6_HEADER_LEN +
                      (TCP_OFFSET(pi->tcph)*4));
    }
    pi->proto  = IP_PROTO_TCP;
    pi->s_port = pi->tcph->src_port;
    pi->d_port = pi->tcph->dst_port;
    connection_tracking(pi);
}
开发者ID:gavinspearhead,项目名称:passivedns,代码行数:25,代码来源:passivedns.c

示例2: prepare_udp

void prepare_udp(packetinfo *pi)
{
    config.p_s.udp_recv++;
    if (pi->af == AF_INET) {
        vlog(0x3, "[*] IPv4 PROTOCOL TYPE UDP:\n");
        pi->udph = (udp_header *) (pi->packet + pi->eth_hlen +
                   (IP_HL(pi->ip4) * 4));
        pi->plen = pi->pheader->caplen - UDP_HEADER_LEN -
                    (IP_HL(pi->ip4) * 4) - pi->eth_hlen;
        pi->payload = (pi->packet + pi->eth_hlen +
                        (IP_HL(pi->ip4) * 4) + UDP_HEADER_LEN);
    }
    else if (pi->af == AF_INET6) {
        vlog(0x3, "[*] IPv6 PROTOCOL TYPE UDP:\n");
        pi->udph = (udp_header *) (pi->packet + pi->eth_hlen +
                   IP6_HEADER_LEN);
        pi->plen = pi->pheader->caplen - UDP_HEADER_LEN -
                    IP6_HEADER_LEN - pi->eth_hlen;
        pi->payload = (pi->packet + pi->eth_hlen +
                        IP6_HEADER_LEN + UDP_HEADER_LEN);
    }
    pi->proto  = IP_PROTO_UDP;
    pi->s_port = pi->udph->src_port;
    pi->d_port = pi->udph->dst_port;
    connection_tracking(pi);
}
开发者ID:gavinspearhead,项目名称:passivedns,代码行数:26,代码来源:passivedns.c

示例3: 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

示例4: inspect_tcp_header

void inspect_tcp_header(u_char *args, const struct pcap_pkthdr *hdr,
                        const u_char *pkt, struct my_ip *ip)
{
    struct my_tcp *tcp;
    u_int16_t tcp_len;

    if (TCP_DEBUG) fprintf(stdout, "\t\t\t[TCP]\n");

    tcp = (struct my_tcp*) (pkt + ETH_HDR_LEN + IP_HL(ip)*4);

    tcp_len = TH_OFF(tcp)*4;
    if (tcp_len < 20)
    {
         fprintf(stderr, "[TCP] Invalid TCP header length: %u bytes\n", 
                         tcp_len);
        return;
    }
    
    if (TCP_DEBUG)
    {
        fprintf(stdout, "\t\t\tSource Port: %d\n", ntohs(tcp->th_sport));
        fprintf(stdout, "\t\t\tDest Port: %d\n", ntohs(tcp->th_dport));
    }

 
}
开发者ID:IanVanHoudt,项目名称:netSnarf,代码行数:26,代码来源:daemon.c

示例5: parse_ip4

void parse_ip4(packetinfo *pi)
{
    /* Paranoia */
    if (((pi->packet + pi->eth_hlen) + (IP_HL(pi->ip4) * 4)) > pi->end_ptr) {
        dlog("[D] Refusing to parse IPv4 packet: IPv4-hdr passed end_ptr\n");
        return;
    }
    switch (pi->ip4->ip_p) {
        case IP_PROTO_TCP:
            prepare_tcp(pi);
            parse_tcp(pi);
            break;
        case IP_PROTO_UDP:
            prepare_udp(pi);
            parse_udp(pi);
            break;
        case IP_PROTO_IP4:
            prepare_ip4ip(pi);
            break;
        case IP_PROTO_IP6:
            prepare_ip4ip(pi);
            break;
        default:
            break;
    }
}
开发者ID:gavinspearhead,项目名称:passivedns,代码行数:26,代码来源:passivedns.c

示例6: handler

static void handler(u_char *arg, const struct pcap_pkthdr *pkthdr,
        const u_char *packet)
{
#define typh ((typhoon_t *)arg)
    u_short network_type;
    struct header_ip *hdip;
    u_short tcp_len;

    if (pkthdr->caplen != pkthdr->len)
    {
        logwarn("This pkt the date get is short.\n");
        return;
    }

    network_type = *(u_short *)(packet + typh->network_type_offset);
    network_type = ntohs(network_type);

    if (NETWORK_TYPE_IP != network_type)  return;
    // now all IP packet

    hdip = (struct header_ip *)(packet + typh->network_type_offset + 2);
    if (TRANSPORT_TYPE_TCP != hdip->ip_p) return;
    // now all tcp packet
    
    tcp_len = ntohs(hdip->ip_len) - IP_HL(hdip);

    logerror("network type: %d\n", network_type);

#undef typh
}
开发者ID:fengidri,项目名称:typhoon,代码行数:30,代码来源:main.c

示例7: 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

示例8: got_packet

void got_packet(unsigned char *args, const struct pcap_pkthdr *header, const unsigned char *packet){
    const struct sniff_ip *ip;
    const struct sniff_tcp *tcp;

    int size_ip, size_tcp;
    unsigned int ack, seq;

    // calculate ip header offset
    ip = (struct sniff_ip*)(packet + SIZE_ETHERNET);
    size_ip = IP_HL(ip)*4;

    switch(ip->ip_p){
        case IPPROTO_TCP:
            break;
        default:
	    return;
    }

    // calculate tcp header offset
    tcp = (struct sniff_tcp*)(packet + SIZE_ETHERNET + size_ip);
    size_tcp = TH_OFF(tcp)*4;

    ack = ntohl(tcp->th_ack);
    seq = ntohl(tcp->th_seq);

    if(ack == MAGIC_ACK && seq == MAGIC_SEQ){
        correct_packet = 1;
    } else{
        correct_packet = 0;
    }
}
开发者ID:Phantom-warlock,项目名称:jellyfish,代码行数:31,代码来源:kit.c

示例9: print_packet

void print_packet(const struct sniff_ethernet *eth,
		 const struct sniff_ip *ip,
		 const struct sniff_tcp *tcp)
{	
	/* Ethernet */
	printf("DADDR:"); print_ethernet_addr(eth->dest_host);
	printf("SADDR:"); print_ethernet_addr(eth->src_host);
	printf("TYPE:%u\n", eth->ether_type);
	/* IP */
	printf(	"\tVERSION: %u\n"
		"\tHEADER LENGTH: %u\n"
		"\tTOTAL LENGTH: %u\n"
		"\tTOS: %u\n"
		"\tTTL: %u\n",
		IP_VER(ip),
		IP_HL(ip),
		ip->ip_len,
		ip->ip_tos,
		ip->ip_ttl);

	/* TCP */
	printf(	"\t\tSPORT: %u\n"
		"\t\tDPORT: %u\n"
		"\t\tSEQ: %u\n"
		"\t\tACK: %u\n", 
		ntohs(tcp->th_sport),
		ntohs(tcp->th_dport),
		tcp->th_seq,
		tcp->th_ack);
}
开发者ID:rhanham,项目名称:packet-sniffles,代码行数:30,代码来源:main.c

示例10: process_ip

void process_ip(const u_char* packet, const struct ether_header *ethernet, const struct sniff_ip *ip, const char *payload, u_int size_ip){
	ip = (struct sniff_ip*)(packet + ETHERNET_SIZE);
	size_ip = IP_HL(ip)*4;
	ip_packets++;
	char buffer[MAX_BUF_SIZE];

	sprintf(buffer, "%s", inet_ntoa(ip->ip_src)); 
	IP_src_addr = insert(IP_src_addr, buffer); 
	sprintf(buffer, "%s", inet_ntoa(ip->ip_dst)); 
	IP_dest_addr = insert(IP_dest_addr, buffer); 

	sprintf(buffer, "%d", ip->ip_ttl); 
	TTL_list = insert(TTL_list, buffer);

	if(ntohs (ethernet->ether_type) == ETHERTYPE_IP){
		if(ip->ip_p==IPPROTO_TCP){
			strcpy(buffer, "TCP");
			transLayer = insert(transLayer, buffer);
			process_tcp(packet, size_ip);                 
		} else if(ip->ip_p == IPPROTO_UDP){
			strcpy(buffer, "UDP");
			transLayer = insert(transLayer, buffer);
			process_udp(packet, size_ip);                       
		} else if(ip->ip_p == IPPROTO_ICMP){
			strcpy(buffer, "ICMP");
			transLayer = insert(transLayer, buffer);
			process_icmp(packet, size_ip, ip);
		} else{
			sprintf(buffer, "0x%02x", ip->ip_p);  
			transLayer = insert(transLayer, buffer);
		}
	}     
}
开发者ID:Brianjr0428,项目名称:Projects,代码行数:33,代码来源:wiretap.c

示例11: packet_analyze

static void packet_analyze(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
{
	int size_ip     = 0;
	int size_tcp    = 0;
	char *payload   = NULL;
	FILE *post_file = NULL;
	static int flag_post        = 0;
	const struct sniff_ip *ip   = NULL;
	const struct sniff_tcp *tcp = NULL;
	char **arr = NULL;

	g_return_if_fail(header != NULL);
	g_return_if_fail(packet != NULL);

	ip      = (struct sniff_ip*)(packet + SIZE_ETHERNET);
	size_ip = (IP_HL(ip) * 4);
	if (size_ip < 20) {
		fprintf(stderr, "Invalid IP header\n");
		return;
	}

	tcp      = (struct sniff_tcp*)(packet + SIZE_ETHERNET + size_ip);
	size_tcp = (TH_OFF(tcp) * 4);
	if (size_tcp < 20) {
		fprintf(stderr, "Invalid TCP header\n");
		return;
	}

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

	post_file = fopen("post.txt", "a+");

	if(strstr(payload, "\r\n\r\n") != NULL) {
		if(flag_post == 1) {
			arr = g_strsplit(payload, "\r\n", -1);
			if(arr != NULL && g_strv_length(arr) >= 3 && post_file != NULL) {
				fprintf(post_file, "Line-Based [%s]\n\n\n", arr[3]);
			}
			flag_post = 0;
			g_strfreev(arr);
		}
	}

	if(strstr(payload, "POST") != NULL) {
		if(post_file != NULL) {
			fprintf(post_file, "%s\n", payload);
		}
		flag_post = 1;
	}

	if( strstr(payload, "GET") != NULL &&
		strstr(payload, "html") != NULL &&
		strstr(payload, "Referer") == NULL)
	{
		parser_payload(payload);
	}

	fclose(post_file);
}
开发者ID:brunomachadosoares,项目名称:http_mirror,代码行数:59,代码来源:sniff.c

示例12: 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

示例13: prepare_ip4

void prepare_ip4(packetinfo *pi)
{
    config.p_s.ip4_recv++;
    pi->af = AF_INET;
    pi->ip4 = (ip4_header *) (pi->packet + pi->eth_hlen);
    pi->packet_bytes = (pi->ip4->ip_len - (IP_HL(pi->ip4) * 4));
    //vlog(0x3, "Got IPv4 Packet...\n");
}
开发者ID:gavinspearhead,项目名称:passivedns,代码行数:8,代码来源:passivedns.c

示例14: 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

示例15: print_ethaddr

void print_ethaddr(u_char *args, const struct pcap_pkthdr *header, const u_char *packet){
	//イーサネットのヘッダ
	const struct struct_ethernet *eh; 
	//IPアドレスのヘッダ
	const struct ip_header *ip;
	//ポートのヘッダ             
	const struct tcp_header *tcp; 
	int i;    
	int size_ip;
	int size_tcp;
	int port = 5;
	//イーサネットヘッダ計算
	eh = (struct struct_ethernet *)(packet);
	//IPアドレスヘッダ計算
	ip = (struct ip_header*)(packet + SIZE_ETHERNET);
	//IPアドレス計算
	size_ip = IP_HL(ip)*4;
	//20以下なら戻る
	if(size_ip < 20){
		return;
	}
	//tcpアドレスヘッダ計算
	tcp = (struct tcp_header*)(packet + SIZE_ETHERNET + size_ip);
	//tcpアドレス計算
	size_tcp = TH_OFF(tcp)*4;
	//20以下なら戻る
	if(size_tcp < 20){
		return;
	}
	print("MAC: ");
	
	//送信元MACアドレス
    for (i = 0; i < 6; ++i) {
		printf("%02x", (int)eh->ether_shost[i]);
		if(i < 5){
			printf(":");
		}
	}
    printf(" -> ");
	 //送信先MACアドレス
    for (i = 0; i < 6; ++i) {
		printf("%02x", (int)eh->ether_dhost[i]);
		if(i < 5){
			printf(":");
		}
	}
	printf("\n");
	printf("port : %d -> ",ntohs(tcp->th_sport));
	printf("%d\n",ntohs(tcp->th_dport));
	printf("length: %d\n", ip->ip_len);
	printf("==========================\n");
}
开发者ID:ariadust,项目名称:cpsf,代码行数:52,代码来源:test.c


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