- (void) unputc(&tp->t_outq); /* make room */
- putc(FRAME_END, &tp->t_outq); /* end the packet */
- sc->sc_if.if_oerrors++;
- } else
- sc->sc_if.if_opackets++;
+ if (flush)
+ (void) putc(FRAME_END, &tp->t_outq);
+
+ while (m) {
+ cp = mtod(m, u_char *);
+ len = m->m_len;
+ while (len > 0) {
+ /*
+ * Find out how many bytes in the string we can
+ * handle without doing something special.
+ */
+ nd = locc(FRAME_ESCAPE, len, cp);
+ np = locc(FRAME_END, len, cp);
+ n = len - MAX(nd, np);
+ if (n) {
+ /*
+ * Put n characters at once
+ * into the tty output queue.
+ */
+ if (b_to_q((char *)cp, n, &tp->t_outq))
+ break;
+ }
+ /*
+ * If there are characters left in the mbuf,
+ * the first one must be special..
+ * Put it out in a different form.
+ */
+ if (len) {
+ if (putc(FRAME_ESCAPE, &tp->t_outq))
+ break;
+ if (putc(*cp == FRAME_ESCAPE ?
+ TRANS_FRAME_ESCAPE : TRANS_FRAME_END,
+ &tp->t_outq)) {
+ (void) unputc(&tp->t_outq);
+ break;
+ }
+ cp++;
+ len--;
+ }
+ }
+ MFREE(m, m2);
+ m = m2;
+ }