netcat源代码分析,gethostpoop()函数

  errno = 0;
  if (name)
    poop = (HINF *) Hmalloc (sizeof (HINF));
  if (! poop)
    bail ("gethostpoop fuxored");
  strcpy (poop->name, unknown);        /* preload it */
/* see wzv:workarounds.c for dg/ux return-a-struct inet_addr lossage */
  iaddr.s_addr = inet_addr (name);

  if (iaddr.s_addr == INADDR_NONE) {    /* here's the great split: names... */
    if (numeric)
      bail ("Can't parse %s as an IP address", name);

fprintf(stderr,"name = %s \n",name);
    hostent = gethostbyname (name);
    if (! hostent)
/* failure to look up a name is fatal, since we can't do anything with it */
/* XXX: h_errno only if BIND?  look up how telnet deals with this */
      bail ("%s: forward host lookup failed: h_errno %d", name, h_errno);
    strncpy (poop->name, hostent->h_name, sizeof (poop->name));
    for (x = 0; hostent->h_addr_list[x] && (x < 8); x++) {
      memcpy (&poop->iaddrs[x], hostent->h_addr_list[x], sizeof (IA));
      strncpy (poop->addrs[x], inet_ntoa (poop->iaddrs[x]),
    sizeof (poop->addrs[0]));
    } /* for x -> addrs, part A */
    if (! o_verbose)            /* if we didn't want to see the */
      return (poop);            /* inverse stuff, we're done. */
/* do inverse lookups in separate loop based on our collected forward addrs,
   since gethostby* tends to crap into the same buffer over and over */
    for (x = 0; poop->iaddrs[x].s_addr && (x < 8); x++) {
      hostent = gethostbyaddr ((char *)&poop->iaddrs[x],
                sizeof (IA), AF_INET);
      if ((! hostent) || (! hostent-> h_name))
    holler ("Warning: inverse host lookup failed for %s: h_errno %d",
      poop->addrs[x], h_errno);
      else
    (void) comparehosts (poop, hostent);
    } /* for x -> addrs, part B */

  } else {            /* not INADDR_NONE: numeric addresses... */


else之前的是gethostpoop()函数的第一个参数是域名的形式,

而else语句中是处理的ip地址的形式。




G:\nc\nc114-debug>nc example.org 55
in res_init
after recycle
after go: x now , optarg 0 optind 1
name = example.org
Single 1, curport 55
in doconnect
in doconnect ,listen socket nnetfd = 1864.
in arm num = 1 stdhnd = 7
handle is 7
in doconnect setjmp


你可能感兴趣的:(netcat源代码分析,gethostpoop()函数)