Tcpdump源码分析系列4:main函数继续研究

革命尚未成功,同志仍需努力!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


switch (tflag)
 {

 case 0: /* Default */
 case 4: /* Default + Date*/
  thiszone = gmt2local(0);
  break;

 case 1: /* No time stamp */
 case 2: /* Unix timeval style */
 case 3: /* Microseconds since previous packet */
        case 5: /* Microseconds since first packet */
  break;

 default: /* Not supported */
  error("only -t, -tt, -ttt, -tttt and -ttttt are supported");
  break;
 }
 //根据t的个数来设置tflag,然后决定是否需要设置thiszone值

~~~~~~~~~~~~

if (fflag != 0 && (VFileName != NULL || RFileName != NULL))
   error("-f can not be used with -V or -r"); 
  
 
  if (VFileName != NULL && RFileName != NULL)
   error("-V and -r are mutually exclusive.");
 //添加参数之间的有效性验证

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#ifdef WITH_CHROOT
 /* if run as root, prepare for chrooting */
 if (getuid() == 0 || geteuid() == 0)
 {
  /* future extensibility for cmd-line arguments */
  if (!chroot_dir)
   chroot_dir = WITH_CHROOT;
 }
 #endif
 //chroot_dir设置为WITH_CHROOT
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

#ifdef WITH_USER
 /* if run as root, prepare for dropping root privileges */
 if (getuid() == 0 || geteuid() == 0) {
  /* Run with '-Z root' to restore old behaviour */
  if (!username)
   username = WITH_USER;
 }
 #endif
 //设置username --->WITH_USER
 //自定义检查点: 1 2 3

 

~~~~~~~~~~~~~~~~~~~~~~```

if (RFileName != NULL || VFileName != NULL)
 {
  //如果RFileName|VFileName至少存在一个
  //这里我们假设是进行live capture
  //则以下代码不执行
  
  /*
   * If RFileName is non-null, it's the pathname of a
   * savefile to read.  If VFileName is non-null, it's
   * the pathname of a file containing a list of pathnames
   * (one per line) of savefiles to read.
   *
   * In either case, we're reading a savefile, not doing
   * a live capture.
   */
#ifndef WIN32
  /*
   * We don't need network access, so relinquish any set-UID
   * or set-GID privileges we have (if any).
   *
   * We do *not* want set-UID privileges when opening a
   * trace file, as that might let the user read other
   * people's trace files (especially if we're set-UID
   * root).
   */
  if (setgid(getgid()) != 0 || setuid(getuid()) != 0 )
   fprintf(stderr, "Warning: setgid/setuid failed !\n");
#endif /* WIN32 */
  if (VFileName != NULL) {
   if (VFileName[0] == '-' && VFileName[1] == '\0')
    VFile = stdin;
   else
    VFile = fopen(VFileName, "r");

   if (VFile == NULL)
    error("Unable to open file: %s\n", strerror(errno));

   ret = get_next_file(VFile, VFileLine);
   if (!ret)
    error("Nothing in %s\n", VFileName);
   RFileName = VFileLine;
  }

  pd = pcap_open_offline(RFileName, ebuf);
  if (pd == NULL)
   error("%s", ebuf);
  dlt = pcap_datalink(pd);
  dlt_name = pcap_datalink_val_to_name(dlt);
  if (dlt_name == NULL) {
   fprintf(stderr, "reading from file %s, link-type %u\n",
       RFileName, dlt);
  } else {
   fprintf(stderr,
       "reading from file %s, link-type %s (%s)\n",
       RFileName, dlt_name,
       pcap_datalink_val_to_description(dlt));
  }
  localnet = 0;
  netmask = 0;
 }

 

转载于:https://my.oschina.net/qiangzigege/blog/171368

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值