about summary refs log tree commit diff homepage
path: root/client.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-10-12 14:23:36 -0400
committerJune McEnroe <june@causal.agency>2018-10-12 14:23:36 -0400
commit638ebfa03b9fec182a5384a46bdde27bc44515a0 (patch)
tree65fbb603df95fd64d2be67ad10b96c5f0f4feb3d /client.c
parentAdd -d and -s flags to server (diff)
downloadtorus-638ebfa03b9fec182a5384a46bdde27bc44515a0.tar.gz
torus-638ebfa03b9fec182a5384a46bdde27bc44515a0.zip
Add -s flag to client
Diffstat (limited to '')
-rw-r--r--client.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/client.c b/client.c
index bdbdba2..de10060 100644
--- a/client.c
+++ b/client.c
@@ -26,6 +26,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sysexits.h>
@@ -668,13 +669,16 @@ static void readInput(void) {
 }
 
 int main(int argc, char *argv[]) {
+	const char *sockPath = "torus.sock";
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "h"))) {
-		if (opt == 'h') {
-			fwrite(HelpData, sizeof(HelpData), 1, stdout);
-			return EX_OK;
-		} else {
-			return EX_USAGE;
+	while (0 < (opt = getopt(argc, argv, "hs:"))) {
+		switch (opt) {
+			break; case 'h': {
+				fwrite(HelpData, sizeof(HelpData), 1, stdout);
+				return EX_OK;
+			}
+			break; case 's': sockPath = optarg;
+			break; default:  return EX_USAGE;
 		}
 	}
 
@@ -685,12 +689,10 @@ int main(int argc, char *argv[]) {
 	client = socket(PF_LOCAL, SOCK_STREAM, 0);
 	if (client < 0) err(EX_OSERR, "socket");
 
-	struct sockaddr_un addr = {
-		.sun_family = AF_LOCAL,
-		.sun_path = "torus.sock",
-	};
-	int error = connect(client, (struct sockaddr *)&addr, sizeof(addr));
-	if (error) err(EX_NOINPUT, "torus.sock");
+	struct sockaddr_un addr = { .sun_family = AF_LOCAL };
+	strlcpy(addr.sun_path, sockPath, sizeof(addr.sun_path));
+	int error = connect(client, (struct sockaddr *)&addr, SUN_LEN(&addr));
+	if (error) err(EX_NOINPUT, "%s", sockPath);
 
 	struct pollfd fds[2] = {
 		{ .fd = STDIN_FILENO, .events = POLLIN },