Subversion Repositories oidinfo_api

Rev

Rev 15 | Rev 21 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15 Rev 16
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OID-Info.com API for PHP
4
 * OID-Info.com API for PHP
5
 * Copyright 2019-2020 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019-2021 Daniel Marschall, ViaThinkSoft
6
 * Version 2020-09-12
6
 * Version 2021-05-21
7
 *
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
10
 * You may obtain a copy of the License at
11
 *
11
 *
Line 993... Line 993...
993
        const DEFAULT_PORT = 49500;
993
        const DEFAULT_PORT = 49500;
994
 
994
 
995
        protected function spp_reader_init() {
995
        protected function spp_reader_init() {
996
                $this->spp_reader_uninit();
996
                $this->spp_reader_uninit();
997
 
997
 
998
                $ary = explode(':', $this->addr);
998
                $ary = explode(':', $this->addr); // TODO: does not work with an IPv6 address
999
                $host = $ary[0];
999
                $host = $ary[0];
1000
                $service_port = isset($ary[1]) ? $ary[1] : self::DEFAULT_PORT;
1000
                $service_port = isset($ary[1]) ? $ary[1] : self::DEFAULT_PORT;
-
 
1001
 
-
 
1002
                $is_ip = filter_var($host, FILTER_VALIDATE_IP) !== false;
-
 
1003
                if (!$is_ip) {
1001
                $address = @gethostbyname($host);
1004
                        $address = @gethostbyname($host);
1002
                if ($address === false) {
1005
                        if ($address === $host) {
1003
                        echo "gethostbyname() failed.\n"; // TODO: exceptions? (also all "echos" below)
1006
                                echo "gethostbyname() failed.\n"; // TODO: exceptions? (also all "echos" below)
1004
                        return false;
1007
                                return false;
1005
                }
1008
                        }
-
 
1009
                } else {
-
 
1010
                        $address = $host;
-
 
1011
                }
-
 
1012
 
1006
                $this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
1013
                $this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
1007
                if ($this->socket === false) {
1014
                if ($this->socket === false) {
1008
                        echo "socket_create() failed: " . socket_strerror(socket_last_error()) . "\n";
1015
                        echo "socket_create() failed: " . socket_strerror(socket_last_error()) . "\n";
1009
                        return false;
1016
                        return false;
1010
                }
1017
                }