git ssb

0+

cel / electrumc



Commit fb6db7d0171f85ee76abb0f0ee5f1827c5eec31e

handle ipv6 address

cel committed on 11/20/2018, 1:18:57 AM
Parent: acdef9a7ba5130985c8c1d04af27b5cfccd2bf16

Files changed

electrumc.cchanged
test.shchanged
electrumc.cView
@@ -93,19 +93,21 @@
9393 host = argv[1];
9494 method = argv[2];
9595 params = argc == 3 ? NULL : argv[3];
9696
97- port = strchr(host, ':');
98- if (!port) errx(1, "address should be in format <host>:<port>:<type>");
99- *port++ = '\0';
100- type = strchr(port, ':');
101- if (!type) errx(1, "address type missing");
97 + type = strrchr(host, ':');
98 + if (!type) errx(1, "address should be in format <host>:<port>:<type>");
10299 *type++ = '\0';
103-
104100 if (!strcmp(type, "t")) use_ssl = false;
105101 else if (!strcmp(type, "s")) use_ssl = true;
106- else errx(1, "address type must be 't' or 's'");
102 + else errx(1, "address type must be 't' or 's', but found: '%s'", type);
107103
104 + port = strrchr(host, ':');
105 + if (!port) errx(1, "address should be in format <host>:<port>:<type>");
106 + *port++ = '\0';
107 +
108 + if (!*host) errx(1, "address hostname missing");
109 +
108110 if (use_ssl) {
109111 ssl_ctx = SSL_CTX_new(TLS_client_method());
110112 if (ssl_ctx == NULL) errx(1, "failed to create ssl context");
111113 (void)SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY);
test.shView
@@ -1,11 +1,11 @@
11 #!/bin/sh
22
3-nc -l -p 9898 <<EOF | diff -u - /dev/fd/3 3<<EOF3 &
3 +nc6 -l -p 9898 <<EOF | diff -u - /dev/fd/3 3<<EOF3 &
44 {"jsonrpc": "2.0", "result": {"confirmed": 0, "unconfirmed": 0}, "id": 0}
55 EOF
66 {"id":0,"method":"foo","params":"bar"}
77 EOF3
88 sleep 0.1
9-./electrumc localhost:9898:t foo \"bar\" | diff -u - /dev/fd/3 3<<EOF3
9 +./electrumc ::1:9898:t foo \"bar\" | diff -u - /dev/fd/3 3<<EOF3
1010 {"jsonrpc": "2.0", "result": {"confirmed": 0, "unconfirmed": 0}, "id": 0}
1111 EOF3

Built with git-ssb-web