确认UDP状态信息


通过pid_ioctl函数的get命令可确认UDP的各种状态。

$return = pid_ioctl($pid, "get ITEM");

可确认UDP状态信息

ITEM 说明 返还值 返还类型
srcaddr source IP address e.g. 192.168.0.1 string
srcport source port number e.g. 1470 integer
dstaddr destination IP address e.g. 192.168.0.2 string
dstport destination port number e.g. 1470 integer
rxlen received data size[Byte] e.g. 200 integer

确认接收数据大小

UDP接收数据大小根据pid_ioctl函数的"get rxlen"来确认。

$rxlen = pid_ioctl($pid, "get rxlen");

此例显示PHPoC设备反复确认UDP接收数据,当确认有接收数据时向控制台输出并终止脚本。

$rbuf = "";
$pid = pid_open("/mmap/udp0");              // open UDP 0
pid_bind($pid, "", 1470);                   // binding
do
{
    $rxlen = pid_ioctl($pid, "get rxlen");  // get received data size
    if($rxlen)
    {
        pid_recvfrom($pid, $rbuf, $rxlen);  // receive data
        echo "$rxlen bytes\r\n";            // print size of received data
    }
    usleep(100000);
}while($rxlen == 0);                        // while receiving no data
pid_close($pid);