netcat源代码分析,dolisten()函数中的whoisit

Datetime:2016-08-23 03:47:43          Topic: Source Code Analysis           Share
G:\nc\nc114-debug>nc -lp 66
in res_init
after recycle
after go: x now , optarg 0 optind 3
curport = (null)
in dolisten lp = 66
in doconnect
in doconnect ,listen socket nnetfd = 1864.
in dolisten nnetfd = 1864
in arm num = 2 stdhnd = 7
handle is 7
before rr = accept
rr = accept = 1852
in arm num = 0 stdhnd = 7
handle is 7
in doconnect ,closesocket nnetfd = 1864.
remend->sin_port = 49177
bigbuf_net = 192.168.1.3

in dolisten , socket nnetfd = 1852 .

  z = ntohs (remend->sin_port);
  fprintf(stderr,"remend->sin_port = %d \n",z);
  strcpy (bigbuf_net, inet_ntoa (remend->sin_addr));
  fprintf(stderr,"bigbuf_net = %s \n",bigbuf_net);
  whozis = gethostpoop (bigbuf_net, o_nflag);
  errno = 0;
  x = 0;                /* use as a flag... */
  if (rad)
    if (memcmp (rad, whozis->iaddrs, sizeof (SA)))
      x = 1;
  if (rp)
    if (z != rp)
      x = 1;
  if (x)                    /* guilty! */
    bail ("invalid connection to [%s] from %s [%s] %d",
    cp, whozis->name, whozis->addrs[0], z);
      holler ("connect to [%s] from %s [%s] %d",        /* oh, you're okay.. */
    cp, whozis->name, whozis->addrs[0], z);

    fprintf(stderr,"in dolisten , socket nnetfd = %d.\n",nnetfd);
  return (nnetfd);                /* open! */





About List