Allow binding to an specific IP

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-04 22:37:56 +01:00
parent 6839001dc3
commit ac6c3c7e69
4 changed files with 11 additions and 9 deletions

View file

@ -30,7 +30,7 @@ the Free Software Foundation, either version 3 of the License, or
class UDPSocket{
private $encrypt;
var $buffer, $connected, $errors, $sock, $server;
function __construct($server, $port, $listen = false){
function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){
$this->errors = array_fill(88,(125 - 88) + 1, true);
$this->server = $server;
$this->port = $port;
@ -41,10 +41,10 @@ class UDPSocket{
$this->buffer = array();
$this->unblock();
}else{
if(socket_bind($this->sock, "0.0.0.0", $port) === true){
if(socket_bind($this->sock, $serverip, $port) === true){
$this->unblock();
}else{
console("[ERROR] Couldn't bind to 0.0.0.0:".$port, true, true, 0);
console("[ERROR] Couldn't bind to $serverip:".$port, true, true, 0);
die();
}
}