Perl setnetent 函数

  • 描述

    setnetent 应该在第一次调用gethostent之前调用此函数。STAYOPEN参数是可选的,在大多数系统上未使用。当getnetent()从网络数据库的下一行检索信息时,setnetent会将枚举设置(或重置)为主机条目集的开头。
  • 句法

    以下是此函数的简单语法-
    
    setnetent STAYOPEN
    
  • 返回值

    此函数不返回任何值。
  • 示例

    以下是显示其基本用法的示例代码-
     
    use Socket;
    
    while ( ($name, $aliases, $addrtype, $net)  = getnetent() ) {
    
       print "Name = $name\n";
       print "Aliases = $aliases\n";
       print "Addrtype = $addrtype\n";
       print "Net = $net\n";
    }
    
    setnetent(1); # Rewind the database;
    
    while ( ($name, $aliases, $addrtype, $net)  = getnetent() ) {
    
       print "Name = $name\n";
       print "Aliases = $aliases\n";
       print "Addrtype = $addrtype\n";
       print "Net = $net\n";
    }
    
    endnetent();  # Closes the database;
    
    尝试一下
    执行以上代码后,将产生以下结果--
    
    Name = default
    Aliases = 
    Addrtype = 2
    Net = 0
    Name = loopback
    Aliases = 
    Addrtype = 2
    Net = 2130706432
    Name = link-local
    Aliases = 
    Addrtype = 2
    Net = 2851995648
    Name = default
    Aliases = 
    Addrtype = 2
    Net = 0
    Name = loopback
    Aliases = 
    Addrtype = 2
    Net = 2130706432
    Name = link-local
    Aliases = 
    Addrtype = 2
    Net = 2851995648