示例#1
0
        public Udp6Cep(ID udpid, ref T_UDP6_CCEP pk_cudp, Nucleus pNucleus, lwip lwip)
        {
            m_CepID   = udpid;
            m_cudp    = pk_cudp;
            m_Nucleus = pNucleus;
            m_lwIP    = lwip;

            ip6_addr addr = new ip6_addr(pk_cudp.myaddr.ipaddr);

            m_Pcb = m_lwIP.udp.udp_new();
            //m_lwIP.udp.udp_bind(m_Pcb, addr, pk_cudp.myaddr.portno);
            //udp.udp_recv(m_Pcb, recv, this);
        }
示例#2
0
        public static ushort inet6_chksum_pseudo(pbuf p, ip6_addr src, ip6_addr dest, byte proto, ushort proto_len)
        {
            uint acc;
            pbuf q;
            byte swapped;

            acc     = 0;
            swapped = 0;
            /* iterate through all pbuf in chain */
            for (q = p; q != null; q = q.next)
            {
                lwip.LWIP_DEBUGF(opt.INET_DEBUG, "_inet_chksum.inet_chksum_pseudo(): checksumming pbuf {0} (has next {1}) \n",
                                 q.GetHashCode(), q.next == null ? 0 : q.next.GetHashCode());
                acc += LWIP_CHKSUM(q, q.len);
                /*lwip.LWIP_DEBUGF(opt.INET_DEBUG, "_inet_chksum.inet_chksum_pseudo(): unwrapped lwip_chksum()={0} \n", acc);*/

                /* just executing this next line is probably faster that the if statement needed
                 * to check whether we really need to execute it, and does no harm */
                acc = FOLD_U32T(acc);
                if (q.len % 2 != 0)
                {
                    swapped = (byte)(1 - swapped);
                    acc     = SWAP_BYTES_IN_WORD((ushort)acc);
                }
                /*lwip.LWIP_DEBUGF(opt.INET_DEBUG, "_inet_chksum.inet_chksum_pseudo(): wrapped lwip_chksum()={0} \n", acc);*/
            }

            if (swapped != 0)
            {
                acc = SWAP_BYTES_IN_WORD((ushort)acc);
            }
            for (int i = 0; i < 8; i++)
            {
                acc += lwip_htons(src.saddr[i]);
                acc += lwip_htons(dest.saddr[i]);
                while ((acc >> 16) != 0)
                {
                    acc = (acc & 0xffff) + (acc >> 16);
                }
            }
            acc += (uint)lwip_htons((ushort)proto);
            acc += (uint)lwip_htons(proto_len);

            /* Fold 32-bit sum to 16 bits
             * calling this twice is propably faster than if statements... */
            acc = FOLD_U32T(acc);
            acc = FOLD_U32T(acc);
            lwip.LWIP_DEBUGF(opt.INET_DEBUG, "_inet_chksum.inet_chksum_pseudo(): pbuf chain lwip_chksum()={0}\n", acc);
            return((ushort)~(acc & 0xffffU));
        }
示例#3
0
        private void recv(object arg, udp_pcb pcb, pbuf p, ip6_addr addr, ushort port)
        {
            System.Diagnostics.Debug.Assert((arg == this) && (pcb == m_Pcb));
            pointer  data      = new pointer(new byte[sizeof(ushort) + T_IPV6EP.length + p.tot_len], 0);
            T_IPV6EP p_dstaddr = new T_IPV6EP(data, sizeof(ushort));
            pointer  p_dat     = new pointer(data, sizeof(ushort) + T_IPV6EP.length);

            data.SetValue(p.tot_len);
            pointer.memcpy(p_dstaddr.ipaddr, addr, T_IPV6ADDR.length);
            p_dstaddr.portno = lwip.lwip_ntohs(port);

            for (pbuf q = p; q != null; q = q.next)
            {
                pointer.memcpy(p_dat, q.payload, q.len);
                p_dat += q.len;
            }

            lock (m_CallBack) {
                m_CallBack.Enqueue(data);
            }

            SetState(true, TMO.TMO_POL, null, OnTimeOut);
        }
示例#4
0
        public ER SendData(T_IPV6EP p_dstaddr, pointer p_dat, int len, TMO tmout)
        {
            pbuf     buf;
            ip6_addr addr = new ip6_addr(p_dstaddr.ipaddr);

            buf = m_lwIP.pbuf_alloc(pbuf_layer.PBUF_TRANSPORT, (ushort)len, pbuf_type.PBUF_POOL);
            if (buf == null)
            {
                return(ER.E_NOMEM);
            }

            int pos = 0;

            for (pbuf q = buf; q != null; q = q.next)
            {
                pointer.memcpy(q.payload, new pointer(p_dat, pos), q.len);
                pos += q.len;
            }

            //m_lwIP.udp.udp_sendto(m_Pcb, buf, addr, p_dstaddr.portno);

            return(ER.E_OK);
        }
示例#5
0
文件: Itron.cs 项目: h7ga40/uITron3
        public static byte[] GetIp6Packet(pointer packet, int len, ip6_addr src, ip6_addr dst, byte proto)
        {
            byte[] data = new byte[2 + 2 * ip6_addr.length + len];

            data[0] = 6;
            data[1] = proto;
            pointer.memcpy(new pointer(data, 2), src, ip6_addr.length);
            pointer.memcpy(new pointer(data, 2 + ip6_addr.length), dst, ip6_addr.length);
            pointer.memcpy(new pointer(data, 2 + 2 * ip6_addr.length), packet, len);

            return data;
        }
示例#6
0
文件: Itron.cs 项目: h7ga40/uITron3
        public static pointer CastIp6Packet(byte[] packet, out int len, out ip6_addr src, out ip6_addr dst, out byte proto)
        {
            len = packet.Length - (2 + 2 * ip6_addr.length);
            proto = packet[1];
            src = new ip6_addr(packet, 2);
            dst = new ip6_addr(packet, 2 + ip6_addr.length);

            return new pointer(packet, 2 + 2 * ip6_addr.length);
        }
示例#7
0
		public static ushort inet6_chksum_pseudo(pbuf p, ip6_addr src, ip6_addr dest, byte proto, ushort proto_len)
		{
			uint acc;
			pbuf q;
			byte swapped;

			acc = 0;
			swapped = 0;
			/* iterate through all pbuf in chain */
			for (q = p; q != null; q = q.next) {
				lwip.LWIP_DEBUGF(opt.INET_DEBUG, "_inet_chksum.inet_chksum_pseudo(): checksumming pbuf {0} (has next {1}) \n",
					q.GetHashCode(), q.next == null ? 0 : q.next.GetHashCode());
				acc += LWIP_CHKSUM(q, q.len);
				/*lwip.LWIP_DEBUGF(opt.INET_DEBUG, "_inet_chksum.inet_chksum_pseudo(): unwrapped lwip_chksum()={0} \n", acc);*/
				/* just executing this next line is probably faster that the if statement needed
				   to check whether we really need to execute it, and does no harm */
				acc = FOLD_U32T(acc);
				if (q.len % 2 != 0) {
					swapped = (byte)(1 - swapped);
					acc = SWAP_BYTES_IN_WORD((ushort)acc);
				}
				/*lwip.LWIP_DEBUGF(opt.INET_DEBUG, "_inet_chksum.inet_chksum_pseudo(): wrapped lwip_chksum()={0} \n", acc);*/
			}

			if (swapped != 0) {
				acc = SWAP_BYTES_IN_WORD((ushort)acc);
			}
			for (int i = 0; i < 8; i++) {
				acc += lwip_htons(src.saddr[i]);
				acc += lwip_htons(dest.saddr[i]);
				while ((acc >> 16) != 0) {
					acc = (acc & 0xffff) + (acc >> 16);
				}
			}
			acc += (uint)lwip_htons((ushort)proto);
			acc += (uint)lwip_htons(proto_len);

			/* Fold 32-bit sum to 16 bits
			   calling this twice is propably faster than if statements... */
			acc = FOLD_U32T(acc);
			acc = FOLD_U32T(acc);
			lwip.LWIP_DEBUGF(opt.INET_DEBUG, "_inet_chksum.inet_chksum_pseudo(): pbuf chain lwip_chksum()={0}\n", acc);
			return (ushort)~(acc & 0xffffU);
		}