From a659590e29412588bca2243b8329e82286244b00 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 10 Apr 2017 17:48:42 +0200 Subject: 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 --- src/stream.c | 12 ++++++------ 1 file 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: -- cgit v1.2.3