From 8e7e23110bc483ba647d33d6f46a7fac1302107c Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 28 Oct 2022 02:17:42 +0100 Subject: more testing and typo fixes --- bee.c | 25 ++++++++++++++++++++++++- unix.c | 4 ++-- unix.h | 1 + util.c | 4 +--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bee.c b/bee.c index 41fc24d..0cd3b13 100644 --- a/bee.c +++ b/bee.c @@ -1,4 +1,5 @@ #include "irc.h" +#include "unix.h" #include @@ -7,8 +8,30 @@ int main() { - if (irc_connect()) { fputs("falure in irc_connect\n",stderr); return 1; } + /* if (irc_connect()) { fputs("falure in irc_connect\n",stderr); return 1; } if (irc_handshake()) { fputs("failure in irc_handshake\n",stderr); return 1; } + */ + + int unixfd; + if ((unixfd = unix_setup("bees2.sock")) == -1) { + fputs("failure in unix_setup\n",stderr); return -1; + } + + char buf[128]; + ssize_t amt; + for (;;) { + if ((amt = recv(unixfd,buf,sizeof buf - 1,0)) == -1) { + perror("recv"); + return 1; + } else if (amt == 0) { + puts("unix eof"); + return 0; + } else { + buf[amt] = 0; + printf("got: %s\n",buf); + } + } + int x; do { diff --git a/unix.c b/unix.c index bbb663d..3228a0b 100644 --- a/unix.c +++ b/unix.c @@ -12,7 +12,7 @@ sock_perms(int fd) return -1; } // set group on socket - if (fchown(fd, -1, group.gr_gid) == -1) { + if (fchown(fd, -1, group->gr_gid) == -1) { perror("chown"); return -1; } @@ -47,7 +47,7 @@ unix_setup(char sockname[]) struct sockaddr_un name; memset(&name, 0, sizeof name); name.sun_family = AF_UNIX; - strncpy(name.sun_path, SOCKETNAME, (sizeof name.sun_path)-1); + strncpy(name.sun_path, sockname, (sizeof name.sun_path)-1); if (bind(sock, (struct sockaddr *)&name, sizeof name) == -1) { perror("(unix) bind"); return -1; diff --git a/unix.h b/unix.h index 410911e..57d1cfc 100644 --- a/unix.h +++ b/unix.h @@ -7,6 +7,7 @@ #include #include #include +#include // takes filename, returns socket fd diff --git a/util.c b/util.c index 3c51df7..97d705a 100644 --- a/util.c +++ b/util.c @@ -1,7 +1,5 @@ #include "util.h" - -#include -#include +#include "debug.h" ssize_t sendall(int sockfd, void *buf, size_t len) { ssize_t total_sent = 0; -- cgit v1.2.3