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

C++ IPH_HL函数代码示例

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

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



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

示例1: __inetPingRecv

/*********************************************************************************************************
** 函数名称: __inetPingRecv
** 功能描述: 接收 ping 包
** 输 入  : iSock         socket
**           usSeqRecv     需要判断的 seq
**           piTTL         接收到的 TTL
** 输 出  : ERROR
** 全局变量: 
** 调用模块: 
*********************************************************************************************************/
static INT  __inetPingRecv (INT  iSock, UINT16  usSeqRecv, INT  *piTTL)
{
             CHAR                   cBuffer[512];
             
             INT                    iCnt = 20;                          /*  默认最多接收的数据包数      */
    REGISTER ssize_t                sstLen;
             INT                    iAddLen = sizeof(struct sockaddr_in);
             struct sockaddr_in     sockaddrinFrom;
             
             struct ip_hdr         *iphdrFrom;
             struct icmp_echo_hdr  *icmphdrFrom;
            
    while ((sstLen = recvfrom(iSock, cBuffer, sizeof(cBuffer), 0, 
                              (struct sockaddr *)&sockaddrinFrom, (socklen_t *)&iAddLen)) > 0) {
        
        if (sstLen >= (sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
            
            iphdrFrom   = (struct ip_hdr *)cBuffer;
            icmphdrFrom = (struct icmp_echo_hdr *)(cBuffer + (IPH_HL(iphdrFrom) * 4));
            
            if ((icmphdrFrom->id == 0xAFAF) && (icmphdrFrom->seqno == htons(usSeqRecv))) {
                *piTTL = 0;
                *piTTL = (u8_t)IPH_TTL(iphdrFrom);
                return  (ERROR_NONE);
            }
        }
        
        iCnt--;                                                         /*  接收到错误的数据包太多      */
        if (iCnt < 0) {
            break;                                                      /*  退出                        */
        }
    }
    
    return  (PX_ERROR);
}
开发者ID:Ga-vin,项目名称:libsylixos,代码行数:45,代码来源:lwip_ping.c


示例2: ping_recv

static void
ping_recv(int s)
{
  char buf[64];
  int fromlen, len;
  struct sockaddr_in from;
  struct ip_hdr *iphdr;
  struct icmp_echo_hdr *iecho;
  fromlen = sizeof(from);
  while((len = lwip_recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0) {
    if (len >= (int)(sizeof(struct ip_hdr)+sizeof(struct icmp_echo_hdr))) {
      ip_addr_t fromaddr;
      inet_addr_to_ipaddr(&fromaddr, &from.sin_addr);
      LWIP_DEBUGF( PING_DEBUG, ("ping: recv "));
      ip_addr_debug_print(PING_DEBUG, &fromaddr);
      LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\r\n", (sys_now() - ping_time)));
      iphdr = (struct ip_hdr *)buf;
      iecho = (struct icmp_echo_hdr *)(buf + (IPH_HL(iphdr) * 4));
      if ((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num))) {
        /* do some ping result processing */
        PING_RESULT((ICMPH_TYPE(iecho) == ICMP_ER));
        return;
      } else {
        LWIP_DEBUGF( PING_DEBUG, ("ping: drop\r\n"));
      }
    }
  }

  if (len == 0) {
    LWIP_DEBUGF( PING_DEBUG, ("ping: recv - %"U32_F" ms - timeout\r\n", (sys_now()-ping_time)));
  }

  /* do some ping result processing */
  PING_RESULT(0);
}
开发者ID:jgrivera67,项目名称:McRTOS,代码行数:35,代码来源:ping.c


示例3: ping_recv

static void
ping_recv(int s)
{
  char*     buf            = NULL;
  int       fromlen, len;
  struct    sockaddr_in from;
  struct    ip_hdr *iphdr;
  struct    icmp_echo_hdr *iecho;
  int       ms;
  BOOL      bResult        = FALSE;

  //Allocate a buffer to contain the received data.
  buf = (char*)KMemAlloc(1500,KMEM_SIZE_TYPE_ANY);
  if(NULL == buf)
  {
	  return;
  }
  while((len = lwip_recvfrom(s, buf, 1500, 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0)
  {
		if(len >= (int)(sizeof(struct ip_hdr)+sizeof(struct icmp_echo_hdr)))
		{
			ip_addr_t fromaddr;
      inet_addr_to_ipaddr(&fromaddr, &from.sin_addr);
			//Get times between sent and receive.
			ms = sys_now() - ping_time;
			ms *= SYSTEM_TIME_SLICE;

      iphdr = (struct ip_hdr *)buf;
      iecho = (struct icmp_echo_hdr *)(buf + (IPH_HL(iphdr) * 4));
      if (((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num)) && iecho->type == ICMP_ER))
			{
				len = len - sizeof(struct ip_hdr) - sizeof(struct icmp_echo_hdr);  //Adjust received data's length,since it
		                                                                       //includes IP and ICMP headers.
				_hx_printf("  [%d] Reply from %s,size = %d,time = %d(ms)\r\n",ping_pkt_seq,inet_ntoa(fromaddr),len,ms);
				ping_succ ++;
				bResult = TRUE;
      }
	    else
	    {
		    //printf("  ping : Received invalid replay,drop it.\r\n");
      }
    }
  }

  if (!bResult)
  {
		_hx_printf("  [%d] Request time out.\r\n",ping_pkt_seq);
  }

  if(buf)  //Release it.
  {
	  KMemFree(buf,KMEM_SIZE_TYPE_ANY,0);
  }
}
开发者ID:AlexShiLucky,项目名称:HelloX_STM32,代码行数:54,代码来源:network2.c


示例4: udp_lookup

uint8_t
udp_lookup(struct ip_hdr *iphdr, struct netif *inp)
{
  struct udp_pcb *pcb;
  struct udp_hdr *udphdr;
  uint16_t src, dest;
  
  udphdr = (struct udp_hdr *)(uint8_t *)iphdr + IPH_HL(iphdr) * 4/sizeof(uint8_t);

  src = NTOHS(udphdr->src);
  dest = NTOHS(udphdr->dest);
  
  pcb = pcb_cache;
  if(pcb != NULL &&
     pcb->remote_port == src &&
     pcb->local_port == dest &&
     (ip_addr_isany(&pcb->remote_ip) ||
      ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) &&
     (ip_addr_isany(&pcb->local_ip) ||
      ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {
    return 1;
  } else {  
    for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
      if(pcb->remote_port == src &&
	 pcb->local_port == dest &&
	 (ip_addr_isany(&pcb->remote_ip) ||
	  ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) &&
	 (ip_addr_isany(&pcb->local_ip) ||
	  ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {
	pcb_cache = pcb;
	break;
      }
    }

    if(pcb == NULL) {
      for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
	if(pcb->local_port == dest &&
	   (ip_addr_isany(&pcb->remote_ip) ||
	    ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) &&
	   (ip_addr_isany(&pcb->local_ip) ||
	    ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {
	  break;
	}
      }
    }
  }

  if(pcb != NULL) {
    return 1;
  } else {  
    return 1;
  }
}
开发者ID:eastzone,项目名称:cs344-sw-cpp,代码行数:53,代码来源:udp.c


示例5: ping_recv

static u8_t ping_recv(void *arg, struct raw_pcb *pcb, 
			struct pbuf *p, ip_addr_t *addr)
{
	struct ip_hdr *iphdr;
	struct icmp_echo_hdr *iecho;
	LWIP_UNUSED_ARG(arg);
	LWIP_UNUSED_ARG(pcb);
	LWIP_UNUSED_ARG(addr);

	LWIP_ASSERT("p != NULL", p != NULL);

	if ((p->tot_len >= (PBUF_IP_HLEN + sizeof(struct icmp_echo_hdr)))) {
		iphdr = (struct ip_hdr *)p->payload;
		iecho = (struct icmp_echo_hdr *)(p->payload + (IPH_HL(iphdr) * 4));
		if ((lns.ping_reply != NULL) &&
		    (iecho->id == PING_ID) && 
		    (iecho->seqno == htons(lns.ping_seq_num))) {
			lns.ping_recv_tstamp = vmm_timer_timestamp();

			lns.ping_reply->ripaddr[0] = ip4_addr1(&lns.ping_addr);
			lns.ping_reply->ripaddr[1] = ip4_addr2(&lns.ping_addr);
			lns.ping_reply->ripaddr[2] = ip4_addr3(&lns.ping_addr);
			lns.ping_reply->ripaddr[3] = ip4_addr4(&lns.ping_addr);
			lns.ping_reply->ttl = IPH_TTL(iphdr);
			lns.ping_reply->len = p->tot_len - (IPH_HL(iphdr) * 4);
			lns.ping_reply->seqno = lns.ping_seq_num;

			vmm_completion_complete(&lns.ping_done);

			/* Free the pbuf */
			pbuf_free(p);

			/* Eat the packet. lwIP should not process it. */
			return 1;
		}
	}

	/* Don't eat the packet. Let lwIP process it. */
	return 0;
}
开发者ID:32bitmicro,项目名称:xvisor,代码行数:40,代码来源:netstack.c


示例6: _udp_check_sum

/* Update UDP datagram's check sum accordingly. */
static void _udp_check_sum(struct ip_hdr* p, struct pbuf* pb)
{
	struct udp_hdr* pUdpHdr = NULL;
	int iph_len = IPH_HL(p);

	LWIP_UNUSED_ARG(pb);

	iph_len *= 4;
	pUdpHdr = (struct udp_hdr*)((char*)p + iph_len);
	__NATDEBUG("%s: reset UDP chksum from [%x] to 0.\r\n",
		__func__, pUdpHdr->chksum);
	pUdpHdr->chksum = 0; /* Reset check sum. */
}
开发者ID:hellox-project,项目名称:HelloX_OS,代码行数:14,代码来源:easynat.c


示例7: validateTCPChksum

/* 
 * Validate a TCP segment's checksum,return TRUE if pass the validation,
 * FALSE will be returned otherwise.
 */
static BOOL validateTCPChksum(struct ip_hdr* p, struct pbuf* pb)
{
	struct tcp_hdr* pTcpHdr = NULL;
	int iph_len = IPH_HL(p);
	int ip_len = ntohs(IPH_LEN(p)); /* Total IP packet length. */
	int chksum_old = 0, chksum_new = 0;
	ip_addr_t src, dest;

	iph_len *= 4;
	/* Locate TCP header. */
	pTcpHdr = (struct tcp_hdr*)((char*)p + iph_len);

	/* Validate pbuf object. */
	if (pb->tot_len < (iph_len + sizeof(struct tcp_hdr)))
	{
		return FALSE;
	}

	/* Validate the length of this packet. */
	if (ip_len < (iph_len + sizeof(struct tcp_hdr)))
	{
		return FALSE;
	}

	/*
	* Preserve TCP segment's check sum value before re-calculate
	* the value.
	*/
	chksum_old = pTcpHdr->chksum;
	ip_addr_copy(src, p->src);
	ip_addr_copy(dest, p->dest);
	pbuf_header(pb, -iph_len); /* move to TCP header. */
	pTcpHdr->chksum = 0; /* Reset the original check sum. */
	/* Recalculate the segment's checksum value. */
	chksum_new = inet_chksum_pseudo(pb, &src, &dest, IP_PROTO_TCP,
		/* IP payload length,e.i,TCP header plus data. */
		ip_len - iph_len);
		//pb->tot_len);
	pbuf_header(pb, iph_len); /* move back. */
	if (chksum_new != chksum_old)
	{
		__LOG("TCP checksum fail:ip_len = %d,pbuf_tot_len = %d,src_addr:%s\r\n",
			ip_len,
			pb->tot_len,
			inet_ntoa(p->src.addr));
		IP_STATS_INC(tcp.chkerr);
		IP_STATS_INC(tcp.drop);
		return FALSE;
	}
	return TRUE;
}
开发者ID:hellox-project,项目名称:HelloX_OS,代码行数:55,代码来源:easynat.c


示例8: _OutPacketMatch

/* Check if there is an entry that for a given output IP packet. */
static BOOL _OutPacketMatch(struct ip_hdr* pHdr, __EASY_NAT_ENTRY* pNatEntry)
{
	struct tcp_hdr* pTcpHdr = NULL;
	struct udp_hdr* pUdpHdr = NULL;
	int iph_len = 0;

	BUG_ON(NULL == pHdr);
	BUG_ON(NULL == pNatEntry);

	/* Increment total match times counter. */
	NatManager.stat.match_times++;

	/* Check according protocol type. */
	iph_len = IPH_HL(pHdr);
	iph_len *= 4;
	switch (pHdr->_proto)
	{
	case IP_PROTO_TCP:
		pTcpHdr = (struct tcp_hdr*)((char*)pHdr + iph_len);
		if ((pHdr->src.addr == pNatEntry->srcAddr_bef.addr) &&
			(pHdr->dest.addr == pNatEntry->dstAddr_bef.addr) &&
			(pTcpHdr->src == htons(pNatEntry->srcPort_bef)) &&
			(pTcpHdr->dest == htons(pNatEntry->dstPort_bef)))
		{
			return TRUE;
		}
		return FALSE;
		break;
	case IP_PROTO_UDP:
		pUdpHdr = (struct udp_hdr*)((char*)pHdr + iph_len);
		if ((pHdr->src.addr == pNatEntry->srcAddr_bef.addr) &&
			(pHdr->dest.addr == pNatEntry->dstAddr_bef.addr) &&
			(pUdpHdr->src == htons(pNatEntry->srcPort_bef)) &&
			(pUdpHdr->dest == htons(pNatEntry->dstPort_bef)))
		{
			return TRUE;
		}
		return FALSE;
		break;
	case IP_PROTO_ICMP:
		return OutPacketMatch_ICMP(pNatEntry, pHdr);
		break;
	default:
		return FALSE;
		break;
	}
	return FALSE;
}
开发者ID:hellox-project,项目名称:HelloX_OS,代码行数:49,代码来源:easynat.c


示例9: OutTranslation

/* Output direction translation. */
static void OutTranslation(__EASY_NAT_ENTRY* pEntry, struct ip_hdr* pHdr,struct pbuf* pb)
{
	struct tcp_hdr* pTcpHdr = NULL;
	struct udp_hdr* pUdpHdr = NULL;
	int iph_len = 0;

	BUG_ON(NULL == pEntry);
	BUG_ON(NULL == pHdr);
	BUG_ON(NULL == pb);

	/*
	* Update NAT entry state info.
	* It must be done before actual translation,since it maybe
	* altered in specific protocol's translation process,such
	* as TCP,it may set the entry's timeout value to MAX to
	* purge the entry as soon as possible,in case of the TCP
	* connection released.
	*/
	pEntry->ms = 0;
	pEntry->match_times++;

	/* Translate address first. */
	pHdr->src.addr = pEntry->srcAddr_aft.addr;
	/* Farther translation according protocol. */
	iph_len = IPH_HL(pHdr);
	iph_len *= 4;
	switch (pHdr->_proto)
	{
	case IP_PROTO_TCP:
		pTcpHdr = (struct tcp_hdr*)((char*)pHdr + iph_len);
		//pTcpHdr->src = htons(pEntry->srcPort_aft); 
		TcpTranslation(pEntry, pTcpHdr, out);
		break;
	case IP_PROTO_UDP:
		pUdpHdr = (struct udp_hdr*)((char*)pHdr + iph_len);
		pUdpHdr->src = htons(pEntry->srcPort_aft);
		break;
	case IP_PROTO_ICMP:
		OutTranslation_ICMP(pEntry, pHdr, pb);
		break;
	default:
		break;
	}
	/* Update the packet's checksum. */
	_iphdr_check_sum(pHdr, pb);
}
开发者ID:hellox-project,项目名称:HelloX_OS,代码行数:47,代码来源:easynat.c


示例10: ip_lookup

u8_t
ip_lookup(void *header, struct netif *inp)
{
    struct ip_hdr *iphdr;

    iphdr = header;

    /* Refuse anything that isn't IPv4. */
    if(IPH_V(iphdr) != 4) {
        return 0;
    }

    /* Immediately accept/decline packets that are fragments or has
       options. */
#if IP_REASSEMBLY == 0
    /*  if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
      return 0;
      }*/
#endif /* IP_REASSEMBLY == 0 */

#if IP_OPTIONS == 0
    if(IPH_HL(iphdr) != 5) {
        return 0;
    }
#endif /* IP_OPTIONS == 0 */

    switch(IPH_PROTO(iphdr)) {
#if LWIP_UDP > 0
    case IP_PROTO_UDP:
        return udp_lookup(iphdr, inp);
        break;
#endif /* LWIP_UDP */
#if LWIP_TCP > 0
    case IP_PROTO_TCP:
        return 1;
#endif /* LWIP_TCP */
    case IP_PROTO_ICMP:
        return 1;
        break;
    default:
        return 0;
    }
}
开发者ID:Joel397,项目名称:Ongoing_work_files,代码行数:43,代码来源:ip.c


示例11: ip_debug_print

void
ip_debug_print(struct pbuf *p)
{
    struct ip_hdr *iphdr = p->payload;
    u8_t *payload;

    payload = (u8_t *)iphdr + IP_HLEN/sizeof(u8_t);

    DEBUGF(IP_DEBUG, ("IP header:\n"));
    DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
    DEBUGF(IP_DEBUG, ("|%2d |%2d |   %2d  |      %4d     | (v, hl, tos, len)\n",
                      IPH_V(iphdr),
                      IPH_HL(iphdr),
                      IPH_TOS(iphdr),
                      ntohs(IPH_LEN(iphdr))));
    DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
    DEBUGF(IP_DEBUG, ("|    %5d      |%d%d%d|    %4d   | (id, flags, offset)\n",
                      ntohs(IPH_ID(iphdr)),
                      ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
                      ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
                      ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
                      ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK));
    DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
    DEBUGF(IP_DEBUG, ("|   %2d  |   %2d  |    0x%04x     | (ttl, proto, chksum)\n",
                      IPH_TTL(iphdr),
                      IPH_PROTO(iphdr),
                      ntohs(IPH_CHKSUM(iphdr))));
    DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
    DEBUGF(IP_DEBUG, ("|  %3ld  |  %3ld  |  %3ld  |  %3ld  | (src)\n",
                      ntohl(iphdr->src.addr) >> 24 & 0xff,
                      ntohl(iphdr->src.addr) >> 16 & 0xff,
                      ntohl(iphdr->src.addr) >> 8 & 0xff,
                      ntohl(iphdr->src.addr) & 0xff));
    DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
    DEBUGF(IP_DEBUG, ("|  %3ld  |  %3ld  |  %3ld  |  %3ld  | (dest)\n",
                      ntohl(iphdr->dest.addr) >> 24 & 0xff,
                      ntohl(iphdr->dest.addr) >> 16 & 0xff,
                      ntohl(iphdr->dest.addr) >> 8 & 0xff,
                      ntohl(iphdr->dest.addr) & 0xff));
    DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
}
开发者ID:Joel397,项目名称:Ongoing_work_files,代码行数:41,代码来源:ip.c


示例12: _tcp_check_sum

/* Update TCP segment's check sum. */
static void _tcp_check_sum(struct ip_hdr* p, struct pbuf* pb)
{
	struct tcp_hdr* pTcpHdr = NULL;
	int iph_len = IPH_HL(p);
	int ip_len = ntohs(IPH_LEN(p)); /* Total IP packet's length. */
	int chksum = 0;
	ip_addr_t src, dest;

	iph_len *= 4;
	/* Locate TCP header. */
	pTcpHdr = (struct tcp_hdr*)((char*)p + iph_len);

	/* Validate pbuf object. */
	if (pb->tot_len < (iph_len + sizeof(struct tcp_hdr)))
	{
		return;
	}

	/* Validate IP packet's total length. */
	if (ip_len < (iph_len + sizeof(struct tcp_hdr)))
	{
		return;
	}

	/*
	* Reset TCP header's check sum since it's source address
	* or source port is changed after NATing.
	*/
	chksum = pTcpHdr->chksum;
	ip_addr_copy(src, p->src);
	ip_addr_copy(dest, p->dest);
	pbuf_header(pb, -iph_len); /* move to TCP header. */
	pTcpHdr->chksum = 0; /* Reset the original check sum. */
	pTcpHdr->chksum = inet_chksum_pseudo(pb, &src, &dest, IP_PROTO_TCP,
		ip_len - iph_len);
	pbuf_header(pb, iph_len); /* move back. */
	__NATDEBUG("%s: TCP check sum updated[%X] -> [%X]\r\n",
		__func__,
		chksum,
		pTcpHdr->chksum);
}
开发者ID:hellox-project,项目名称:HelloX_OS,代码行数:42,代码来源:easynat.c


示例13: InitNatEntry

/* Initialize a new NAT entry giving the IP header. */
static void InitNatEntry(__EASY_NAT_ENTRY* pEntry, struct ip_hdr* pHdr, struct netif* pOutIf)
{
	struct udp_hdr* pUdpHdr = NULL;
	struct tcp_hdr* pTcpHdr = NULL;
	int iph_len = 0;

	/* Set NAT entry according IP header. */
	pEntry->srcAddr_bef.addr = pHdr->src.addr;
	pEntry->dstAddr_bef.addr = pHdr->dest.addr;
	pEntry->srcAddr_aft.addr = pOutIf->ip_addr.addr; /* Changed. */
	pEntry->dstAddr_aft.addr = pHdr->dest.addr;
	pEntry->protocol = pHdr->_proto;
	pEntry->netif = pOutIf; 
	pEntry->ms = 0;
	pEntry->match_times++;

	iph_len = IPH_HL(pHdr);
	iph_len *= 4;
	switch (pHdr->_proto)
	{
	case IP_PROTO_TCP:
		pTcpHdr = (struct tcp_hdr*)((char*)pHdr + iph_len);
		pEntry->srcPort_bef = ntohs(pTcpHdr->src);
		pEntry->srcPort_aft = ntohs(GetTCPSrcPort());      /* Changed. */
		pEntry->dstPort_bef = ntohs(pTcpHdr->dest);
		pEntry->dstPort_aft = ntohs(pTcpHdr->dest);
		break;
	case IP_PROTO_UDP:
		pUdpHdr = (struct udp_hdr*)((char*)pHdr + iph_len);
		pEntry->srcPort_bef = ntohs(pUdpHdr->src);
		pEntry->srcPort_aft = ntohs(GetUDPSrcPort());      /* Changed. */
		pEntry->dstPort_bef = ntohs(pUdpHdr->dest);
		pEntry->dstPort_aft = ntohs(pUdpHdr->dest);
		break;
	case IP_PROTO_ICMP:
		InitNatEntry_ICMP(pEntry, pHdr);
		break;
	default:
		break;
	}
}
开发者ID:hellox-project,项目名称:HelloX_OS,代码行数:42,代码来源:easynat.c


示例14: ip_debug_print

void
ip_debug_print(struct pbuf *p)
{
  struct ip_hdr *iphdr = p->payload;
  u8_t *payload;

  payload = (u8_t *)iphdr + IP_HLEN;

  LWIP_DEBUGF(IP_DEBUG, ("IP header:\n"));
  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
  LWIP_DEBUGF(IP_DEBUG, ("|%2"S16_F" |%2"S16_F" |  0x%02"X16_F" |     %5"U16_F"     | (v, hl, tos, len)\n",
                    IPH_V(iphdr),
                    IPH_HL(iphdr),
                    IPH_TOS(iphdr),
                    ntohs(IPH_LEN(iphdr))));
  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
  LWIP_DEBUGF(IP_DEBUG, ("|    %5"U16_F"      |%"U16_F"%"U16_F"%"U16_F"|    %4"U16_F"   | (id, flags, offset)\n",
                    ntohs(IPH_ID(iphdr)),
                    ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
                    ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
                    ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
                    ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK));
  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
  LWIP_DEBUGF(IP_DEBUG, ("|  %3"U16_F"  |  %3"U16_F"  |    0x%04"X16_F"     | (ttl, proto, chksum)\n",
                    IPH_TTL(iphdr),
                    IPH_PROTO(iphdr),
                    ntohs(IPH_CHKSUM(iphdr))));
  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
  LWIP_DEBUGF(IP_DEBUG, ("|  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  | (src)\n",
                    ip4_addr1(&iphdr->src),
                    ip4_addr2(&iphdr->src),
                    ip4_addr3(&iphdr->src),
                    ip4_addr4(&iphdr->src)));
  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
  LWIP_DEBUGF(IP_DEBUG, ("|  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  | (dest)\n",
                    ip4_addr1(&iphdr->dest),
                    ip4_addr2(&iphdr->dest),
                    ip4_addr3(&iphdr->dest),
                    ip4_addr4(&iphdr->dest)));
  LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
}
开发者ID:AldenHiggins,项目名称:ELEC424-Lab06-Scheduling-with-FreeRTOS,代码行数:41,代码来源:ip.c


示例15: show_ip_pkt

static void show_ip_pkt(struct pbuf *p)
{
	struct ip_hdr *iphdr = (struct ip_hdr *)p->payload;
	u8_t *payload;

	payload = (u8_t *)iphdr + IP_HLEN;

	_hx_printf("[%s]IP header:\r\n",__func__);
	_hx_printf("+-------------------------------+\r\n");
	_hx_printf("|%2"S16_F" |%2"S16_F" |  0x%02"X16_F" |     %5"U16_F"     | (v, hl, tos, len)\r\n",
		IPH_V(iphdr),
		IPH_HL(iphdr),
		IPH_TOS(iphdr),
		ntohs(IPH_LEN(iphdr)));
	_hx_printf("+-------------------------------+\r\n");
	_hx_printf("|    %5"U16_F"      |%"U16_F"%"U16_F"%"U16_F"|    %4"U16_F"   | (id, flags, offset)\r\n",
		ntohs(IPH_ID(iphdr)),
		ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
		ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
		ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
		ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK);
	_hx_printf("+-------------------------------+\r\n");
	_hx_printf("|  %3"U16_F"  |  %3"U16_F"  |    0x%04"X16_F"     | (ttl, proto, chksum)\r\n",
		IPH_TTL(iphdr),
		IPH_PROTO(iphdr),
		ntohs(IPH_CHKSUM(iphdr)));
	_hx_printf("+-------------------------------+\r\n");
	_hx_printf("|  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  | (src)\r\n",
		ip4_addr1_16(&iphdr->src),
		ip4_addr2_16(&iphdr->src),
		ip4_addr3_16(&iphdr->src),
		ip4_addr4_16(&iphdr->src));
	_hx_printf("+-------------------------------+\r\n");
	_hx_printf("|  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  |  %3"U16_F"  | (dest)\r\n",
		ip4_addr1_16(&iphdr->dest),
		ip4_addr2_16(&iphdr->dest),
		ip4_addr3_16(&iphdr->dest),
		ip4_addr4_16(&iphdr->dest));
	_hx_printf("+-------------------------------+\r\n");
}
开发者ID:hellox-project,项目名称:HelloX_OS,代码行数:40,代码来源:easynat.c


示例16: ip_reass

/**
 * Reassembles incoming IP fragments into an IP datagram.
 *
 * @param p points to a pbuf chain of the fragment
 * @return NULL if reassembly is incomplete, ? otherwise
 */
struct pbuf *
ip_reass(struct pbuf *p)
{
  struct pbuf *r;
  struct ip_hdr *fraghdr;
  struct ip_reassdata *ipr;
  struct ip_reass_helper *iprh;
  u16_t offset, len;
  u8_t clen;
  struct ip_reassdata *ipr_prev = NULL;

  IPFRAG_STATS_INC(ip_frag.recv);
  snmp_inc_ipreasmreqds();

  fraghdr = (struct ip_hdr*)p->payload;

  if ((IPH_HL(fraghdr) * 4) != IP_HLEN) {
    LWIP_DEBUGF(IP_REASS_DEBUG,("ip_reass: IP options currently not supported!\n"));
    IPFRAG_STATS_INC(ip_frag.err);
    goto nullreturn;
  }

  offset = (ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8;
  len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4;

  /* Check if we are allowed to enqueue more datagrams. */
  clen = pbuf_clen(p);
  if ((ip_reass_pbufcount + clen) > IP_REASS_MAX_PBUFS) {
#if IP_REASS_FREE_OLDEST
    if (!ip_reass_remove_oldest_datagram(fraghdr, clen) ||
        ((ip_reass_pbufcount + clen) > IP_REASS_MAX_PBUFS))
#endif /* IP_REASS_FREE_OLDEST */
    {
      /* No datagram could be freed and still too many pbufs enqueued */
      LWIP_DEBUGF(IP_REASS_DEBUG,("ip_reass: Overflow condition: pbufct=%d, clen=%d, MAX=%d\n",
        ip_reass_pbufcount, clen, IP_REASS_MAX_PBUFS));
      IPFRAG_STATS_INC(ip_frag.memerr);
      /* @todo: send ICMP time exceeded here? */
      /* drop this pbuf */
      goto nullreturn;
    }
  }

  /* Look for the datagram the fragment belongs to in the current datagram queue,
   * remembering the previous in the queue for later dequeueing. */
  for (ipr = reassdatagrams; ipr != NULL; ipr = ipr->next) {
    /* Check if the incoming fragment matches the one currently present
       in the reassembly buffer. If so, we proceed with copying the
       fragment into the buffer. */
    if (IP_ADDRESSES_AND_ID_MATCH(&ipr->iphdr, fraghdr)) {
      LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: matching previous fragment ID=%"X16_F"\n",
        ntohs(IPH_ID(fraghdr))));
      IPFRAG_STATS_INC(ip_frag.cachehit);
      break;
    }
    ipr_prev = ipr;
  }

  if (ipr == NULL) {
  /* Enqueue a new datagram into the datagram queue */
    ipr = ip_reass_enqueue_new_datagram(fraghdr, clen);
    /* Bail if unable to enqueue */
    if(ipr == NULL) {
      goto nullreturn;
    }
  } else {
    if (((ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) == 0) && 
      ((ntohs(IPH_OFFSET(&ipr->iphdr)) & IP_OFFMASK) != 0)) {
      /* ipr->iphdr is not the header from the first fragment, but fraghdr is
       * -> copy fraghdr into ipr->iphdr since we want to have the header
       * of the first fragment (for ICMP time exceeded and later, for copying
       * all options, if supported)*/
      SMEMCPY(&ipr->iphdr, fraghdr, IP_HLEN);
    }
  }
  /* Track the current number of pbufs current 'in-flight', in order to limit 
  the number of fragments that may be enqueued at any one time */
  ip_reass_pbufcount += clen;

  /* At this point, we have either created a new entry or pointing 
   * to an existing one */

  /* check for 'no more fragments', and update queue entry*/
  if ((IPH_OFFSET(fraghdr) & PP_NTOHS(IP_MF)) == 0) {
    ipr->flags |= IP_REASS_FLAG_LASTFRAG;
    ipr->datagram_len = offset + len;
    LWIP_DEBUGF(IP_REASS_DEBUG,
     ("ip_reass: last fragment seen, total len %"S16_F"\n",
      ipr->datagram_len));
  }
  /* find the right place to insert this pbuf */
  /* @todo: trim pbufs if fragments are overlapping */
  if (ip_reass_chain_frag_into_datagram_and_validate(ipr, p)) {
    /* the totally last fragment (flag more fragments = 0) was received at least
//.........这里部分代码省略.........
开发者ID:0wsqqsw,项目名称:lantern,代码行数:101,代码来源:ip_frag.c


示例17: ip_reass_chain_frag_into_datagram_and_validate

/**
 * Chain a new pbuf into the pbuf list that composes the datagram.  The pbuf list
 * will grow over time as  new pbufs are rx.
 * Also checks that the datagram passes basic continuity checks (if the last
 * fragment was received at least once).
 * @param root_p points to the 'root' pbuf for the current datagram being assembled.
 * @param new_p points to the pbuf for the current fragment
 * @return 0 if invalid, >0 otherwise
 */
static int
ip_reass_chain_frag_into_datagram_and_validate(struct ip_reassdata *ipr, struct pbuf *new_p)
{
  struct ip_reass_helper *iprh, *iprh_tmp, *iprh_prev=NULL;
  struct pbuf *q;
  u16_t offset,len;
  struct ip_hdr *fraghdr;
  int valid = 1;

  /* Extract length and fragment offset from current fragment */
  fraghdr = (struct ip_hdr*)new_p->payload; 
  len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4;
  offset = (ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8;

  /* overwrite the fragment's ip header from the pbuf with our helper struct,
   * and setup the embedded helper structure. */
  /* make sure the struct ip_reass_helper fits into the IP header */
  LWIP_ASSERT("sizeof(struct ip_reass_helper) <= IP_HLEN",
              sizeof(struct ip_reass_helper) <= IP_HLEN);
  iprh = (struct ip_reass_helper*)new_p->payload;
  iprh->next_pbuf = NULL;
  iprh->start = offset;
  iprh->end = offset + len;

  /* Iterate through until we either get to the end of the list (append),
   * or we find on with a larger offset (insert). */
  for (q = ipr->p; q != NULL;) {
    iprh_tmp = (struct ip_reass_helper*)q->payload;
    if (iprh->start < iprh_tmp->start) {
      /* the new pbuf should be inserted before this */
      iprh->next_pbuf = q;
      if (iprh_prev != NULL) {
        /* not the fragment with the lowest offset */
#if IP_REASS_CHECK_OVERLAP
        if ((iprh->start < iprh_prev->end) || (iprh->end > iprh_tmp->start)) {
          /* fragment overlaps with previous or following, throw away */
          goto freepbuf;
        }
#endif /* IP_REASS_CHECK_OVERLAP */
        iprh_prev->next_pbuf = new_p;
      } else {
        /* fragment with the lowest offset */
        ipr->p = new_p;
      }
      break;
    } else if(iprh->start == iprh_tmp->start) {
      /* received the same datagram twice: no need to keep the datagram */
      goto freepbuf;
#if IP_REASS_CHECK_OVERLAP
    } else if(iprh->start < iprh_tmp->end) {
      /* overlap: no need to keep the new datagram */
      goto freepbuf;
#endif /* IP_REASS_CHECK_OVERLAP */
    } else {
      /* Check if the fragments received so far have no wholes. */
      if (iprh_prev != NULL) {
        if (iprh_prev->end != iprh_tmp->start) {
          /* There is a fragment missing between the current
           * and the previous fragment */
          valid = 0;
        }
      }
    }
    q = iprh_tmp->next_pbuf;
    iprh_prev = iprh_tmp;
  }

  /* If q is NULL, then we made it to the end of the list. Determine what to do now */
  if (q == NULL) {
    if (iprh_prev != NULL) {
      /* this is (for now), the fragment with the highest offset:
       * chain it to the last fragment */
#if IP_REASS_CHECK_OVERLAP
      LWIP_ASSERT("check fragments don't overlap", iprh_prev->end <= iprh->start);
#endif /* IP_REASS_CHECK_OVERLAP */
      iprh_prev->next_pbuf = new_p;
      if (iprh_prev->end != iprh->start) {
        valid = 0;
      }
    } else {
#if IP_REASS_CHECK_OVERLAP
      LWIP_ASSERT("no previous fragment, this must be the first fragment!",
        ipr->p == NULL);
#endif /* IP_REASS_CHECK_OVERLAP */
      /* this is the first fragment we ever received for this ip datagram */
      ipr->p = new_p;
    }
  }

  /* At this point, the validation part begins: */
  /* If we already received the last fragment */
//.........这里部分代码省略.........
开发者ID:0wsqqsw,项目名称:lantern,代码行数:101,代码来源:ip_frag.c


示例18: udp_input

/**
 * Process an incoming UDP datagram.
 *
 * Given an incoming UDP datagram (as a chain of pbufs) this function
 * finds a corresponding UDP PCB and hands over the pbuf to the pcbs
 * recv function. If no pcb is found or the datagram is incorrect, the
 * pbuf is freed.
 *
 * @param p pbuf to be demultiplexed to a UDP PCB.
 * @param inp network interface on which the datagram was received.
 *
 */
void
udp_input(struct pbuf *p, struct netif *inp)
{
    struct udp_hdr *udphdr;
    struct udp_pcb *pcb, *prev;
    struct udp_pcb *uncon_pcb;
    struct ip_hdr *iphdr;
    u16_t src, dest;
    u8_t local_match;
    u8_t broadcast;

    PERF_START;

    UDP_STATS_INC(udp.recv);

    iphdr = (struct ip_hdr *)p->payload;

    /* Check minimum length (IP header + UDP header)
     * and move payload pointer to UDP header */
    if (p->tot_len < (IPH_HL(iphdr) * 4 + UDP_HLEN) || pbuf_header(p, -(s16_t)(IPH_HL(iphdr) * 4))) {
        /* drop short packets */
        LWIP_DEBUGF(UDP_DEBUG,
                    ("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
        UDP_STATS_INC(udp.lenerr);
        UDP_STATS_INC(udp.drop);
        snmp_inc_udpinerrors();
        pbuf_free(p);
        goto end;
    }

    udphdr = (struct udp_hdr *)p->payload;

    /* is broadcast packet ? */
    broadcast = ip_addr_isbroadcast(&current_iphdr_dest, inp);

    LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));

    /* convert src and dest ports to host byte order */
    src = ntohs(udphdr->src);
    dest = ntohs(udphdr->dest);

    udp_debug_print(udphdr);

    /* print the UDP source and destination */
    LWIP_DEBUGF(UDP_DEBUG,
                ("udp (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") <-- "
                 "(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
                 ip4_addr1_16(&iphdr->dest), ip4_addr2_16(&iphdr->dest),
                 ip4_addr3_16(&iphdr->dest), ip4_addr4_16(&iphdr->dest), ntohs(udphdr->dest),
                 ip4_addr1_16(&iphdr->src), ip4_addr2_16(&iphdr->src),
                 ip4_addr3_16(&iphdr->src), ip4_addr4_16(&iphdr->src), ntohs(udphdr->src)));

#if LWIP_DHCP
    pcb = NULL;
    /* when LWIP_DHCP is active, packets to DHCP_CLIENT_PORT may only be processed by
       the dhcp module, no other UDP pcb may use the local UDP port DHCP_CLIENT_PORT */
    if (dest == DHCP_CLIENT_PORT) {
        /* all packets for DHCP_CLIENT_PORT not coming from DHCP_SERVER_PORT are dropped! */
        if (src == DHCP_SERVER_PORT) {
            if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) {
                /* accept the packe if
                   (- broadcast or directed to us) -> DHCP is link-layer-addressed, local ip is always ANY!
                   - inp->dhcp->pcb->remote == ANY or iphdr->src */
                if ((ip_addr_isany(&inp->dhcp->pcb->remote_ip) ||
                        ip_addr_cmp(&(inp->dhcp->pcb->remote_ip), &current_iphdr_src))) {
                    pcb = inp->dhcp->pcb;
                }
            }
        }
    } else
#endif /* LWIP_DHCP */
    {
        prev = NULL;
        local_match = 0;
        uncon_pcb = NULL;
        /* Iterate through the UDP pcb list for a matching pcb.
         * 'Perfect match' pcbs (connected to the remote port & ip address) are
         * preferred. If no perfect match is found, the first unconnected pcb that
         * matches the local port and ip address gets the datagram. */
        for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
            local_match = 0;
            /* print the PCB local and remote address */
            LWIP_DEBUGF(UDP_DEBUG,
                        ("pcb (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") --- "
                         "(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
                         ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
                         ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip), pcb->local_port,
                         ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip),
//.........这里部分代码省略.........
开发者ID:miaozhendaoren,项目名称:EthUdp297,代码行数:101,代码来源:udp.c


示例19: ip_input

/**
 * This function is called by the network interface device driver when
 * an IP packet is received. The function does the basic checks of the
 * IP header such as packet size being at least larger than the header
 * size etc. If the packet was not destined for us, the packet is
 * forwarded (using ip_forward). The IP checksum is always checked.
 *
 * Finally, the packet is sent to the upper layer protocol input function.
 * 
 * @param p the received IP packet (p->payload points to IP header)
 * @param inp the netif on which this packet was received
 * @return ERR_OK if the packet was processed (could return ERR_* if it wasn't
 *         processed, but currently always returns ERR_OK)
 */
err_t
ip_input(struct pbuf *p, struct netif *inp)
{
  struct ip_hdr *iphdr;
  struct netif *netif;
  u16_t iphdr_hlen;
  u16_t iphdr_len;
#if LWIP_DHCP
  int check_ip_src=1;
#endif /* LWIP_DHCP */

  IP_STATS_INC(ip.recv);
  snmp_inc_ipinreceives();

  /* identify the IP header */
  iphdr = p->payload;
  if (IPH_V(iphdr) != 4) {
    LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_WARNING, ("IP packet dropped due to bad version number %"U16_F"\n", IPH_V(iphdr)));
    ip_debug_print(p);
    pbuf_free(p);
    IP_STATS_INC(ip.err);
    IP_STATS_INC(ip.drop);
    snmp_inc_ipinhdrerrors();
    return ERR_OK;
  }

  /* obtain IP header length in number of 32-bit words */
  iphdr_hlen = IPH_HL(iphdr);
  /* calculate IP header length in bytes */
  iphdr_hlen *= 4;
  /* obtain ip length in bytes */
  iphdr_len = ntohs(IPH_LEN(iphdr));

  /* header length exceeds first pbuf length, or ip length exceeds total pbuf length? */
  if ((iphdr_hlen > p->len) || (iphdr_len > p->tot_len)) {
    if (iphdr_hlen > p->len) {
      LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
        ("IP header (len %"U16_F") does not fit in first pbuf (len %"U16_F"), IP packet dropped.\n",
        iphdr_hlen, p->len));
    }
    if (iphdr_len > p->tot_len) {
      LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
        ("IP (len %"U16_F") is longer than pbuf (len %"U16_F"), IP packet dropped.\n",
        iphdr_len, p->tot_len));
    }
    /* free (drop) packet pbufs */
    pbuf_free(p);
    IP_STATS_INC(ip.lenerr);
    IP_STATS_INC(ip.drop);
    snmp_inc_ipindiscards();
    return ERR_OK;
  }

  /* verify checksum */
#if CHECKSUM_CHECK_IP
  if (inet_chksum(iphdr, iphdr_hlen) != 0) {

    LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
      ("Checksum (0x%"X16_F") failed, IP packet dropped.\n", inet_chksum(iphdr, iphdr_hlen)));
    ip_debug_print(p);
    pbuf_free(p);
    IP_STATS_INC(ip.chkerr);
    IP_STATS_INC(ip.drop);
    snmp_inc_ipinhdrerrors();
    return ERR_OK;
  }
#endif

  /* Trim pbuf. This should have been done at the netif layer,
   * but we'll do it anyway just to be sure that its done. */
  pbuf_realloc(p, iphdr_len);

  /* match packet against an interface, i.e. is this packet for us? */
#if LWIP_IGMP
  if (ip_addr_ismulticast(&(iphdr->dest))) {
    if ((inp->flags & NETIF_FLAG_IGMP) && (igmp_lookfor_group(inp, &(iphdr->dest)))) {
      netif = inp;
    } else {
      netif = NULL;
    }
  } else
#endif /* LWIP_IGMP */
  {
    /* start trying with inp. if that's not acceptable, start walking the
       list of configured neti 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

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