aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-04-10 17:48:42 +0200
committerHarald Welte <laforge@gnumonks.org>2017-04-10 17:48:42 +0200
commita659590e29412588bca2243b8329e82286244b00 (patch)
tree923ec56bc44b62744eef57fe367d2365beafad82 /src/stream.c
parent7cee4b67e90aeb260bde11ee7f299e507c94bc10 (diff)
stream.c: Fix endianness handling of PPID and STREAM_ID
In their infinite wisdom, the inventors of SCTP designed an API (the sockets API described in RFC6458), where some members are in host byte order (like the stream identifier), while other members are in network byte order (like the PPID). Let's handle this properly (we assumed both are network byte order), and also use 16-bit htons/ntohs fo the PPID, rather than htonl/ntohl. Change-Id: I777174ca2915c6de0063db41a745c71b4a09bbec
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/stream.c b/src/stream.c
index f899a41..f5ead17 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -162,8 +162,8 @@ static int osmo_stream_cli_write(struct osmo_stream_cli *cli)
#ifdef HAVE_LIBSCTP
case IPPROTO_SCTP:
memset(&sinfo, 0, sizeof(sinfo));
- sinfo.sinfo_ppid = htonl(msgb_sctp_ppid(msg));
- sinfo.sinfo_stream = htonl(msgb_sctp_stream(msg));
+ sinfo.sinfo_ppid = htons(msgb_sctp_ppid(msg));
+ sinfo.sinfo_stream = msgb_sctp_stream(msg);
ret = sctp_send(cli->ofd.fd, msg->data, msgb_length(msg),
&sinfo, MSG_NOSIGNAL);
break;
@@ -692,8 +692,8 @@ static void osmo_stream_srv_write(struct osmo_stream_srv *conn)
#ifdef HAVE_LIBSCTP
case IPPROTO_SCTP:
memset(&sinfo, 0, sizeof(sinfo));
- sinfo.sinfo_ppid = htonl(msgb_sctp_ppid(msg));
- sinfo.sinfo_stream = htonl(msgb_sctp_stream(msg));
+ sinfo.sinfo_ppid = htons(msgb_sctp_ppid(msg));
+ sinfo.sinfo_stream = msgb_sctp_stream(msg);
ret = sctp_send(conn->ofd.fd, msg->data, msgb_length(msg),
&sinfo, MSG_NOSIGNAL);
break;
@@ -871,8 +871,8 @@ int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg)
}
return -EAGAIN;
}
- msgb_sctp_ppid(msg) = ntohl(sinfo.sinfo_ppid);
- msgb_sctp_stream(msg) = ntohl(sinfo.sinfo_stream);
+ msgb_sctp_ppid(msg) = ntohs(sinfo.sinfo_ppid);
+ msgb_sctp_stream(msg) = sinfo.sinfo_stream;
break;
#endif
case IPPROTO_TCP: