libkdegames/kggzmod
misc_private.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KGGZMOD_MISC_PRIVATE_H
00022 #define KGGZMOD_MISC_PRIVATE_H
00023
00024 #include <sys/types.h>
00025 #include <sys/socket.h>
00026 #include <sys/uio.h>
00027 #include <sys/un.h>
00028 #include <arpa/inet.h>
00029 #include <netinet/in.h>
00030 #include <netdb.h>
00031
00032 #ifdef Q_OS_WIN
00033 #include <kdebug.h>
00034 #endif
00035
00036 namespace KGGZMod
00037 {
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 bool readfiledescriptor(int sock, int *recvfd)
00048 {
00049 #ifndef Q_OS_WIN
00050 struct msghdr msg;
00051 struct iovec iov[1];
00052 ssize_t n;
00053 char dummy;
00054
00055 union {
00056 struct cmsghdr cm;
00057 char control[CMSG_SPACE(sizeof(int))];
00058 } control_un;
00059 struct cmsghdr *cmptr;
00060
00061 msg.msg_control = control_un.control;
00062 msg.msg_controllen = sizeof(control_un.control);
00063
00064 msg.msg_name = NULL;
00065 msg.msg_namelen = 0;
00066
00067
00068 iov[0].iov_base = &dummy;
00069 iov[0].iov_len = 1;
00070
00071 msg.msg_iov = iov;
00072 msg.msg_iovlen = 1;
00073
00074 if ( (n = recvmsg(sock, &msg, 0)) < 0) {
00075
00076 return false;
00077 }
00078
00079 if (n == 0) {
00080
00081 return false;
00082 }
00083
00084 if ( (cmptr = CMSG_FIRSTHDR(&msg)) == NULL
00085 || cmptr->cmsg_len != CMSG_LEN(sizeof(int))) {
00086
00087 return false;
00088 }
00089
00090 if (cmptr->cmsg_level != SOL_SOCKET) {
00091
00092 return false;
00093 }
00094
00095 if (cmptr->cmsg_type != SCM_RIGHTS) {
00096
00097 return false;
00098 }
00099
00100
00101 *recvfd = *((int *) CMSG_DATA(cmptr));
00102
00103 return true;
00104 #else
00105 kError() << "This path should never be called.";
00106 return false;
00107 #endif
00108 }
00109
00110 }
00111
00112 #endif
00113