PHP Doku:: Ermittelt den Protokollnamen anhand der Protokollnummer - function.getprotobynumber.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige DiensteNetworkNetzwerk-Funktionengetprotobynumber

Ein Service von Reinhard Neidl - Webprogrammierung.

Netzwerk-Funktionen

<<getprotobyname

getservbyname>>

getprotobynumber

(PHP 4, PHP 5)

getprotobynumberErmittelt den Protokollnamen anhand der Protokollnummer

Beschreibung

string getprotobynumber ( int $number )

Die Funktion getprotobynumber() gibt den Protokollnamen passend zur angegebenen Protokollnummer (number) zurück. Der Wert wird anhand der Datei /etc/protocols ermittelt.

Parameter-Liste

number

Die Protokollnummer.

Rückgabewerte

Gibt den Protokollnamen als String zurück.

Siehe auch


2 BenutzerBeiträge:
- Beiträge aktualisieren...
recycling dot sp dot am at gmail dot com
13.09.2010 12:40
Note that by the time of writing this note (5.3.3), there seems to be only two defined constants for the protocol numbers: SOL_UDP and SOL_TCP.
For all other protocols (like ICMP,... ) you'll have to provide the exact number (EG: 1 for ICMP, ... )
<?php
   
echo getprotobynumber(SOL_TCP) . "\n"; // prints tcp
   
echo getprotobynumber(SOL_UDP) . "\n"; // prints udp
   
var_dump(getprotobyname('tcp') == SOL_TCP); // bool(true)
   
var_dump(getprotobyname('udp') == SOL_UDP); // bool(true)
?>
On a UNIX system (don't know if this is true for Windows), the php functions getprotobyname and getprotobynumber are just wrapper for their corresponding system calls. These functions returns the protocol name or protocol number based on the definition from IANA. If you are looking for a protocol and you don't know its number, you can find the exact protocol number here: http://www.iana.org/assignments/protocol-numbers
Vipindas K.S
8.05.2008 17:39
getprotobynumber()
=====================
getprotobynumber() gets the protocol name for the given protocol number on the local system. If the protocol number is not recognized,the function returns FALSE.The given code snippet gives the list of protocols along with their protocol numbers

<?
$format
= "%6s %s\n<br />";
for (
$number = 0; $number < 255; $number++)
 {
   if (
getprotobynumber ($number))

     
printf ($format, " $number-->", getprotobynumber ($number));
 }

?>

OUTPUT:

0--> ip
1--> icmp
3--> ggp
6--> tcp
8--> egp
12--> pup
17--> udp
20--> hmp
22--> xns-idp
27--> rdp
66--> rvd



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)