commit - 286c4f40a54be609d0c03e8229826d9fee5ad8d3
commit + 58173ca20e1c2ca78dcb04ae194734079b89166d
blob - 4c2344bfbe79b5859348bdf0436eadada4d6b4d3
blob + 38ecf0a9ba48826f53f043161ae9c89bd27d3715
--- gg.1
+++ gg.1
.Sh SYNOPSIS
.Nm
.Bk -words
-.Op Fl 23bchNV
+.Op Fl 23bchNVv
+.Op Fl H Ar hostname
.Ar IRI
.Ek
.Sh DESCRIPTION
Print only the body of the response.
.It Fl c
Print only the response code.
+.It Fl H Ar hostname
+Use the given
+.Ar hostname
+for SNI, instead of the one extracted from the IRI.
+The IRI hostname will still be used for the DNS resolution.
.It Fl h
Print only the response header.
.It Fl N
hostname.
.It Fl V
Only validate the IRI, don't do the Gemini transaction.
+.It Fl v
+Print also the request.
.El
.Pp
Note that
blob - ab67c0cd53f76b99bc448ca9a2d65f5aa6d38140
blob + 97fb71683db2443945279974d51dea3658516673
--- gg.c
+++ gg.c
#include "gmid.h"
+int flag2, flag3, bflag, cflag, hflag, Nflag, Vflag, vflag;
+
int
main(int argc, char **argv)
{
struct tls *ctx;
char iribuf[GEMINI_URL_LEN], buf[GEMINI_URL_LEN];
const char *parse_err = "unknown error", *port = "1965";
+ const char *hostname;
char *t;
- int ch, flag2, flag3, bflag, cflag, hflag, Nflag, Vflag;
+ int ch;
+ int handshake;
ssize_t len;
- flag2 = flag3 = bflag = cflag = hflag = Nflag = Vflag = 0;
- while ((ch = getopt(argc, argv, "23cbhNV")) != -1) {
+ hostname = NULL;
+ while ((ch = getopt(argc, argv, "23cbH:hNVv")) != -1) {
switch (ch) {
case '2':
flag2 = 1;
case 'c':
cflag = 1;
break;
+ case 'H':
+ hostname = optarg;
+ break;
case 'h':
hflag = 1;
break;
case 'V':
Vflag = 1;
break;
+ case 'v':
+ vflag = 1;
+ break;
default:
- fprintf(stderr, "USAGE: %s [-23cbhNV]", *argv);
+ fprintf(stderr, "USAGE: %s [-23cbhNVv] [-H hostname]\n",
+ *argv);
return 1;
}
}
if (*iri.port != '\0')
port = iri.port;
- if (tls_connect(ctx, iri.host, port) == -1)
+
+ if (hostname == NULL)
+ hostname = iri.host;
+
+ if (tls_connect_servername(ctx, iri.host, port, hostname) == -1)
errx(1, "tls_connect: %s", tls_error(ctx));
- tls_write(ctx, buf, strlen(buf));
- /* if (tls_write(ctx, buf, strlen(buf)) != -1) */
- /* errx(1, "tls_write: %s", tls_error(ctx)); */
+ for (handshake = 0; !handshake;) {
+ switch (tls_handshake(ctx)) {
+ case 0:
+ case -1:
+ handshake = 1;
+ break;
+ }
+ }
+ if (vflag)
+ printf("%s", buf);
+ if (tls_write(ctx, buf, strlen(buf)) == -1)
+ errx(1, "tls_write: %s", tls_error(ctx));
+
for (;;) {
switch (len = tls_read(ctx, buf, sizeof(buf))) {
case 0: