From 2482dd05e5b7806b4bad69ac8e07dbc4dd6714e0 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sat, 3 Mar 2012 13:45:23 -0600 Subject: [PATCH] =?UTF-8?q?Fix=20hostname=20display=20in=20titlebar=20with?= =?UTF-8?q?=20certain=20programs=20This=20closes=20Bug=20889=20Thanks=20to?= =?UTF-8?q?=20Sl=C3=A1vek=20Banko=20for=20the=20patch!=20(cherry=20picked?= =?UTF-8?q?=20from=20commit=209e3f8a7f0c9f2ed1125c717f5374aaf8d4ec225e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kwin/utils.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/kwin/utils.cpp b/kwin/utils.cpp index 34d29f98a..a2e563d88 100644 --- a/kwin/utils.cpp +++ b/kwin/utils.cpp @@ -18,6 +18,8 @@ License. See the file "COPYING" for the exact licensing terms. #include "utils.h" #include +#include +#include #ifndef KCMRULES @@ -323,6 +325,27 @@ bool isLocalMachine( const TQCString& host ) if( host == hostnamebuf ) return true; } + else + { // e.g. LibreOffice likes to give FQDN, even if gethostname() doesn't include domain + struct addrinfo hints, *res, *addr; + bool is_local = false; + + memset (&hints, 0, sizeof (hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags |= AI_CANONNAME; + + if( getaddrinfo( host, NULL, &hints, &res ) != 0) + return false; + for(addr = res; !is_local && addr; addr = addr->ai_next) + { + if( res->ai_canonname && + host == TQCString( res->ai_canonname )) + is_local = true; + } + freeaddrinfo(res); + return is_local; + } } return false; }