summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/hdlc.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1999-04-03 11:54:00 +0000
committerbrian <brian@FreeBSD.org>1999-04-03 11:54:00 +0000
commit5db8066ee9cdb955373c32193af6f95f65e204fb (patch)
treea9278079799020a63ed0219bfde87099a328fb4f /usr.sbin/ppp/hdlc.c
parentaffd55a23b9e3a35ceccf2ae330484d3cd15000d (diff)
downloadFreeBSD-src-5db8066ee9cdb955373c32193af6f95f65e204fb.zip
FreeBSD-src-5db8066ee9cdb955373c32193af6f95f65e204fb.tar.gz
Handle the detection of frames even if we read them
with more than one read(). When we detect one, don't forget to pass it to async_Input() and drop our terminal back into command mode. Don't output an extraneous \r if we're passed \r\n to prompt_vprintf in raw mode.
Diffstat (limited to 'usr.sbin/ppp/hdlc.c')
-rw-r--r--usr.sbin/ppp/hdlc.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/usr.sbin/ppp/hdlc.c b/usr.sbin/ppp/hdlc.c
index 894b2b3..2176b5f 100644
--- a/usr.sbin/ppp/hdlc.c
+++ b/usr.sbin/ppp/hdlc.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: hdlc.c,v 1.39 1999/02/11 10:14:08 brian Exp $
+ * $Id: hdlc.c,v 1.40 1999/03/29 08:21:26 brian Exp $
*
* TODO:
*/
@@ -558,35 +558,41 @@ hdlc_Input(struct bundle *bundle, struct mbuf * bp, struct physical *physical)
}
/*
- * Detect a HDLC frame
+ * Detect a HDLC frame
*/
-static const char *FrameHeaders[] = {
- "\176\377\003\300\041",
- "\176\377\175\043\300\041",
- "\176\177\175\043\100\041",
- "\176\175\337\175\043\300\041",
- "\176\175\137\175\043\100\041",
- NULL,
+static const struct frameheader {
+ const u_char *data;
+ int len;
+} FrameHeaders[] = {
+ { "\176\377\003\300\041", 5 },
+ { "\176\377\175\043\300\041", 6 },
+ { "\176\177\175\043\100\041", 6 },
+ { "\176\175\337\175\043\300\041", 7 },
+ { "\176\175\137\175\043\100\041", 7 },
+ { NULL, 0 }
};
-u_char *
-hdlc_Detect(struct physical *physical, u_char *cp, int n)
+int
+hdlc_Detect(u_char const **cp, int n, int issync)
{
- const char *fp, **hp;
- char *ptr;
-
- cp[n] = '\0'; /* be sure to null terminate */
- ptr = NULL;
- for (hp = FrameHeaders; *hp; hp++) {
- fp = *hp;
- if (physical_IsSync(physical))
- fp++;
- ptr = strstr((char *)cp, fp); /* XXX: cp may have embedded NULs */
- if (ptr)
- break;
+ const struct frameheader *fh;
+ const u_char *h;
+ size_t len, cmp;
+
+ while (n) {
+ for (fh = FrameHeaders; fh->len; fh++) {
+ h = issync ? fh->data + 1 : fh->data;
+ len = issync ? fh->len - 1 : fh->len;
+ cmp = n >= len ? len : n;
+ if (memcmp(*cp, h, cmp) == 0)
+ return cmp == len;
+ }
+ n--;
+ (*cp)++;
}
- return (u_char *)ptr;
+
+ return 0;
}
int
OpenPOWER on IntegriCloud