shithub: toe

Download patch

ref: 07d85c76c7fd2529b053282f0037455a6e0ce51f
author: Julien Blanchard <julien@sideburns.eu>
date: Fri Jun 19 14:23:36 EDT 2020

Can toe a local account, a domain and user@domain

--- /dev/null
+++ b/LICENSE
@@ -1,0 +1,21 @@
+MIT License
+
+Copyright (c) 2019-2020 Julien Blanchard
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
\ No newline at end of file
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,11 @@
+</$objtype/mkfile
+
+BIN=/$objtype/bin
+TARG=toe
+
+OFILES=\
+	toe.$O\
+
+HFILES=\
+
+</sys/src/cmd/mkone
--- /dev/null
+++ b/toe.c
@@ -1,0 +1,67 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+
+void
+visit(char *domain, char *user)
+{
+	char *naddr;
+	char *line;
+	int fd;
+	Biobuf out, body;
+
+	naddr = netmkaddr(domain, "tcp", "79");
+	fd = dial(naddr, 0, 0, 0);
+	if(fd < 0){
+		print("unable to connect to %s: %r", domain);
+		return;
+	}
+
+	if (user == nil) {
+		fprint(fd, "\r\n");
+	} else {
+		fprint(fd, "%s\r\n", user);
+	}
+	
+	Binit(&body, fd, OREAD);
+	Binit(&out, 1, OWRITE);
+
+	while((line = Brdstr(&body, '\n', 0)) != nil){
+		Bprint(&out, "%s", line);
+		free(line);
+	}
+	
+	Bflush(&out);
+	Bflush(&body);
+	close(fd);
+}
+
+void
+main(int argc, char **argv)
+{
+	char *user, *domain, *query;
+	
+	if( argc == 2 ) {
+		query = argv[1];
+
+		if (query[0] == '@') {
+			user = nil;
+			domain = query + 1;	
+		} else if (strstr(argv[1], "@") == nil) {
+			user = argv[1];
+			domain = "localhost";
+		} else {
+			user = strtok(argv[1], "@");
+			domain = strtok(nil, "@");
+		}
+				
+		visit(domain, user);
+		exits(0);
+   	}
+   	else if( argc > 2 ) {
+      	print("Too many arguments supplied.\n");
+   	}
+   	else {
+      	print("Usage: toe [user]@server.\n");
+   	}	
+}