CMSG_DATA.3 (31c472b8) CMSG_DATA.3 (c8b8b38e)
1.\" Written by Jared Yanovich <jaredy@openbsd.org>
2.\" Public domain, July 3, 2005
3.\"
4.\" $FreeBSD$
1.\" Written by Jared Yanovich <jaredy@openbsd.org>
2.\" Public domain, July 3, 2005
3.\"
4.\" $FreeBSD$
5.Dd March 13, 2020
5.Dd August 19, 2018
6.Dt CMSG_DATA 3
7.Os
8.Sh NAME
9.Nm CMSG_DATA ,
10.Nm CMSG_FIRSTHDR ,
11.Nm CMSG_LEN ,
12.Nm CMSG_NXTHDR ,
13.Nm CMSG_SPACE

--- 31 unchanged lines hidden (view full) ---

45.Pp
46The following routines are provided:
47.Bl -tag -width Ds
48.It Fn CMSG_DATA cmsg
49This routine accesses the data portion of the control message header
50.Fa cmsg .
51It ensures proper alignment constraints on the beginning of ancillary
52data are met.
6.Dt CMSG_DATA 3
7.Os
8.Sh NAME
9.Nm CMSG_DATA ,
10.Nm CMSG_FIRSTHDR ,
11.Nm CMSG_LEN ,
12.Nm CMSG_NXTHDR ,
13.Nm CMSG_SPACE

--- 31 unchanged lines hidden (view full) ---

45.Pp
46The following routines are provided:
47.Bl -tag -width Ds
48.It Fn CMSG_DATA cmsg
49This routine accesses the data portion of the control message header
50.Fa cmsg .
51It ensures proper alignment constraints on the beginning of ancillary
52data are met.
53.It Fn CMSG_FIRSTHDR msghdr
53.It Fn CMSG_FIRSTHDR mhdr
54This routine accesses the first control message attached to the
55message
54This routine accesses the first control message attached to the
55message
56.Fa msghdr .
56.Fa msg .
57If no control messages are attached to the message, this routine
58returns
59.Dv NULL .
60.It Fn CMSG_LEN len
61This routine determines the size in bytes of a control message,
62which includes the control message header.
63.Fa len
64specifies the length of the data held by the control message.
65This value is what is normally stored in the
66.Fa cmsg_len
67of each control message.
68This routine accounts for any alignment constraints on the beginning of
69ancillary data.
57If no control messages are attached to the message, this routine
58returns
59.Dv NULL .
60.It Fn CMSG_LEN len
61This routine determines the size in bytes of a control message,
62which includes the control message header.
63.Fa len
64specifies the length of the data held by the control message.
65This value is what is normally stored in the
66.Fa cmsg_len
67of each control message.
68This routine accounts for any alignment constraints on the beginning of
69ancillary data.
70.It Fn CMSG_NXTHDR msghdr cmsg
70.It Fn CMSG_NXTHDR mhdr cmsg
71This routine returns the location of the control message following
72.Fa cmsg
73in the message
71This routine returns the location of the control message following
72.Fa cmsg
73in the message
74.Fa msghdr .
74.Fa mhdr .
75If
76.Fa cmsg
77is the last control message in the chain, this routine returns
78.Dv NULL .
79.It Fn CMSG_SPACE len
80This routine determines the size in bytes needed to hold a control
81message and its contents of length
82.Fa len ,

--- 54 unchanged lines hidden (view full) ---

137 if (msg.msg_flags & (MSG_CTRUNC | MSG_TRUNC))
138 errx(EX_IOERR, "control message truncated");
139 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
140 cmsg = CMSG_NXTHDR(&msg, cmsg)) {
141 if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) &&
142 cmsg->cmsg_level == SOL_SOCKET &&
143 cmsg->cmsg_type == SCM_RIGHTS) {
144 hellofd[1] = *(int *)CMSG_DATA(cmsg);
75If
76.Fa cmsg
77is the last control message in the chain, this routine returns
78.Dv NULL .
79.It Fn CMSG_SPACE len
80This routine determines the size in bytes needed to hold a control
81message and its contents of length
82.Fa len ,

--- 54 unchanged lines hidden (view full) ---

137 if (msg.msg_flags & (MSG_CTRUNC | MSG_TRUNC))
138 errx(EX_IOERR, "control message truncated");
139 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
140 cmsg = CMSG_NXTHDR(&msg, cmsg)) {
141 if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) &&
142 cmsg->cmsg_level == SOL_SOCKET &&
143 cmsg->cmsg_type == SCM_RIGHTS) {
144 hellofd[1] = *(int *)CMSG_DATA(cmsg);
145 printf("child: sending '%s'\\n", buf);
145 printf("child: sending '%s'\n", buf);
146 if (write(hellofd[1], buf, HELLOLEN) == -1)
147 err(EX_IOERR, "failed to send 'hello'");
148 }
149 }
150 break;
151 default:
152 close(presharedfd[1]);
153

--- 6 unchanged lines hidden (view full) ---

160 cmsg->cmsg_type = SCM_RIGHTS;
161 *(int *)CMSG_DATA(cmsg) = hellofd[1];
162
163 if (sendmsg(presharedfd[0], &msg, 0) == -1)
164 err(EX_IOERR, "sendmsg");
165 close(hellofd[1]);
166
167 if (read(hellofd[0], buf, HELLOLEN) == -1)
146 if (write(hellofd[1], buf, HELLOLEN) == -1)
147 err(EX_IOERR, "failed to send 'hello'");
148 }
149 }
150 break;
151 default:
152 close(presharedfd[1]);
153

--- 6 unchanged lines hidden (view full) ---

160 cmsg->cmsg_type = SCM_RIGHTS;
161 *(int *)CMSG_DATA(cmsg) = hellofd[1];
162
163 if (sendmsg(presharedfd[0], &msg, 0) == -1)
164 err(EX_IOERR, "sendmsg");
165 close(hellofd[1]);
166
167 if (read(hellofd[0], buf, HELLOLEN) == -1)
168 err(EX_IOERR, "failed to receive 'hello'");
169 printf("parent: received '%s'\\n", buf);
168 err(EX_IOERR, "faild to receive 'hello'");
169 printf("parent: received '%s'\n", buf);
170 break;
171 }
172
173 return (0);
174}
175.Ed
176.Sh SEE ALSO
177.Xr recvmsg 2 ,

--- 37 unchanged lines hidden ---
170 break;
171 }
172
173 return (0);
174}
175.Ed
176.Sh SEE ALSO
177.Xr recvmsg 2 ,

--- 37 unchanged lines hidden ---