NN_CMSG(3)

πŸ“¦
version 1.2.2 Β· 5 versions
, in fedora 44

πŸ’– NN_CMSG(3) πŸ’–

okay bestie, welcome to nanomsg (vibes version 1.2.2, if u were wondering) πŸ’… this page is all about nn_cmsg and the little functions that let u peek at the extra lil goodies glued onto ur messages. yes it's giving ✨access control information✨, no cap.


πŸŽ€ NAME πŸŽ€

nn_cmsg β€” access control information. literally the tools for reading the bonus data hanging off ur messages 🫢


✨ SYNOPSIS ✨

#include <nanomsg/nn.h>

struct nn_cmsghdr *NN_CMSG_FIRSTHDR(struct nn_msghdr *hdr);

struct nn_cmsghdr *NN_CMSG_NXTHDR(struct nn_msghdr *hdr, struct
nn_cmsghdr *cmsg);

unsigned char *NN_CMSG_DATA(struct nn_cmsghdr *cmsg);

size_t NN_CMSG_SPACE(size_t len);

size_t NN_CMSG_LEN(size_t len);

πŸ¦‹ DESCRIPTION πŸ¦‹

so these functions? they're how u iterate over ancillary data attached to a message. think of it like the side quests of ur message β€” extra properties riding along for the trip 🌈

the struct, bestie πŸ‘‘

The structure nn_cmsghdr represents a single ancillary property and it's got these members:

size_t cmsg_len;
int cmsg_level;
int cmsg_type;
  • cmsg_len β€” the size of the property data, including the nn_cmsghdr structure that comes right before it. yes it counts itself, iconic πŸ’…
  • cmsg_level β€” the level of the property. same values as u'd use with nn_getsockopt(3) and nn_setsockopt(3), slay ✨
  • cmsg_type β€” the name of the property. these names are specific to each level, so don't go mixin' 'em up πŸ™ˆ

the functions, one by one 🌸

  • NN_CMSG_FIRSTHDR β€” returns a pointer to the first nn_cmsghdr in the control buffer inside the nn_msghdr structure u handed over. ur entry point, ur main character moment πŸ‘‘
  • NN_CMSG_NXTHDR β€” returns the next nn_cmsghdr after the one u supplied. if there isn't enough space left in the buffer it returns NULL. that's ur stop signal, no drama πŸ’€
  • NN_CMSG_DATA β€” returns a pointer to the data associated with the nn_cmsghdr u gave it. the actual payload, the real one πŸ“
  • NN_CMSG_SPACE β€” returns the number of bytes occupied by nn_cmsghdr with a payload of the specified length. math girlies rise 🧚
  • NN_CMSG_LEN β€” returns the value to store in the cmsg_len member of the cmsghdr structure, taking into account any necessary alignment. alignment matters, don't skip it fr fr ⭐

πŸ”₯ EXAMPLE πŸ”₯

iterating over ancillary properties, like a lil loop-de-loop:

struct nn_cmsghdr *hdr = NN_CMSG_FIRSTHDR (&msg);
while (hdr != NULL) {
    size_t len = hdr->cmsg_len - sizeof (nn_cmsghdr);
    printf ("level: %d property: %d length: %dB data: ",
        (int) hdr->cmsg_level,
        (int) hdr->cmsg_type,
        (int) len);
    unsigned char *data = NN_CMSG_DATA(hdr);
    while (len) {
        printf ("%02X", *data);
        ++data;
        --len;
    }
    printf ("\n");
    hdr = NN_CMSG_NXTHDR (&msg, hdr);
}

see how it just keeps going until hdr is NULL? that's the whole vibe check right there πŸ’œ


🌈 SEE ALSO 🌈

nn_sendmsg(3) nn_recvmsg(3) nn_getsockopt(3) nn_setsockopt(3) nanomsg(7)

go read those too, they're all connected, iykyk πŸ¦‹


πŸ’œ AUTHORS πŸ’œ

Martin Sustrik <sustrik@250bpm.com> β€” the og, we stan 🫢


kay that's the whole page bestie!! go forth and iterate ur ancillary data with confidence πŸ’–βœ¨

nanomsg 1.2.2, dated 2026-01-16 β€” mwah, love u, bye πŸ’…πŸŽ€

πŸ“¦ where this page comes from