aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers/slip_common.c
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2005-06-13 18:52:18 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-13 23:58:43 -0400
commita3c77c67a443e631febf708bb0c376caede31657 (patch)
tree75672c8dec41054de7b635df59a9f014f6a5ad14 /arch/um/drivers/slip_common.c
parent98fdffccea6cc3fe9dba32c0fcc310bcb5d71529 (diff)
[PATCH] uml: slirp and slip driver cleanups and fixes
This patch merges a lot of duplicated code in the slip and slirp drivers, abstracts out the slip protocol, and makes the slip driver work in 2.6. Signed-off-by: Jeff Dike <jdike@addtoit.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/drivers/slip_common.c')
-rw-r--r--arch/um/drivers/slip_common.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/arch/um/drivers/slip_common.c b/arch/um/drivers/slip_common.c
new file mode 100644
index 000000000000..e89cfc68fc3e
--- /dev/null
+++ b/arch/um/drivers/slip_common.c
@@ -0,0 +1,54 @@
1#include <string.h>
2#include "slip_common.h"
3#include "net_user.h"
4
5int slip_proto_read(int fd, void *buf, int len, struct slip_proto *slip)
6{
7 int i, n, size, start;
8
9 if(slip->more > 0){
10 i = 0;
11 while(i < slip->more){
12 size = slip_unesc(slip->ibuf[i++], slip->ibuf,
13 &slip->pos, &slip->esc);
14 if(size){
15 memcpy(buf, slip->ibuf, size);
16 memmove(slip->ibuf, &slip->ibuf[i],
17 slip->more - i);
18 slip->more = slip->more - i;
19 return size;
20 }
21 }
22 slip->more = 0;
23 }
24
25 n = net_read(fd, &slip->ibuf[slip->pos],
26 sizeof(slip->ibuf) - slip->pos);
27 if(n <= 0)
28 return n;
29
30 start = slip->pos;
31 for(i = 0; i < n; i++){
32 size = slip_unesc(slip->ibuf[start + i], slip->ibuf,&slip->pos,
33 &slip->esc);
34 if(size){
35 memcpy(buf, slip->ibuf, size);
36 memmove(slip->ibuf, &slip->ibuf[start+i+1],
37 n - (i + 1));
38 slip->more = n - (i + 1);
39 return size;
40 }
41 }
42 return 0;
43}
44
45int slip_proto_write(int fd, void *buf, int len, struct slip_proto *slip)
46{
47 int actual, n;
48
49 actual = slip_esc(buf, slip->obuf, len);
50 n = net_write(fd, slip->obuf, actual);
51 if(n < 0)
52 return n;
53 else return len;
54}