Search code examples
c++socketsnetwork-programmingudpbsd

Can I use sendto() or sendmsg() to push a packet to the server's recvmmsg()?


Seeing as recvmmsg() has a counterpart sendmmsg(). I was wondering if we could use sendto() or sendmsg() instead, will recvmmsg() still work? or will we have to use sendmmsg()?

Also one more thing to note is that sendto() being the only one that does not contain the msghdr *msg parameter, upon receiving the packet with recvmmsg() will it be packed into a msghdr on arrival?


Solution

  • Yes, they're the same thing.

    From man sendmmsg

    The  sendmmsg() system call is an extension of sendmsg(2)
    that allows the caller to transmit multiple messages on 
    a socket using a single system call. (This has performance
    benefits for some applications.)
    

    So basically, when you call sendmmsg(sock, msglist, n, flags), you're doing

    for (i=0; i<n; i++)
        sendmsg(sock, msglist[i], flags);