Perl setnetent 函数



说明

在首次调用 getnetent 之前应调用此函数。STAYOPEN 参数是可选的,在大多数系统上均未用到。由于 getnetent() 会检索网络数据库中下一行的信息,因此 setnetent 会将枚举 (或重置) 设置为主机条目集合的开头。

语法

以下是此函数的简单语法 -

setnetent STAYOPEN

返回值

此函数不返回值。

示例

以下是显示其基本用法的示例代码 -

#!/usr/bin/perl

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
perl_function_references.htm
广告