NN_CMSG(3)
π 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 thenn_cmsghdrstructure that comes right before it. yes it counts itself, iconic πcmsg_levelβ the level of the property. same values as u'd use withnn_getsockopt(3)andnn_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 firstnn_cmsghdrin the control buffer inside thenn_msghdrstructure u handed over. ur entry point, ur main character moment πNN_CMSG_NXTHDRβ returns the nextnn_cmsghdrafter the one u supplied. if there isn't enough space left in the buffer it returnsNULL. that's ur stop signal, no drama πNN_CMSG_DATAβ returns a pointer to the data associated with thenn_cmsghdru gave it. the actual payload, the real one πNN_CMSG_SPACEβ returns the number of bytes occupied bynn_cmsghdrwith a payload of the specified length. math girlies rise π§NN_CMSG_LENβ returns the value to store in thecmsg_lenmember of thecmsghdrstructure, 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
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms