Hacker News new | past | comments | ask | show | jobs | submit login
Netcat.c (opensource.apple.com)
83 points by metamusic on July 21, 2015 | hide | past | favorite | 22 comments



This implementation isn't Apple specific. Search for some of the comments from this code and you'll see it show up all over.

It's also from 1995.


Yep. This "incredibly funny" implementation of netcat is... just like the original netcat.


Ah... but now the title has changed. It was along the lines of "Incredibly funny implementation of netcat in open source Apple code"


I posted it, but didn't edit the title. I'm assuming a moderator did that, but the reason for it escapes me.


In general (though not 100% of the time) titles should be the same on HN as they are on the page you're submitting. The goal is to reduce editorializing, and link baiting: https://news.ycombinator.com/newsguidelines.html


The "funniness" is probably subjective. This type of code rant aren't exactly rare. However, these particular complaints about BSD sockets are common and IMO fully deserved. That design isn't exactly brilliant. Another insightful critique (by DJB): http://cr.yp.to/tcpip/twofd.html


The README that Hobbit (author of the original netcat) wrote is a really good read. I learned a lot when I first read it years and years ago. I especially remember it describing how it is possible to get "in front" of another daemon. If the daemon has bound a listening socket to 0.0.0.0, as most do, you can bind to a more specific address on the same port and intercept inbound connections. Fun!

http://sysunconfig.net/unixtips/netcat_readme.html


what? am i going mad? people like this code?!

comments are no replacement for readable and concise code, i tried to read this from start to finish - but i don't know where one block ends and the next begins.

what the fuck does the variable "pr00gie" contain? yea the comments are half a laugh (as far as 90s "micro$haft" humour goes), but the code that it shamelessly decorates is fucking horrific.

        /* The DNS spec is officially case-insensitive, but for those times when you
           *really* wanna see any and all discrepancies, by all means define this. */
        #ifdef ANAL     
          if (strcmp (poop->name, hp->h_name) != 0) {   /* case-sensitive */
        #else
          if (strcasecmp (poop->name, hp->h_name) != 0) { /* normal */
        #endif
so, not only is this by definition entirely superfluous, but the identifiers used are fucking meaningless. if all you see is "cc -DANAL" what the fuck does that mean? ok, so obviously means picky, but in what regard? how the fuck do you know it's got anything to do with ___domain names?

why not something like;

        //DNS standard is case insensitive, but you can enable case sensitivity
        #if defined(DNS_CASE_SENSITIVE)     
          if (strcmp(poop->name, hp->h_name) != 0) {
        #else
          if (strcasecmp(poop->name, hp->h_name) != 0) {
        #endif
or even better (and get rid of #ifdefs in function code), have this up at the top with the rest of the programmer humour?

        //DNS standard is case insensitive, but you can enable case sensitivity 
        #if defined(DNS_CASE_SENSITIVE)     
          #define dnsstrcmp strcmp
        #else
          #define dnsstrcmp strcasecmp
        #endif
no wonder computers fucking suck, we're not standing on the shoulders of giants, rather the top of an everest-sized mountain of technical debt and hacks. this should not be celebrated.


s/fuck/goodness/g # for goodness' sake, this is HN, not /.


Favorite comment from the source code:

/* If your shitbox doesn't have getopt, step into the nineties already. */


I especially liked: /* None genuine without this seal! _H*/


I usually doesn't tend to like that kind of long winding functions, but with the excellent commenting, I really like that piece of code.


In production code, I actually try not to be obscene lest somebody else come across it.

However, the pervasive wtf undercurrent here in the comments actually makes it colorful yet oddly not too distracting. I like it.


I had an f-bomb in shipping source for over a year before I noticed it. (Was a chunk of code that had been object file only then we switch to shipping source.)

Somehow it even got through the lawyers' Bad Words filter.


I like the idea of a bad-words filter as a post-commit hook or something!


i only add obscene comments on my personal stuff -- but whenever i'm trying to debug a hard problem, i will add a logger.debug("is this f*ing code reachable?").

i just have to make really really sure i don't commit these kind of changes.


  #ifdef GAPING_SECURITY_HOLE


    holler ("Preposterous fd value %d", fd);
(I just had to debug a descriptor mess and this style of freewheeling 90’s-style documentation rejuvenated me w/r/t all of that, hah)


In fact, Windows builds with -DGAPING_SECURITY_HOLE is pretty much the reason why Windows virus scanners detect nc.exe. (The #define enables the -e flag, which starts processes with stdio redirected over the network when the connection succeeds.)


My favorite function names: gethostpoop and getportpoop, hailing from the get*poop family.


Luckily we all switched to nmap's `ncat` utility. At least, I hope all of us did.


#ifdef ANAL if (strcmp (poop->name, hp->h_name) != 0)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: