

Netcat.c - metamusic
http://www.opensource.apple.com/source/netcat/netcat-4/netcat/netcat.c
Some highlights:<p>1. Take a look at &#x27;gethostpoop&#x27;
2. Take a look at &#x27;getportpoop&#x27;
3. Make sure to read the netdb.h rant in the function above.
4. #ifdef GAPING_SECURITY_HOLE<p>Nearly half the comments in the file are taking the piss out of BSD sockets. Enjoy!
======
astrodust
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.

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

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

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

~~~
codezero
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](https://news.ycombinator.com/newsguidelines.html)

------
FullyFunctional
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](http://cr.yp.to/tcpip/twofd.html)

------
mct
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](http://sysunconfig.net/unixtips/netcat_readme.html)

------
foxhill
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.

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

------
blubbi2
Favorite comment from the source code:

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

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

------
yxhuvud
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.

~~~
angersock
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.

~~~
linuxlizard
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.

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

------
nathancahill

      #ifdef GAPING_SECURITY_HOLE

~~~
fish2000

        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)

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

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

