现在的位置: 首页 > 综合 > 正文

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

2013年01月09日 ⁄ 综合 ⁄ 共 1584字 ⁄ 字号 评论关闭

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 dolisten ,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! */

调试二(无变化,既rad和rp都是null)

if (rad)
    if (memcmp (rad, whozis->iaddrs, sizeof (SA)))
      x = 1;
  if (rp)
    if (z != rp)
      x = 1;

改为:

  if (rad){
    if (memcmp (rad, whozis->iaddrs, sizeof (SA)))
      x = 1;
fprintf(stderr,"in dolisten rad not null \n");
}
  if (rp){
    if (z != rp)
      x = 1;
fprintf(stderr,"in dolisten rp not null \n");
}

实验三:nc -vlp 66                         [192.168.1.4]

nc     192.168.1.4  66                                 [192.168.1.3]

remend->sin_port = 49336
bigbuf_net = 192.168.1.3
connect to [192.168.1.4] from TYGHBN [192.168.1.3] 49336
in dolisten , socket nnetfd = 1852.

可见,加上-v选项,whoisit会显示出双方连接的情况。

本地地址,from后是对方的主机名,ip地址,及端口号。

抱歉!评论已关闭.