PATCH/RFC use recvfrom with MSG_TRUNC as flag

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Holger Hans Peter Freyther holger at freyther.de
Fri Jul 23 11:07:55 UTC 2010


Hi Harald, Dieter,

what do you think of using MSG_TRUNC and checking if we have
truncated our packets in a recv call?

Dieter do you know if cygwin will silently ignore the MSG_TRUNC
flag or if you will have a problem on Window?



diff --git a/openbsc/src/gprs/gprs_ns.c b/openbsc/src/gprs/gprs_ns.c
index 3db1d67..ab2d937 100644
--- a/openbsc/src/gprs/gprs_ns.c
+++ b/openbsc/src/gprs/gprs_ns.c
@@ -867,7 +867,7 @@ static struct msgb *read_nsip_msg(struct bsc_fd *bfd, int *error,
                return NULL;
        }
 
-       ret = recvfrom(bfd->fd, msg->data, NS_ALLOC_SIZE - NS_ALLOC_HEADROOM, 0,
+       ret = recvfrom(bfd->fd, msg->data, NS_ALLOC_SIZE - NS_ALLOC_HEADROOM, MSG_TRUNC,
                        (struct sockaddr *)saddr, &saddr_len);
        if (ret < 0) {
                LOGP(DNS, LOGL_ERROR, "recv error %s during NSIP recv\n",
@@ -879,6 +879,11 @@ static struct msgb *read_nsip_msg(struct bsc_fd *bfd, int *error,
                msgb_free(msg);
                *error = ret;
                return NULL;
+       } else if (ret > NS_ALLOC_SIZE - NS_ALLOC_HEADROOM) {
+               LOGP(DNS, LOGL_ERROR, "truncated msg. real size is: %d\n", ret);
+               msgb_free(msg);
+               *error = -ENOSPC;
+               return NULL;
        }
 
        msg->l2h = msg->data;




More information about the OpenBSC mailing list