Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

netcat.c is by far one of the most entertaining code reads out there. Because of the unix networking / portability rants -- which are sometimes informative -- and also because the Hobbit was such a strange, scatalogical creature...

    grep -in poop netcat.c

    110:struct host_poop {
    115:#define HINF struct host_poop
    117:struct port_poop {
    122:#define PINF struct port_poop
    163:HINF ** gates = NULL;		/* LSRR hop hostpoop */
    169:PINF * portpoop = NULL;		/* for getportpoop / getservby* */
    336:   cross-check the host_poop we have so far against new gethostby*() info,
    340:int comparehosts (poop, hp)
    341:  HINF * poop;
    349:  if (strcmp (poop->name, hp->h_name) != 0) {		/* case-sensitive */
    351:  if (strcasecmp (poop->name, hp->h_name) != 0) {	/* normal */
    353:    holler ("DNS fwd/rev mismatch: %s != %s", poop->name, hp->h_name);
    360:/* gethostpoop :
    361:   resolve a host 8 ways from sunday; return a new host_poop struct with its
    365:HINF * gethostpoop (name, numeric)
    371:  register HINF * poop = NULL;
    397:    poop = (HINF *) Hmalloc (sizeof (HINF));
    398:  if (! poop)
    399:    bail ("gethostpoop fuxored");
    400:  strcpy (poop->name, unknown);		/* preload it */
    411:    strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 2);
    413:      memcpy (&poop->iaddrs[x], hostent->h_addr_list[x], sizeof (IA));
    414:      strncpy (poop->addrs[x], inet_ntoa (poop->iaddrs[x]),
    415:	sizeof (poop->addrs[0]));
    418:      return (poop);			/* inverse stuff, we're done. */
    421:    for (x = 0; poop->iaddrs[x].s_addr && (x < 8); x++) {
    422:      hostent = gethostbyaddr ((char *)&poop->iaddrs[x],
    426:	  poop->addrs[x]);
    428:	(void) comparehosts (poop, hostent);
    432:    memcpy (poop->iaddrs, &iaddr, sizeof (IA));
    433:    strncpy (poop->addrs[0], inet_ntoa (iaddr), sizeof (poop->addrs));
    435:      return (poop);
    437:      return (poop);			/* the full DNS hair */
    443:	strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 2);
    444:	hostent = gethostbyname (poop->name);
    447:		poop->name);
    449:	  (void) comparehosts (poop, hostent);
    453:/* whatever-all went down previously, we should now have a host_poop struct
    456:  return (poop);
    457:} /* gethostpoop */
    459:/* getportpoop :
    460:   Same general idea as gethostpoop -- look up a port in /etc/services, fill
    461:   in global port_poop, but return the actual port *number*.  Pass ONE of:
    466:USHORT getportpoop (pstring, pnum)
    476:  portpoop->name[0] = '?';		/* fast preload */
    477:  portpoop->name[1] = '\0';
    495:      strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name));
    509:      return (getportpoop (NULL, x));	/* recurse for numeric-string-arg */
    514:      strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name));
    536:  sprintf (portpoop->anum, "%d", x);	/* always load any numeric specs! */
    537:  portpoop->num = (x & 0xffff);		/* ushort, remember... */
    538:  return (portpoop->num);
    539:} /* getportpoop */
    994:   gethostpoop wants a string and there's much gnarlier code out there already,
    1002:  whozis = gethostpoop (bigbuf_net, o_nflag);
    1451:  portpoop = (PINF *) Hmalloc (sizeof (PINF));
    1545:	gp = gethostpoop (optarg, o_nflag);
    1572:	o_lport = getportpoop (optarg, 0);
    1584:	wherefrom = gethostpoop (optarg, o_nflag);
    1654:    whereto = gethostpoop (argv[optind], o_nflag);
    1669:      curport = getportpoop (argv[optind], 0);
    1713:        hiport = getportpoop (cp, 0);
    1719:    loport = getportpoop (argv[optind], 0);
    1740:      curport = getportpoop (NULL, curport);
    1749:	  whereto->name, whereto->addrs[0], curport, portpoop->name);
    1768:	    whereto->name, whereto->addrs[0], curport, portpoop->name);


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

Search: