Internet: account for socket_create() maybe failing in getInternalIP()

This commit is contained in:
Dylan K. Taylor 2020-04-15 09:37:17 +01:00
parent 51908ec45a
commit 53dbbd5f97

View File

@ -116,7 +116,10 @@ class Internet{
* @throws InternetException
*/
public static function getInternalIP() : string{
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$sock = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if($sock === false){
throw new InternetException("Failed to get internal IP: " . trim(socket_strerror(socket_last_error())));
}
try{
if(!@socket_connect($sock, "8.8.8.8", 65534)){
throw new InternetException("Failed to get internal IP: " . trim(socket_strerror(socket_last_error($sock))));