aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kerrisk <mtk.manpages@gmail.com>2016-04-22 10:00:25 +0200
committerMichael Kerrisk <mtk.manpages@gmail.com>2016-04-22 10:00:25 +0200
commit6cd7a2c6dac333e33aa49c280359da9805f7141d (patch)
tree1412caa7f1b1c841fa110ea2b4a1b5f27cfa4663
parent03117dc0dbf8982b673a47ca3b88936b5fea227e (diff)
downloadman-pages-6cd7a2c6dac333e33aa49c280359da9805f7141d.tar.gz
cmsg.3: Minor cosmetic changes to example code
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
-rw-r--r--man3/cmsg.321
1 files changed, 9 insertions, 12 deletions
diff --git a/man3/cmsg.3 b/man3/cmsg.3
index 16f78aad33..45571ca260 100644
--- a/man3/cmsg.3
+++ b/man3/cmsg.3
@@ -173,8 +173,9 @@ int *ttlptr;
int received_ttl;
/* Receive auxiliary data in msgh */
+
for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
- cmsg = CMSG_NXTHDR(&msgh,cmsg)) {
+ cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
if (cmsg\->cmsg_level == IPPROTO_IP
&& cmsg\->cmsg_type == IP_TTL) {
ttlptr = (int *) CMSG_DATA(cmsg);
@@ -182,11 +183,9 @@ for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
break;
}
}
+
if (cmsg == NULL) {
- /*
- * Error: IP_TTL not enabled or small buffer
- * or I/O error.
- */
+ /* Error: IP_TTL not enabled or small buffer or I/O error */
}
.fi
.in
@@ -199,14 +198,13 @@ UNIX domain socket using
.nf
struct msghdr msg = {0};
struct cmsghdr *cmsg;
-int myfds[NUM_FD]; /* Contains the file descriptors to pass. */
-union {
- /* ancillary data buffer, wrapped in a union in order to ensure
- it is suitably aligned */
+int myfds[NUM_FD]; /* Contains the file descriptors to pass */
+int *fdptr;
+union { /* Ancillary data buffer, wrapped in a union
+ in order to ensure it is suitably aligned */
char buf[CMSG_SPACE(sizeof myfds)];
struct cmsghdr align;
} u;
-int *fdptr;
msg.msg_control = u.buf;
msg.msg_controllen = sizeof u.buf;
@@ -214,8 +212,7 @@ cmsg = CMSG_FIRSTHDR(&msg);
cmsg\->cmsg_level = SOL_SOCKET;
cmsg\->cmsg_type = SCM_RIGHTS;
cmsg\->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
-/* Initialize the payload: */
-fdptr = (int *) CMSG_DATA(cmsg);
+fdptr = (int *) CMSG_DATA(cmsg); /* Initialize the payload */
memcpy(fdptr, myfds, NUM_FD * sizeof(int));
.fi
.in