Live data from Hacker News

Show HN: Gemini web client in 100 lines of C

github.com

11–20 of 47 posts

Re: Show HN: Gemini web client in 100 lines of C

#11
https://github.com/ir33k/gmi100/blob/master/gmi100.c#L27 definitely threw me for a loop until I realized it was a line saving trick. It would be more readable to save lines elsewhere by exploiting the comma operator instead of essentially cramming irrelevant statements into a conditional.

For example:

  addr.sin_family = AF_INET;
  addr.sin_port = htons(1965);
Could become:

  addr.sin_family = AF_INET, addr.sin_port = htons(1965);

Re: Show HN: Gemini web client in 100 lines of C

#12
post #7
post #5

Earlier quoted context omitted.

Web refers to Gemini here, it being a command-line client for the Gemini web. These line-based browsers used to be more common, there were a few ones for the www but also ‘ftp’ has such a mode. As does my little ‘nostt’ Teletext reader.

> Web refers to Gopher here, it being a command-line client for the Gopher web. Gemini, not Gopher.

Oops, edited! Thanks.

Re: Show HN: Gemini web client in 100 lines of C

#13

https://github.com/ir33k/gmi100/blob/master/gmi100.c#L27 definitely threw me for a loop until I realized it was a line saving trick. It would be more readable to save lines elsewhere by exploiting the comma operator instead of essentially cramming irrelevant statements into a conditional. For example: addr.sin_family = AF_INET; addr.sin_port = htons(1965); Could become: addr.sin_family = AF_INET, addr.sin_port = hton…

Ah yes, there are couple of line saving tricks like that. Mostly in for loops.

Thanks for suggestion. I will go through code again to see if I can save more space with normal code.

Actually that was my workflow. Each time I managed to write something in simpler way I reverted few tricks.

Re: Show HN: Gemini web client in 100 lines of C

#14
post #2

What do you mean by web client? From the github it looks more like a command line program.

If you're going to nitpick you could nitpick on the use of "web" (though, as others note, that's not wholly inaccurate), but there are plenty of command-line web clients. For example, wget and curl.

Yes, wget and curl are web clients. This is not.

Re: Show HN: Gemini web client in 100 lines of C

#15
post #5
post #2

What do you mean by web client? From the github it looks more like a command line program.

Web refers to Gemini here, it being a command-line client for the Gemini web. These line-based browsers used to be more common, there were a few ones for the www but also ‘ftp’ has such a mode. As does my little ‘nostt’ Teletext reader.

I've only ever heard it called "Gemini", not "Gemini web".

"Gemini web" is a bad name because Gemini's not being part of the web was the main motive in Gemini's creation.

"Geminisphere" or "Geminiverse" would be fine with me as a name for the totality of Gemini servers considered collectively.

Re: Show HN: Gemini web client in 100 lines of C

#16
post #6
post #4

Earlier quoted context omitted.

Yea, you are right. Poor choose of words on my side. One can argue the definition of "web" but it would be much more precise to write "CLI client".

There’s nothing to argue. The "World Wide Web" or "Web" is defined as servers and clients communicating using the HTTP protocol. (Usually, it means that content is using HTML but this is not mandatory). "Gemini" is defined as servers and client communicating using the "Gemini" protocol (and content is usually in the gemtext format). Both are part of the Internet, which is defined as an INTERconnection of NETworks, th…

> A "Web Gemini client" means a browser capable of accessing both Gemini and the Web

It could also be a Gemini client running on the web, which is what I initially thought it would be from reading the title.

Re: Show HN: Gemini web client in 100 lines of C

#17
post #6

Earlier quoted context omitted.

There’s nothing to argue. The "World Wide Web" or "Web" is defined as servers and clients communicating using the HTTP protocol. (Usually, it means that content is using HTML but this is not mandatory). "Gemini" is defined as servers and client communicating using the "Gemini" protocol (and content is usually in the gemtext format). Both are part of the Internet, which is defined as an INTERconnection of NETworks, th…

> A "Web Gemini client" means a browser capable of accessing both Gemini and the Web It could also be a Gemini client running on the web, which is what I initially thought it would be from reading the title.

Yes, sry for confusion. I don't see any way to correct my mistake as edit button for title and description is no longer available to me. At least I don't have this mistake on GitHub.

Re: Show HN: Gemini web client in 100 lines of C

#18
It's a nice project, but - I guess as is tradition with the majority of C projects - it has resource leaks and buffer overflows. There is at least one resource leak, namely, `sfd` is not closed when certain `WARN()` invocations jump back to the `start` label; for example, when `gethostbyname()` fails (i.e. try a non-existent domain and observe that the sockets remain open with `lsof`). (It also seems to be leaked in the happy path, so presumably `SSL_set_fd()` does not take ownership.) And if the user simply presses enter, i.e. the input is an empty line, there is a buffer underflow in line 55 as `j` will be -1 initially.

Also

    addr.sin_addr.s_addr = *((unsigned long*)he->h_addr_list[i]);
is a potential buffer overflow where `long` is 64 bits since only the first four bytes of `h_addr_list[i]` can be accessed, and also potentially misaligned for `unsigned long`; and it will also not work correctly on big endian platforms where `long` is 64 bits. Using `memcpy()` would have avoided all these problems. I am really confused as to how you arrived at the conclusion that "yes, this is the way to copy 4 bytes from A to B".

This sounds rude, I know, and I apologize; I don't want to single you/this project out personally. I am just frustrated that even today there are people who work on C/C++ projects seemingly without having made GCC's -fanalyzer/asan/ubsan/valgrind/etc. an important part of their development workflow.

Post reply on HN