描述
這個函數應該在第一次調用 getprotoent 之前調用。 STAYOPEN 參數是可選的,在大多數係統上都未使用。當 getprotoent() 檢索協議數據庫中下一行的信息時,setprotoent 將枚舉設置(或重置)到主機條目集的開頭。
用法
以下是此函數的簡單語法 -
setprotoent STAYOPEN
返回值
此函數不返回任何值。
示例
以下是顯示其基本用法的示例代碼 -
#!/usr/bin/perl
while(($name, $aliases, $protocol_number) = getprotoent()) {
print "Name = $name\n";
print "Aliases = $aliases\n";
print "Protocol Number = $protocol_number\n";
}
setprotoent(1); # Rewind the database.
while(($name, $aliases, $protocol_number) = getprotoent()) {
print "Name = $name\n";
print "Aliases = $aliases\n";
print "Protocol Number = $protocol_number\n";
}
endprotoent(); # Closes the database
執行上述代碼時,會產生以下結果 -
Name = ip Aliases = IP Protocol Number = 0 Name = hopopt Aliases = HOPOPT Protocol Number = 0 Name = icmp Aliases = ICMP Protocol Number = 1 Name = igmp Aliases = IGMP Protocol Number = 2 Name = ggp Aliases = GGP Protocol Number = 3 Name = ipencap Aliases = IP-ENCAP Protocol Number = 4 Name = st Aliases = ST Protocol Number = 5 . . . Name = rsvp-e2e-ignore Aliases = RSVP-E2E-IGNORE Protocol Number = 134 Name = udplite Aliases = UDPLite Protocol Number = 136 Name = mpls-in-ip Aliases = MPLS-in-IP Protocol Number = 137 Name = manet Aliases = manet Protocol Number = 138 Name = hip Aliases = HIP Protocol Number = 139 Name = shim6 Aliases = Shim6 Protocol Number = 140
相關用法
- Perl setpriority用法及代碼示例
- Perl setpwent用法及代碼示例
- Perl sethostent用法及代碼示例
- Perl setgrent用法及代碼示例
- Perl setsockopt用法及代碼示例
- Perl setnetent用法及代碼示例
- Perl setservent用法及代碼示例
- Perl semget用法及代碼示例
- Perl send用法及代碼示例
- Perl seekdir用法及代碼示例
- Perl semctl用法及代碼示例
- Perl semop用法及代碼示例
- Perl select用法及代碼示例
- Perl sin()用法及代碼示例
- Perl split用法及代碼示例
- Perl shmctl用法及代碼示例
- Perl splice用法及代碼示例
注:本文由純淨天空篩選整理自 Perl setprotoent Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。