aboutsummaryrefslogtreecommitdiff
path: root/src/client.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2015-12-03 17:57:36 -0500
committerFranklin Wei <git@fwei.tk>2015-12-03 17:57:36 -0500
commit1c795424fde9839ab6ebfd49ce7a84ac946be3c0 (patch)
tree2a33473d1ada10efe52b770ce9ec8ab2d452ec20 /src/client.c
downloadnetcosm-1c795424fde9839ab6ebfd49ce7a84ac946be3c0.zip
netcosm-1c795424fde9839ab6ebfd49ce7a84ac946be3c0.tar.gz
netcosm-1c795424fde9839ab6ebfd49ce7a84ac946be3c0.tar.bz2
netcosm-1c795424fde9839ab6ebfd49ce7a84ac946be3c0.tar.xz
initial commit
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c
new file mode 100644
index 0000000..e907172
--- /dev/null
+++ b/src/client.c
@@ -0,0 +1,47 @@
+#include "netcosm.h"
+
+int client_fd;
+
+void __attribute__((format(printf,1,2))) out(const char *fmt, ...)
+{
+ char buf[128];
+ memset(buf, 0, sizeof(buf));
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+ write(client_fd, buf, sizeof(buf));
+}
+
+char *client_read(void)
+{
+ static char buf[128];
+ if(read(client_fd, buf, sizeof(buf) - 1) < 0)
+ {
+ error("lost connection");
+ exit(EXIT_FAILURE);
+ }
+ buf[sizeof(buf) - 1] = '\0';
+ const unsigned char ctrlc[] = { 0xff, 0xf4, 0xff, 0xfd, 0x06 };
+
+ if(!memcmp(buf, ctrlc, sizeof(ctrlc)))
+ exit(0);
+
+ return buf;
+}
+
+void client_main(int fd, struct sockaddr_in *addr, int total)
+{
+ client_fd = fd;
+
+ bool admin = false;
+
+ char *ip = inet_ntoa(addr->sin_addr);
+ printf("New client %s\n", ip);
+ printf("Total clients: %d\n", total);
+ out("Hello %s.\n", ip);
+ out("Please authenticate to continue.\n");
+ out("login: ");
+ char *input = client_read();
+
+}