27 #include <sys/socket.h>
29 #include <sys/ioctl.h>
30 #include <net/ethernet.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
35 #include "creator-utils.h"
36 #include "encode-decode.h"
52 SendSocket (
const char *path,
int fd,
const int magic_number)
58 LOG (
"Create Unix socket");
59 int sock = socket (PF_UNIX, SOCK_DGRAM, 0);
60 ABORT_IF (sock == -1,
"Unable to open socket", 1);
69 socklen_t clientAddrLen;
70 struct sockaddr_un clientAddr;
72 LOG (
"Decode address " << path);
74 ABORT_IF (rc ==
false,
"Unable to decode path", 0);
77 int status = connect (sock, (
struct sockaddr*)&clientAddr, clientAddrLen);
78 ABORT_IF (status == -1,
"Unable to connect to emu device", 1);
99 uint32_t magic = magic_number;
100 iov.iov_base = &magic;
101 iov.iov_len =
sizeof(magic);
114 size_t msg_size =
sizeof(int);
115 char control[CMSG_SPACE (msg_size)];
133 msg.msg_control = control;
134 msg.msg_controllen =
sizeof (control);
148 struct cmsghdr *cmsg;
149 cmsg = CMSG_FIRSTHDR (&msg);
150 cmsg->cmsg_level = SOL_SOCKET;
151 cmsg->cmsg_type = SCM_RIGHTS;
152 cmsg->cmsg_len = CMSG_LEN (msg_size);
157 msg.msg_controllen = cmsg->cmsg_len;
163 int *fdptr = (
int*)(CMSG_DATA (cmsg));
169 ssize_t len = sendmsg (sock, &msg, 0);
170 ABORT_IF (len == -1,
"Could not send socket back to emu net device", 1);
172 LOG (
"sendmsg complete");
void SendSocket(const char *path, int fd, const int magic_number)
Send the file descriptor back to the code that invoked the creation.
bool StringToBuffer(std::string s, uint8_t *buffer, uint32_t *len)
Convert string encoded by the inverse function (TapBufferToString) back into a byte buffer...