Perl setprotoent 函数

  • 描述

    setprotoent 应在首次调用getprotoent之前调用。STAYOPEN参数是可选的,在大多数系统上未使用。当getprotoent()检索协议数据库中下一行的信息时,setprotoent会将枚举设置(或重置)为主机条目集的开头。
  • 句法

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

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

    以下是显示其基本用法的示例代码-
     
    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 = tcp
    Aliases = TCP
    Protocol Number = 6
    Name = egp
    Aliases = EGP
    Protocol Number = 8
    Name = igp
    Aliases = IGP
    Protocol Number = 9
    Name = pup
    Aliases = PUP
    Protocol Number = 12
    Name = udp
    Aliases = UDP
    Protocol Number = 17
    Name = hmp
    Aliases = HMP
    Protocol Number = 20
    Name = xns-idp
    Aliases = XNS-IDP
    Protocol Number = 22
    Name = rdp
    Aliases = RDP
    Protocol Number = 27
    Name = iso-tp4
    Aliases = ISO-TP4
    Protocol Number = 29
    Name = dccp
    Aliases = DCCP
    Protocol Number = 33
    Name = xtp
    Aliases = XTP
    Protocol Number = 36
    Name = ddp
    Aliases = DDP
    Protocol Number = 37
    Name = idpr-cmtp
    Aliases = IDPR-CMTP
    Protocol Number = 38
    Name = ipv6
    Aliases = IPv6
    Protocol Number = 41
    Name = ipv6-route
    Aliases = IPv6-Route
    Protocol Number = 43
    Name = ipv6-frag
    Aliases = IPv6-Frag