about summary refs log tree commit diff stats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index c36bc9a..fc5835b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -64,35 +64,35 @@ void usage(char *name) {
 }
 
 int set_loglevel(char *level) {
-	if (strncmp("emerg", level, 6) != 0) {
+	if (strncmp("emerg", level, 6) == 0) {
 		setlogmask(LOG_UPTO(LOG_EMERG));
 		return 0;
 	}
-	if (strncmp("alert", level, 6) != 0) {
+	if (strncmp("alert", level, 6) == 0) {
 		setlogmask(LOG_UPTO(LOG_ALERT));
 		return 0;
 	}
-	if (strncmp("crit", level, 5) != 0) {
+	if (strncmp("crit", level, 5) == 0) {
 		setlogmask(LOG_UPTO(LOG_CRIT));
 		return 0;
 	}
-	if (strncmp("err", level, 4) != 0) {
+	if (strncmp("err", level, 4) == 0) {
 		setlogmask(LOG_UPTO(LOG_ERR));
 		return 0;
 	}
-	if (strncmp("warn", level, 5) != 0) {
+	if (strncmp("warn", level, 5) == 0) {
 		setlogmask(LOG_UPTO(LOG_WARNING));
 		return 0;
 	}
-	if (strncmp("notice", level, 7) != 0) {
+	if (strncmp("notice", level, 7) == 0) {
 		setlogmask(LOG_UPTO(LOG_NOTICE));
 		return 0;
 	}
-	if (strncmp("info", level, 5) != 0) {
+	if (strncmp("info", level, 5) == 0) {
 		setlogmask(LOG_UPTO(LOG_INFO));
 		return 0;
 	}
-	if (strncmp("debug", level, 6) != 0) {
+	if (strncmp("debug", level, 6) == 0) {
 		setlogmask(LOG_UPTO(LOG_DEBUG));
 		return 0;
 	}
@@ -144,7 +144,7 @@ int main(int argc, char **argv) {
 				break;
 			case 'l':
 				loglevset = 1;
-				if (!set_loglevel(optarg)) {
+				if (set_loglevel(optarg)) {
 					fprintf(stderr, "invalid option for -l\n");
 					usage(argv[0]);
 					return -1;
@@ -181,7 +181,7 @@ int main(int argc, char **argv) {
 			syslog(LOG_INFO, "daemonized");
 		}
 	}
-	struct timeval timeout = { 1, 0 };
+	struct timeval timeout = { 30, 0 };
 	if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) {
 		syslog(LOG_ERR, "unable to set socket timeout: %s", strerror(errno));
 		retme = -1;
@@ -196,7 +196,7 @@ int main(int argc, char **argv) {
 		retme = -1;
 		goto cleanup;
 	}
-	syslog(LOG_INFO, "socket bind success");
+	syslog(LOG_DEBUG, "socket bind success");
 	if (daemonize) {
 		//TODO: use getpwnam_r() and getgrnam_r()
 		struct group *g = getgrnam((const char *)&group);
@@ -246,6 +246,12 @@ int main(int argc, char **argv) {
 			);
 			continue;
 		}
+		syslog(
+			LOG_INFO,
+			"got connection from %s:%d",
+			inet_ntoa(caddr.sin_addr),
+			ntohs(caddr.sin_port)
+		);
 		nbd_nbtpd_args *args = malloc(sizeof(nbd_nbtpd_args));
 		if (args == NULL) {
 			syslog(
@@ -255,7 +261,7 @@ int main(int argc, char **argv) {
 			);
 			continue;
 		}
-		nbd_tftp_opcode oc = ntohs(((uint16_t)buf[0] << 8) + buf[1]);
+		nbd_tftp_opcode oc = ((uint16_t)buf[0] << 8) + buf[1];
 		args->client = caddr;
 		args->err = 0;
 		memset(args->path, '\0', NBD_NBTPD_ARGS_PATH_MAX);
@@ -293,6 +299,9 @@ int main(int argc, char **argv) {
 		}
 		//TODO: use std threads
 		int e;
+		syslog(LOG_ERR, "spawning thread for %s", inet_ntoa(caddr.sin_addr));
+//		void *lol = func((void *)args);
+//		free(lol);
 		if ((e = pthread_create(_thread, 0, func, (void *)args)) != 0) {
 			syslog(
 				LOG_CRIT,