about summary refs log tree commit diff homepage
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
commitb343cae3421763035eb1ca30cc5e8143ad417064 (patch)
tree5ece2c5d9b5c7184e69cbbbca993aab399ea324d
parentAdd -d and -s flags to server (diff)
downloadtorus-b343cae3421763035eb1ca30cc5e8143ad417064.tar.gz
torus-b343cae3421763035eb1ca30cc5e8143ad417064.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 d1c11ac..7e41b5f 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 },