summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2011-05-02 22:32:29 +0000
committerratchov <ratchov@openbsd.org>2011-05-02 22:32:29 +0000
commitb5fec221881e61c0314348d9bcd18146bfd75aad (patch)
treed3d51dea8e57a8cac3c566c41f3a0356e6ef5c7f
parentset the TCP_NODELAY option for TCP connections (diff)
downloadwireguard-openbsd-b5fec221881e61c0314348d9bcd18146bfd75aad.tar.xz
wireguard-openbsd-b5fec221881e61c0314348d9bcd18146bfd75aad.zip
Add missing byter order conversions in message headers. Fixes the case
when the server and the client are not of the same endianness. Found by naddy.
-rw-r--r--lib/libsndio/aucat.c24
-rw-r--r--lib/libsndio/sio_aucat.c64
-rw-r--r--usr.bin/aucat/sock.c146
3 files changed, 125 insertions, 109 deletions
diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c
index ba8016b43a1..d28ad40e795 100644
--- a/lib/libsndio/aucat.c
+++ b/lib/libsndio/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.47 2011/05/02 22:24:23 ratchov Exp $ */
+/* $OpenBSD: aucat.c,v 1.48 2011/05/02 22:32:29 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -69,8 +69,8 @@ aucat_rmsg(struct aucat *hdl, int *eof)
}
hdl->rtodo -= n;
}
- if (hdl->rmsg.cmd == AMSG_DATA) {
- hdl->rtodo = hdl->rmsg.u.data.size;
+ if (ntohl(hdl->rmsg.cmd) == AMSG_DATA) {
+ hdl->rtodo = ntohl(hdl->rmsg.u.data.size);
hdl->rstate = RSTATE_DATA;
} else {
hdl->rtodo = sizeof(struct amsg);
@@ -109,8 +109,8 @@ aucat_wmsg(struct aucat *hdl, int *eof)
}
hdl->wtodo -= n;
}
- if (hdl->wmsg.cmd == AMSG_DATA) {
- hdl->wtodo = hdl->wmsg.u.data.size;
+ if (ntohl(hdl->wmsg.cmd) == AMSG_DATA) {
+ hdl->wtodo = ntohl(hdl->wmsg.u.data.size);
hdl->wstate = WSTATE_DATA;
} else {
hdl->wtodo = 0xdeadbeef;
@@ -165,8 +165,8 @@ aucat_wdata(struct aucat *hdl, const void *buf, size_t len, unsigned wbpf, int *
len -= len % wbpf;
if (len == 0)
len = wbpf;
- hdl->wmsg.cmd = AMSG_DATA;
- hdl->wmsg.u.data.size = len;
+ hdl->wmsg.cmd = htonl(AMSG_DATA);
+ hdl->wmsg.u.data.size = htonl(len);
hdl->wtodo = sizeof(struct amsg);
hdl->wstate = WSTATE_MSG;
/* FALLTHROUGH */
@@ -423,16 +423,16 @@ aucat_open(struct aucat *hdl, const char *str, unsigned mode, int isaudio)
* say hello to server
*/
AMSG_INIT(&hdl->wmsg);
- hdl->wmsg.cmd = AMSG_AUTH;
+ hdl->wmsg.cmd = htonl(AMSG_AUTH);
if (!aucat_mkcookie(hdl->wmsg.u.auth.cookie))
goto bad_connect;
hdl->wtodo = sizeof(struct amsg);
if (!aucat_wmsg(hdl, &eof))
goto bad_connect;
AMSG_INIT(&hdl->wmsg);
- hdl->wmsg.cmd = AMSG_HELLO;
+ hdl->wmsg.cmd = htonl(AMSG_HELLO);
hdl->wmsg.u.hello.version = AMSG_VERSION;
- hdl->wmsg.u.hello.mode = mode;
+ hdl->wmsg.u.hello.mode = htons(mode);
strlcpy(hdl->wmsg.u.hello.who, __progname,
sizeof(hdl->wmsg.u.hello.who));
strlcpy(hdl->wmsg.u.hello.opt, opt,
@@ -445,7 +445,7 @@ aucat_open(struct aucat *hdl, const char *str, unsigned mode, int isaudio)
DPRINTF("aucat_init: mode refused\n");
goto bad_connect;
}
- if (hdl->rmsg.cmd != AMSG_ACK) {
+ if (ntohl(hdl->rmsg.cmd) != AMSG_ACK) {
DPRINTF("aucat_init: protocol err\n");
goto bad_connect;
}
@@ -463,7 +463,7 @@ aucat_close(struct aucat *hdl, int eof)
if (!eof) {
AMSG_INIT(&hdl->wmsg);
- hdl->wmsg.cmd = AMSG_BYE;
+ hdl->wmsg.cmd = htonl(AMSG_BYE);
hdl->wtodo = sizeof(struct amsg);
if (!aucat_wmsg(hdl, &eof))
goto bad_close;
diff --git a/lib/libsndio/sio_aucat.c b/lib/libsndio/sio_aucat.c
index abdce5efb64..8186298d967 100644
--- a/lib/libsndio/sio_aucat.c
+++ b/lib/libsndio/sio_aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sio_aucat.c,v 1.5 2011/04/18 23:57:35 ratchov Exp $ */
+/* $OpenBSD: sio_aucat.c,v 1.6 2011/05/02 22:32:29 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -80,36 +80,42 @@ static struct sio_ops sio_aucat_ops = {
static int
sio_aucat_runmsg(struct sio_aucat_hdl *hdl)
{
+ int delta;
+ unsigned size, ctl;
+
if (!aucat_rmsg(&hdl->aucat, &hdl->sio.eof))
return 0;
- switch (hdl->aucat.rmsg.cmd) {
+ switch (ntohl(hdl->aucat.rmsg.cmd)) {
case AMSG_DATA:
- if (hdl->aucat.rmsg.u.data.size == 0 ||
- hdl->aucat.rmsg.u.data.size % hdl->rbpf) {
+ size = ntohl(hdl->aucat.rmsg.u.data.size);
+ if (size == 0 || size % hdl->rbpf) {
DPRINTF("sio_aucat_runmsg: bad data message\n");
hdl->sio.eof = 1;
return 0;
}
return 1;
case AMSG_POS:
- hdl->maxwrite += hdl->aucat.rmsg.u.ts.delta * (int)hdl->wbpf;
+ delta = ntohl(hdl->aucat.rmsg.u.ts.delta);
+ hdl->maxwrite += delta * (int)hdl->wbpf;
DPRINTF("aucat: pos = %d, maxwrite = %d\n",
- hdl->aucat.rmsg.u.ts.delta, hdl->maxwrite);
- hdl->delta = hdl->aucat.rmsg.u.ts.delta;
+ delta, hdl->maxwrite);
+ hdl->delta = delta;
break;
case AMSG_MOVE:
- hdl->maxwrite += hdl->aucat.rmsg.u.ts.delta * hdl->wbpf;
- hdl->delta += hdl->aucat.rmsg.u.ts.delta;
+ delta = ntohl(hdl->aucat.rmsg.u.ts.delta);
+ hdl->maxwrite += delta * hdl->wbpf;
+ hdl->delta += delta;
DPRINTF("aucat: move = %d, delta = %d, maxwrite = %d\n",
- hdl->aucat.rmsg.u.ts.delta, hdl->delta, hdl->maxwrite);
+ delta, hdl->delta, hdl->maxwrite);
if (hdl->delta >= 0) {
sio_onmove_cb(&hdl->sio, hdl->delta);
hdl->delta = 0;
}
break;
case AMSG_SETVOL:
- hdl->curvol = hdl->reqvol = hdl->aucat.rmsg.u.vol.ctl;
- sio_onvol_cb(&hdl->sio, hdl->curvol);
+ ctl = ntohl(hdl->aucat.rmsg.u.vol.ctl);
+ hdl->curvol = hdl->reqvol = ctl;
+ sio_onvol_cb(&hdl->sio, ctl);
break;
case AMSG_STOP:
hdl->pstate = PSTATE_INIT;
@@ -130,8 +136,8 @@ sio_aucat_buildmsg(struct sio_aucat_hdl *hdl)
if (hdl->curvol != hdl->reqvol) {
hdl->aucat.wstate = WSTATE_MSG;
hdl->aucat.wtodo = sizeof(struct amsg);
- hdl->aucat.wmsg.cmd = AMSG_SETVOL;
- hdl->aucat.wmsg.u.vol.ctl = hdl->reqvol;
+ hdl->aucat.wmsg.cmd = htonl(AMSG_SETVOL);
+ hdl->aucat.wmsg.u.vol.ctl = htonl(hdl->reqvol);
hdl->curvol = hdl->reqvol;
return aucat_wmsg(&hdl->aucat, &hdl->sio.eof);
}
@@ -186,7 +192,7 @@ sio_aucat_start(struct sio_hdl *sh)
DPRINTF("aucat: start, maxwrite = %d\n", hdl->maxwrite);
AMSG_INIT(&hdl->aucat.wmsg);
- hdl->aucat.wmsg.cmd = AMSG_START;
+ hdl->aucat.wmsg.cmd = htonl(AMSG_START);
hdl->aucat.wtodo = sizeof(struct amsg);
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
return 0;
@@ -231,7 +237,7 @@ sio_aucat_stop(struct sio_hdl *sh)
* send stop message
*/
AMSG_INIT(&hdl->aucat.wmsg);
- hdl->aucat.wmsg.cmd = AMSG_STOP;
+ hdl->aucat.wmsg.cmd = htonl(AMSG_STOP);
hdl->aucat.wtodo = sizeof(struct amsg);
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
return 0;
@@ -260,19 +266,19 @@ sio_aucat_setpar(struct sio_hdl *sh, struct sio_par *par)
struct sio_aucat_hdl *hdl = (struct sio_aucat_hdl *)sh;
AMSG_INIT(&hdl->aucat.wmsg);
- hdl->aucat.wmsg.cmd = AMSG_SETPAR;
+ hdl->aucat.wmsg.cmd = htonl(AMSG_SETPAR);
hdl->aucat.wmsg.u.par.bits = par->bits;
hdl->aucat.wmsg.u.par.bps = par->bps;
hdl->aucat.wmsg.u.par.sig = par->sig;
hdl->aucat.wmsg.u.par.le = par->le;
hdl->aucat.wmsg.u.par.msb = par->msb;
- hdl->aucat.wmsg.u.par.rate = par->rate;
- hdl->aucat.wmsg.u.par.appbufsz = par->appbufsz;
+ hdl->aucat.wmsg.u.par.rate = htonl(par->rate);
+ hdl->aucat.wmsg.u.par.appbufsz = htonl(par->appbufsz);
hdl->aucat.wmsg.u.par.xrun = par->xrun;
if (hdl->sio.mode & SIO_REC)
- hdl->aucat.wmsg.u.par.rchan = par->rchan;
+ hdl->aucat.wmsg.u.par.rchan = htons(par->rchan);
if (hdl->sio.mode & SIO_PLAY)
- hdl->aucat.wmsg.u.par.pchan = par->pchan;
+ hdl->aucat.wmsg.u.par.pchan = htons(par->pchan);
hdl->aucat.wtodo = sizeof(struct amsg);
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
return 0;
@@ -285,14 +291,14 @@ sio_aucat_getpar(struct sio_hdl *sh, struct sio_par *par)
struct sio_aucat_hdl *hdl = (struct sio_aucat_hdl *)sh;
AMSG_INIT(&hdl->aucat.wmsg);
- hdl->aucat.wmsg.cmd = AMSG_GETPAR;
+ hdl->aucat.wmsg.cmd = htonl(AMSG_GETPAR);
hdl->aucat.wtodo = sizeof(struct amsg);
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
return 0;
hdl->aucat.rtodo = sizeof(struct amsg);
if (!aucat_rmsg(&hdl->aucat, &hdl->sio.eof))
return 0;
- if (hdl->aucat.rmsg.cmd != AMSG_GETPAR) {
+ if (ntohl(hdl->aucat.rmsg.cmd) != AMSG_GETPAR) {
DPRINTF("sio_aucat_getpar: protocol err\n");
hdl->sio.eof = 1;
return 0;
@@ -302,15 +308,15 @@ sio_aucat_getpar(struct sio_hdl *sh, struct sio_par *par)
par->sig = hdl->aucat.rmsg.u.par.sig;
par->le = hdl->aucat.rmsg.u.par.le;
par->msb = hdl->aucat.rmsg.u.par.msb;
- par->rate = hdl->aucat.rmsg.u.par.rate;
- par->bufsz = hdl->aucat.rmsg.u.par.bufsz;
- par->appbufsz = hdl->aucat.rmsg.u.par.appbufsz;
+ par->rate = ntohl(hdl->aucat.rmsg.u.par.rate);
+ par->bufsz = ntohl(hdl->aucat.rmsg.u.par.bufsz);
+ par->appbufsz = ntohl(hdl->aucat.rmsg.u.par.appbufsz);
par->xrun = hdl->aucat.rmsg.u.par.xrun;
- par->round = hdl->aucat.rmsg.u.par.round;
+ par->round = ntohl(hdl->aucat.rmsg.u.par.round);
if (hdl->sio.mode & SIO_PLAY)
- par->pchan = hdl->aucat.rmsg.u.par.pchan;
+ par->pchan = ntohs(hdl->aucat.rmsg.u.par.pchan);
if (hdl->sio.mode & SIO_REC)
- par->rchan = hdl->aucat.rmsg.u.par.rchan;
+ par->rchan = ntohs(hdl->aucat.rmsg.u.par.rchan);
return 1;
}
diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c
index 4fe4b6b8a80..26a5252a9c6 100644
--- a/usr.bin/aucat/sock.c
+++ b/usr.bin/aucat/sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.c,v 1.58 2011/05/02 22:20:18 ratchov Exp $ */
+/* $OpenBSD: sock.c,v 1.59 2011/05/02 22:32:29 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -752,7 +752,12 @@ int
sock_setpar(struct sock *f)
{
struct amsg_par *p = &f->rmsg.u.par;
- unsigned min, max, rate;
+ unsigned min, max, rate, pchan, rchan, appbufsz;
+
+ rchan = ntohs(p->rchan);
+ pchan = ntohs(p->pchan);
+ appbufsz = ntohl(p->appbufsz);
+ rate = ntohl(p->rate);
if (AMSG_ISSET(p->bits)) {
if (p->bits < BITS_MIN || p->bits > BITS_MAX) {
@@ -799,13 +804,13 @@ sock_setpar(struct sock *f)
f->rpar.le = f->wpar.le = p->le ? 1 : 0;
if (AMSG_ISSET(p->msb))
f->rpar.msb = f->wpar.msb = p->msb ? 1 : 0;
- if (AMSG_ISSET(p->rchan) && (f->mode & MODE_RECMASK)) {
- if (p->rchan < 1)
- p->rchan = 1;
- if (p->rchan > NCHAN_MAX)
- p->rchan = NCHAN_MAX;
+ if (AMSG_ISSET(rchan) && (f->mode & MODE_RECMASK)) {
+ if (rchan < 1)
+ rchan = 1;
+ if (rchan > NCHAN_MAX)
+ rchan = NCHAN_MAX;
f->wpar.cmin = f->opt->wpar.cmin;
- f->wpar.cmax = f->opt->wpar.cmin + p->rchan - 1;
+ f->wpar.cmax = f->opt->wpar.cmin + rchan - 1;
if (f->wpar.cmax > f->opt->wpar.cmax)
f->wpar.cmax = f->opt->wpar.cmax;
#ifdef DEBUG
@@ -819,13 +824,13 @@ sock_setpar(struct sock *f)
}
#endif
}
- if (AMSG_ISSET(p->pchan) && (f->mode & MODE_PLAY)) {
- if (p->pchan < 1)
- p->pchan = 1;
- if (p->pchan > NCHAN_MAX)
- p->pchan = NCHAN_MAX;
+ if (AMSG_ISSET(pchan) && (f->mode & MODE_PLAY)) {
+ if (pchan < 1)
+ pchan = 1;
+ if (pchan > NCHAN_MAX)
+ pchan = NCHAN_MAX;
f->rpar.cmin = f->opt->rpar.cmin;
- f->rpar.cmax = f->opt->rpar.cmin + p->pchan - 1;
+ f->rpar.cmax = f->opt->rpar.cmin + pchan - 1;
if (f->rpar.cmax > f->opt->rpar.cmax)
f->rpar.cmax = f->opt->rpar.cmax;
#ifdef DEBUG
@@ -839,20 +844,20 @@ sock_setpar(struct sock *f)
}
#endif
}
- if (AMSG_ISSET(p->rate)) {
- if (p->rate < RATE_MIN)
- p->rate = RATE_MIN;
- if (p->rate > RATE_MAX)
- p->rate = RATE_MAX;
- f->round = dev_roundof(f->dev, p->rate);
- f->rpar.rate = f->wpar.rate = p->rate;
- if (!AMSG_ISSET(p->appbufsz)) {
- p->appbufsz = f->dev->bufsz / f->dev->round * f->round;
+ if (AMSG_ISSET(rate)) {
+ if (rate < RATE_MIN)
+ rate = RATE_MIN;
+ if (rate > RATE_MAX)
+ rate = RATE_MAX;
+ f->round = dev_roundof(f->dev, rate);
+ f->rpar.rate = f->wpar.rate = rate;
+ if (!AMSG_ISSET(appbufsz)) {
+ appbufsz = f->dev->bufsz / f->dev->round * f->round;
#ifdef DEBUG
if (debug_level >= 3) {
sock_dbg(f);
dbg_puts(": using ");
- dbg_putu(p->appbufsz);
+ dbg_putu(appbufsz);
dbg_puts(" fr app buffer size\n");
}
#endif
@@ -861,7 +866,7 @@ sock_setpar(struct sock *f)
if (debug_level >= 3) {
sock_dbg(f);
dbg_puts(": using ");
- dbg_putu(p->rate);
+ dbg_putu(rate);
dbg_puts("Hz sample rate, ");
dbg_putu(f->round);
dbg_puts(" fr block size\n");
@@ -894,19 +899,19 @@ sock_setpar(struct sock *f)
}
#endif
}
- if (AMSG_ISSET(p->appbufsz)) {
+ if (AMSG_ISSET(appbufsz)) {
rate = (f->mode & MODE_PLAY) ? f->rpar.rate : f->wpar.rate;
min = 1;
max = 1 + rate / f->dev->round;
min *= f->round;
max *= f->round;
- p->appbufsz += f->round - 1;
- p->appbufsz -= p->appbufsz % f->round;
- if (p->appbufsz < min)
- p->appbufsz = min;
- if (p->appbufsz > max)
- p->appbufsz = max;
- f->bufsz = p->appbufsz;
+ appbufsz += f->round - 1;
+ appbufsz -= appbufsz % f->round;
+ if (appbufsz < min)
+ appbufsz = min;
+ if (appbufsz > max)
+ appbufsz = max;
+ f->bufsz = appbufsz;
#ifdef DEBUG
if (debug_level >= 3) {
sock_dbg(f);
@@ -980,14 +985,16 @@ int
sock_hello(struct sock *f)
{
struct amsg_hello *p = &f->rmsg.u.hello;
+ unsigned mode;
+ mode = ntohs(p->mode);
#ifdef DEBUG
if (debug_level >= 3) {
sock_dbg(f);
dbg_puts(": hello from <");
dbg_puts(p->who);
dbg_puts(">, mode = ");
- dbg_putx(p->mode);
+ dbg_putx(mode);
dbg_puts(", ver ");
dbg_putu(p->version);
dbg_puts("\n");
@@ -1004,7 +1011,7 @@ sock_hello(struct sock *f)
#endif
return 0;
}
- switch (p->mode) {
+ switch (mode) {
case MODE_MIDIIN:
case MODE_MIDIOUT:
case MODE_MIDIOUT | MODE_MIDIIN:
@@ -1017,7 +1024,7 @@ sock_hello(struct sock *f)
if (debug_level >= 1) {
sock_dbg(f);
dbg_puts(": ");
- dbg_putx(p->mode);
+ dbg_putx(mode);
dbg_puts(": unsupported mode\n");
}
#endif
@@ -1028,12 +1035,12 @@ sock_hello(struct sock *f)
return 0;
if (!dev_ref(f->opt->dev))
return 0;
- if ((p->mode & MODE_REC) && (f->opt->mode & MODE_MON)) {
- p->mode &= ~MODE_REC;
- p->mode |= MODE_MON;
+ if ((mode & MODE_REC) && (f->opt->mode & MODE_MON)) {
+ mode &= ~MODE_REC;
+ mode |= MODE_MON;
}
f->dev = f->opt->dev;
- f->mode = (p->mode & f->opt->mode) & f->dev->mode;
+ f->mode = (mode & f->opt->mode) & f->dev->mode;
#ifdef DEBUG
if (debug_level >= 3) {
sock_dbg(f);
@@ -1042,7 +1049,7 @@ sock_hello(struct sock *f)
dbg_puts("\n");
}
#endif
- if (f->mode != p->mode) {
+ if (f->mode != mode) {
#ifdef DEBUG
if (debug_level >= 1) {
sock_dbg(f);
@@ -1080,8 +1087,9 @@ sock_execmsg(struct sock *f)
{
struct amsg *m = &f->rmsg;
struct abuf *obuf;
+ unsigned size, ctl;
- switch (m->cmd) {
+ switch (ntohl(m->cmd)) {
case AMSG_DATA:
#ifdef DEBUG
if (debug_level >= 4) {
@@ -1121,7 +1129,8 @@ sock_execmsg(struct sock *f)
aproc_del(f->pipe.file.rproc);
return 0;
}
- if (m->u.data.size % obuf->bpf != 0) {
+ size = ntohl(m->u.data.size);
+ if (size % obuf->bpf != 0) {
#ifdef DEBUG
if (debug_level >= 1) {
sock_dbg(f);
@@ -1132,7 +1141,7 @@ sock_execmsg(struct sock *f)
return 0;
}
f->rstate = SOCK_RDATA;
- f->rtodo = m->u.data.size / obuf->bpf;
+ f->rtodo = size / obuf->bpf;
#ifdef DEBUG
if (debug_level >= 2 &&
f->pstate != SOCK_MIDI && f->rtodo > f->rmax) {
@@ -1210,7 +1219,7 @@ sock_execmsg(struct sock *f)
else
f->pstate = SOCK_STOP;
AMSG_INIT(m);
- m->cmd = AMSG_STOP;
+ m->cmd = htonl(AMSG_STOP);
f->rstate = SOCK_RRET;
f->rtodo = sizeof(struct amsg);
break;
@@ -1256,7 +1265,7 @@ sock_execmsg(struct sock *f)
return 0;
}
AMSG_INIT(m);
- m->cmd = AMSG_GETPAR;
+ m->cmd = htonl(AMSG_GETPAR);
m->u.par.legacy_mode = f->mode;
if (f->mode & MODE_PLAY) {
m->u.par.bits = f->rpar.bits;
@@ -1264,8 +1273,8 @@ sock_execmsg(struct sock *f)
m->u.par.sig = f->rpar.sig;
m->u.par.le = f->rpar.le;
m->u.par.msb = f->rpar.msb;
- m->u.par.rate = f->rpar.rate;
- m->u.par.pchan = f->rpar.cmax - f->rpar.cmin + 1;
+ m->u.par.rate = htonl(f->rpar.rate);
+ m->u.par.pchan = htons(f->rpar.cmax - f->rpar.cmin + 1);
}
if (f->mode & MODE_RECMASK) {
m->u.par.bits = f->wpar.bits;
@@ -1273,13 +1282,13 @@ sock_execmsg(struct sock *f)
m->u.par.sig = f->wpar.sig;
m->u.par.le = f->wpar.le;
m->u.par.msb = f->wpar.msb;
- m->u.par.rate = f->wpar.rate;
- m->u.par.rchan = f->wpar.cmax - f->wpar.cmin + 1;
+ m->u.par.rate = htonl(f->wpar.rate);
+ m->u.par.rchan = htons(f->wpar.cmax - f->wpar.cmin + 1);
}
- m->u.par.appbufsz = f->bufsz;
- m->u.par.bufsz =
- f->bufsz + (f->dev->bufsz / f->dev->round) * f->round;
- m->u.par.round = f->round;
+ m->u.par.appbufsz = htonl(f->bufsz);
+ m->u.par.bufsz = htonl(
+ f->bufsz + (f->dev->bufsz / f->dev->round) * f->round);
+ m->u.par.round = htonl(f->round);
f->rstate = SOCK_RRET;
f->rtodo = sizeof(struct amsg);
break;
@@ -1301,7 +1310,8 @@ sock_execmsg(struct sock *f)
aproc_del(f->pipe.file.rproc);
return 0;
}
- if (m->u.vol.ctl > MIDI_MAXCTL) {
+ ctl = ntohl(m->u.vol.ctl);
+ if (ctl > MIDI_MAXCTL) {
#ifdef DEBUG
if (debug_level >= 1) {
sock_dbg(f);
@@ -1311,9 +1321,9 @@ sock_execmsg(struct sock *f)
aproc_del(f->pipe.file.rproc);
return 0;
}
- sock_setvol(f, m->u.vol.ctl);
+ sock_setvol(f, ctl);
if (f->slot >= 0)
- ctl_slotvol(f->dev->midi, f->slot, m->u.vol.ctl);
+ ctl_slotvol(f->dev->midi, f->slot, ctl);
f->rtodo = sizeof(struct amsg);
f->rstate = SOCK_RMSG;
break;
@@ -1363,7 +1373,7 @@ sock_execmsg(struct sock *f)
return 0;
}
AMSG_INIT(m);
- m->cmd = AMSG_ACK;
+ m->cmd = htonl(AMSG_ACK);
f->rstate = SOCK_RRET;
f->rtodo = sizeof(struct amsg);
break;
@@ -1420,8 +1430,8 @@ sock_buildmsg(struct sock *f)
}
#endif
AMSG_INIT(&f->wmsg);
- f->wmsg.cmd = AMSG_POS;
- f->wmsg.u.ts.delta = f->startpos;
+ f->wmsg.cmd = htonl(AMSG_POS);
+ f->wmsg.u.ts.delta = htonl(f->startpos);
f->rmax += f->startpos;
f->wtodo = sizeof(struct amsg);
f->wstate = SOCK_WMSG;
@@ -1444,8 +1454,8 @@ sock_buildmsg(struct sock *f)
f->wmax += f->delta;
f->rmax += f->delta;
AMSG_INIT(&f->wmsg);
- f->wmsg.cmd = AMSG_MOVE;
- f->wmsg.u.ts.delta = f->delta;
+ f->wmsg.cmd = htonl(AMSG_MOVE);
+ f->wmsg.u.ts.delta = htonl(f->delta);
f->wtodo = sizeof(struct amsg);
f->wstate = SOCK_WMSG;
f->delta = 0;
@@ -1466,8 +1476,8 @@ sock_buildmsg(struct sock *f)
}
#endif
AMSG_INIT(&f->wmsg);
- f->wmsg.cmd = AMSG_SETVOL;
- f->wmsg.u.vol.ctl = f->vol;
+ f->wmsg.cmd = htonl(AMSG_SETVOL);
+ f->wmsg.u.vol.ctl = htonl(f->vol);
f->wtodo = sizeof(struct amsg);
f->wstate = SOCK_WMSG;
f->lastvol = f->vol;
@@ -1514,8 +1524,8 @@ sock_buildmsg(struct sock *f)
size *= ibuf->bpf;
}
AMSG_INIT(&f->wmsg);
- f->wmsg.cmd = AMSG_DATA;
- f->wmsg.u.data.size = size;
+ f->wmsg.cmd = htonl(AMSG_DATA);
+ f->wmsg.u.data.size = htonl(size);
f->wtodo = sizeof(struct amsg);
f->wstate = SOCK_WMSG;
return 1;
@@ -1648,7 +1658,7 @@ sock_write(struct sock *f)
case SOCK_WMSG:
if (!sock_wmsg(f, &f->wmsg, &f->wtodo))
return 0;
- if (f->wmsg.cmd != AMSG_DATA) {
+ if (ntohl(f->wmsg.cmd) != AMSG_DATA) {
f->wstate = SOCK_WIDLE;
f->wtodo = 0xdeadbeef;
break;
@@ -1657,7 +1667,7 @@ sock_write(struct sock *f)
* XXX: why not set f->wtodo in sock_wmsg() ?
*/
f->wstate = SOCK_WDATA;
- f->wtodo = f->wmsg.u.data.size /
+ f->wtodo = ntohl(f->wmsg.u.data.size) /
LIST_FIRST(&f->pipe.file.wproc->ins)->bpf;
/* PASSTHROUGH */
case SOCK_WDATA: