fixup! taps: wip: init

This commit is contained in:
Else, Someone 2026-01-22 14:29:45 +02:00 committed by Else Someone
parent 8bbafe0f0a
commit 564913c123
7 changed files with 57 additions and 49 deletions

View file

@ -9,9 +9,9 @@
#include <linux/vm_sockets.h>
struct msghdr mk_msghdr();
#include "sendfd.h"
int ch_connect(const char*, const char*);
ssize_t send_fd(int, int);
#define _WRITE_CONFIRM(fd, buf, buflen) {if (write((fd), (buf), (buflen)) != (buflen)) { perror("ch-proxy/write/partial write"); exit(EXIT_FAILURE); }}
@ -168,19 +168,13 @@ int main(int argc, char** argv) {
exit(EXIT_FAILURE);
}
if (send_fd(1, s) == -1) {
if (send_fd(1, s, NULL) == -1) {
perror("ssh-vsock-proxy/main/send_fd");
return EXIT_FAILURE;
}
return 0;
}
struct msghdr mk_msghdr() {
struct msghdr msg;
memset(&msg, 0, sizeof(msg));
return msg;
}
int ch_connect(const char *path, const char *port) {
int s = socket(AF_UNIX, SOCK_STREAM, 0);
@ -212,38 +206,3 @@ int ch_connect(const char *path, const char *port) {
return s;
}
ssize_t send_fd(int dst_fd, int fd) {
struct msghdr msg = mk_msghdr();
/* openssh expects to receive a dummy length=1 iovec? */
char ch;
struct iovec vec;
vec.iov_base = &ch;
vec.iov_len = 1;
msg.msg_iov = &vec;
msg.msg_iovlen = 1;
union {
struct cmsghdr align;
char buf[CMSG_SPACE(sizeof(int))];
} u;
msg.msg_control = u.buf;
msg.msg_controllen = sizeof(u.buf);
struct cmsghdr *cmptr;
cmptr = CMSG_FIRSTHDR(&msg);
if (cmptr == NULL) {
fprintf(stderr, "ch-proxy/send_fd/CMSG_FIRSTHDR: failed to initialize msg_control\n");
exit(EXIT_FAILURE);
}
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
*((int*) CMSG_DATA(cmptr)) = fd;
return (sendmsg(dst_fd, &msg, 0));
}