This page is part of an archival collection and is no longer actively maintained.

It may contain outdated information and may not meet current or future WCAG accessibility standards. We provide this content, its subpages, and associated links for historical reference only. If you need assistance, please contact support@cs.washington.edu

Code Fragment
 len := Mbuf.m_length(pkt_mbuf);
    (* copy data into its own mbuf chain *)
    this.pkt := Mbuf.m_gethdr(Mbuf.M_DONTWAIT, Mbuf.MT_DATA);
    IF len < Mbuf.MHLEN THEN
      this.pkt.mh_hdr.mh_len := len;
      (* Slow copy from mbuf chain to contiguous buffer -  ugh *)
      srcPos := 0; (* start copying after the headers *)
      dstPos := 0;
      WHILE pkt_mbuf # NIL DO
        WITH srcBuf = Mbuf.Array(pkt_mbuf)^,
             srcSize = BYTESIZE(srcBuf)-srcPos,
             dstBuf = Mbuf.Array(this.pkt)^
         DO
          IF srcSize >= 0 THEN
            SUBARRAY(dstBuf,dstPos,srcSize) :=
              SUBARRAY(srcBuf,srcPos,srcSize);
            srcPos := 0;
          ELSE
            DEC(srcPos,BYTESIZE(srcBuf));
          END;
          INC(dstPos,srcSize);
        END;
        pkt_mbuf := pkt_mbuf.mh_hdr.mh_next;
      END;
    ELSE
      this.pkt.mh_hdr.mh_len := 0;
      Mbuf.MH_ALIGN(pkt_mbuf,Mbuf.MHLEN);
      data := Mbuf.m_copym(pkt_mbuf,0,len,Mbuf.M_WAIT);
      this.pkt.mh_hdr.mh_next := data;
    END;
    MbufPublic.SetPktHdrLen(this.pkt,len);