vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| usr.bin/ssh/monitor_fdpass.c has two functions to pass file descriptors between processes. These look similar to the functions in Stevens UNIX Network Programming, Vol. 1, 2nd Ed. I have a question about the size of the data and msg_controllen. monitor_fdpass.c uses: mm_send_fd(int socket, int fd) { char tmp[CMSG_SPACE(sizeof(int))]; msg.msg_controllen = CMSG_LEN(sizeof(int)); mm_receive_fd(int socket) { char tmp[CMSG_SPACE(sizeof(int))]; msg.msg_controllen = sizeof(tmp); while Stevens (Section 14.7) uses: union { struct cmsghdr cm; char control[CMSG_SPACE(sizeof(int))]; } control_un; msg.msg_controllen = sizeof(control_un.control); in both cases. Moreover, today Wietse Venema sent out a patch claiming that it is required for OpenBSD/Sparc64 (for send_fd and receive_fd): * Adapted from: W. Richard Stevens, UNIX Network Programming, Volume 1, + * Second edition. Except that we use CMSG_LEN instead of CMSG_SPACE, for + * portability to LP64 environments. union { struct cmsghdr just_for_alignment; - char control[CMSG_SPACE(sizeof(newfd))]; + char control[CMSG_LEN(sizeof(newfd))]; } control_un; - msg.msg_controllen = sizeof(control_un.control); + msg.msg_controllen = CMSG_LEN(sizeof(newfd)); /* Fix 200506 */ Unfortunately I don't have access to an OpenBSD/SPARC64 machine, so I can't test this claim. Question: what is the "correct" way to specify the sizes of the buffers and msg_controllen (for the latter: why not simply use sizeof(buffer)? ok, this would fail is someone changes the buffer to char* and allocates it). |
| Thread Tools | |
| Display Modes | |
|
|