PHP 8.5.0 Beta 1 available for testing

Voting

: one minus one?
(Example: nine)

The Note You're Voting On

recycling dot sp dot am at gmail dot com
14 years ago
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

<< Back to user notes page

To Top