Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Socket error: Operation not permitted

Status
Not open for further replies.

iranor

Programmer
Jun 17, 2004
174
CA
I try to run an irc-php interface script, but it can't connect to the irc server. This is what the script debug me:

[DEBUG] Debugging enabled
[DEBUG] Connecting now...
[DEBUG] Socket creation was successful, but an error has occured now: Operation not permitted
[DEBUG] Too many levels of symbolic links
[DEBUG] Reached end of socket!

The 4th error always change between 4 things, but what is the possible cause of the Operation not permitted thing?
 
What do you use to open the socket?
How do you arrive at these error messages?
 
Code:
function Connect ($server="", $port=-1, $nick="", $user="", $rname="", $pass="")
    {
        if($server!="") $this->_server=$server;
        if($port  !="") $this->_port=$port;
        if($nick  !="") $this->_nick=$nick;
        if($user  !="") $this->_user=strtolower($user);
        if($rname !="") $this->_rname=$rname;
        $this->_svrpass=$pass;

        if($this->_server == "") return $this->doerr("No server was specified!");
        if($this->_port == -1) return $this->doerr("No port was specified!");
        if($this->_nick=="") return $this->doerr("No nick was specified!");
        if($this->_user=="") return $this->doerr("No user was specified!");
        if($this->_rname=="") return $this->doerr("No realname was specified!");

        if(!preg_match("/^[-a-zA-Z.0-9]{5,}$/",$this->_server)) return $this->doerr("Server is malformed!");
        if(!is_numeric($this->_port) || $this->_port!=(int)$this->_port || $this->_port<1024 || $this->_port>65535) return $this->doerr("Specified port is out of range!");
        if(!preg_match("/^[-_a-zA-Z0-9\[\]\|\\]]{1,30}$/",$this->_nick)) return $this->doerr("Nick is invalid!");
        if(!preg_match("/^[_a-z]+$/",$this->_user)) return $this->doerr("User is invalid!");
        if($this->_rname=="") $this->_rname="Web Integration Bot";
        $this->dodebug("Connecting now...");

        if(!($tsk=socket_create(AF_INET,SOCK_STREAM,SOL_TCP))) return $this->doerr("Socket error (".socket_strerror(socket_last_error()).")");
        if(!(socket_bind($tsk,"0.0.0.0",0))) return $this->doerr("Bind error (".socket_strerror(socket_last_error()).")");
        if(!(socket_connect($tsk,$this->_server,$this->_port))) return $this->doerr("Connect error (".socket_strerror(socket_last_error()).")");
        $this->_sock=$tsk;   unset($tsk);
        if($e=socket_last_error($this->_sock) > 0)
        {
            return $this->doerr("Socket creation was successful, but an error has occured now: ".socket_strerror($e));
        }

        //socket_set_nonblock($this->_sock);
        if($this->_svrpass != "")
            $this->send_raw("PASS ".$this->_svrpass);
        $this->send_raw("NICK ".$this->_nick);
        $this->send_raw(sprintf("USER %s %s %s :%s",$this->_user,"gordo.ehpg.net",$this->_server,$this->_rname));
        sleep(1);
        return 1;
    }
 
Cleaned, the important parts are:

Code:
function Connect ($server="", $port=-1, $nick="", $user="", $rname="")
    {
        $this->dodebug("Connecting now...");

        $tsk = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
        socket_bind($tsk, "0.0.0.0", 0);
        socket_connect($tsk, $this->_server, $this->_port);
        $this->_sock=$tsk;
        unset($tsk);
        if($e = socket_last_error($this->_sock) > 0)
        {
            return $this->doerr("Socket creation was successful, but an error has occured now: ".socket_strerror($e));
        }
    }


This is the config file which give the server informations:

Code:
<?
include 'irc.php';
$irc = new IRC(1);
$server = 'irc.gamesurge.net';
$port = '6667';
$nick = 'Botname';
$ident = 'Botname';
$rname = 'Botname';

$irc->connect($server, $port, $nick, $ident, $rname);
$irc->message_loop();
?>
[/code>
 
I don't know if it does matter about the file size, or something... But the above code shows me 90% of the time the error message Operation not permitted.

If i change one line of the script /comment some line, it works fine, but i'm quite limited in the amount of code allowed :(
 
I'm seeing some weirdness with your code.

Your function accepts a server and port, which your code snippet is passing to it, but it does not actually use the parameters you're passing the function.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top