git ssb

8+

cel / sbotc



Commit 0eccbd66c5ee0cffbbd4b37b8d0872b13a1ea563

Add -4, -6 options (IPv4/IPv6)

cel committed on 10/4/2018, 11:03:12 PM
Parent: 0a1eafebf9031de6ae2153de5539b4b151496dc5

Files changed

sbotc.1changed
sbotc.cchanged
sbotc.1View
@@ -20,9 +20,14 @@
2020 .
2121 .Oo
2222 .Op Fl s Ar host
2323 .Op Fl p Ar port
24 +.Oo
25 +.Fl 4
2426 |
27 +.Fl 6
28 +.Oc
29 +|
2530 .Op Fl u Ar socket_path
2631 .Oc
2732 .
2833 .Op Fl t Ar type
@@ -46,8 +51,12 @@
4651 .Fl K ,
4752 and
4853 .Fl c
4954 options have no effect and output a warning if used.
55 +.It Fl 4
56 +Connect to server over IPv4 only.
57 +.It Fl 6
58 +Connect to server over IPv6 only.
5059 .It Fl c Ar cap
5160 Capability key for secret-handshake. Default is SSB's capability key,
5261 .Li 1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s= .
5362 .It Fl s Ar host
@@ -118,8 +127,10 @@
118127 .Fl c ,
119128 .Fl k ,
120129 .Fl K ,
121130 .Fl c ,
131 +.Fl 4 ,
132 +.Fl 6 ,
122133 or
123134 .Fl T
124135 are specified,
125136 .Nm
sbotc.cView
@@ -86,8 +86,14 @@
8686 stream_state_ended_ok,
8787 stream_state_ended_error,
8888 };
8989
90 +enum ip_family {
91 + ip_family_ipv4 = AF_INET,
92 + ip_family_ipv6 = AF_INET6,
93 + ip_family_any = AF_UNSPEC
94 +};
95 +
9096 static unsigned char zeros[24] = {0};
9197
9298 static const unsigned char ssb_cap[] = {
9399 0xd4, 0xa1, 0xcb, 0x88, 0xa6, 0x6f, 0x02, 0xf8,
@@ -98,22 +104,22 @@
98104
99105 static void usage() {
100106 fputs("usage: sbotc [-j] [-T]\n"
101107 " [ -n | [-c <cap>] [-k <key>] [-K <keypair_seed>] ]\n"
102- " [ [-s <host>] [-p <port>] | [-u <socket_path>] ]\n"
108 + " [ [-s <host>] [-p <port>] [ -4 | -6 ] | [-u <socket_path>] ]\n"
103109 " [-t <type>] <method> [<argument>...]\n", stderr);
104110 exit(EXIT_FAILURE);
105111 }
106112
107-static int tcp_connect(const char *host, const char *port) {
113 +static int tcp_connect(const char *host, const char *port, enum ip_family ip_family) {
108114 struct addrinfo hints;
109115 struct addrinfo *result, *rp;
110116 int s;
111117 int fd;
112118 int err;
113119
114120 memset(&hints, 0, sizeof(hints));
115- hints.ai_family = AF_UNSPEC;
121 + hints.ai_family = ip_family;
116122 hints.ai_protocol = IPPROTO_TCP;
117123
118124 s = getaddrinfo(host, port, &hints, &result);
119125 if (s < 0) errx(1, "unable to resolve host: %s", gai_strerror(s));
@@ -862,8 +868,11 @@
862868 bool host_arg = false;
863869 bool port_arg = false;
864870 bool key_arg = false;
865871 bool shs_cap_key_str_arg = false;
872 + bool ipv4_arg = false;
873 + bool ipv6_arg = false;
874 + enum ip_family ip_family;
866875
867876 get_app_dir(app_dir, sizeof(app_dir));
868877
869878 char config_buf[8192];
@@ -892,13 +901,21 @@
892901 case 'p': port = argv[++i]; port_arg = true; break;
893902 case 'u': socket_path = argv[++i]; break;
894903 case 't': typestr = argv[++i]; break;
895904 case 'n': noauth = true; break;
905 + case '4': ipv4_arg = true; break;
906 + case '6': ipv6_arg = true; break;
896907 default: usage();
897908 }
898909 }
899910 if (i < argc) methodstr = argv[i++]; else if (!test) usage();
900911
912 + if (ipv4_arg && ipv6_arg) errx(1, "options -4 and -6 conflict");
913 + ip_family =
914 + ipv4_arg ? ip_family_ipv4 :
915 + ipv6_arg ? ip_family_ipv6 :
916 + ip_family_any;
917 +
901918 if (shs_cap_key_str) {
902919 rc = pubkey_decode(shs_cap_key_str, shs_cap_key);
903920 if (rc < 0) err(1, "unable to decode cap key '%s'", shs_cap_key_str);
904921 } else {
@@ -956,9 +973,9 @@
956973 } else {
957974 memcpy(remote_key, public_key, 32);
958975 }
959976
960- bool implied_tcp = host_arg || port_arg;
977 + bool implied_tcp = host_arg || port_arg || ipv4_arg || ipv6_arg;
961978 bool implied_auth = key_arg || keypair_seed_str || shs_cap_key_str_arg || test;
962979
963980 if (test) {
964981 infd = STDIN_FILENO;
@@ -983,9 +1000,9 @@
9831000 infd = outfd = s;
9841001
9851002 } else {
9861003 do_tcp_connect:
987- s = tcp_connect(host, port);
1004 + s = tcp_connect(host, port, ip_family);
9881005 if (s < 0) err(1, "tcp_connect");
9891006 infd = outfd = s;
9901007 }
9911008

Built with git-ssb-web