summaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2009-04-29 09:43:37 +0100
committerMark McLoughlin <markmc@redhat.com>2009-06-09 11:38:49 +0100
commita4586061284fdd8f2222fcdbdd1dbb25fc9c5590 (patch)
treeef09b6cc563b7b85fe30408ea72bd9aed876a645 /net.c
parentaebe05223b1ca874fdeaf3a39be4489efc9b9419 (diff)
downloadqemu-a4586061284fdd8f2222fcdbdd1dbb25fc9c5590.tar.gz
qemu-a4586061284fdd8f2222fcdbdd1dbb25fc9c5590.tar.bz2
qemu-a4586061284fdd8f2222fcdbdd1dbb25fc9c5590.zip
net: factor tap_read_packet() out of tap_send()
Move portability clutter out into its own function. Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Diffstat (limited to 'net.c')
-rw-r--r--net.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/net.c b/net.c
index 803b3352ad..da18f0f649 100644
--- a/net.c
+++ b/net.c
@@ -951,21 +951,31 @@ static void tap_receive(void *opaque, const uint8_t *buf, int size)
}
}
-static void tap_send(void *opaque)
-{
- TAPState *s = opaque;
- uint8_t buf[4096];
- int size;
-
#ifdef __sun__
+static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
+{
struct strbuf sbuf;
int f = 0;
- sbuf.maxlen = sizeof(buf);
+
+ sbuf.maxlen = maxlen;
sbuf.buf = (char *)buf;
- size = getmsg(s->fd, NULL, &sbuf, &f) >=0 ? sbuf.len : -1;
+
+ return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
+}
#else
- size = read(s->fd, buf, sizeof(buf));
+static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
+{
+ return read(tapfd, buf, maxlen);
+}
#endif
+
+static void tap_send(void *opaque)
+{
+ TAPState *s = opaque;
+ uint8_t buf[4096];
+ int size;
+
+ size = tap_read_packet(s->fd, buf, sizeof(buf));
if (size > 0) {
qemu_send_packet(s->vc, buf, size);
}