summaryrefslogtreecommitdiffstats
path: root/src/socket.py
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-02-05 17:18:31 +0100
committerAndreas Schneider <asn@cryptomilk.org>2013-02-07 16:58:18 +0100
commit237c6e951a8268afeaa288d8ddf0c79da32f6fd1 (patch)
tree682e9be946c28709c4cfb95fc72af7626f898786 /src/socket.py
downloadsocket_wrapper-237c6e951a8268afeaa288d8ddf0c79da32f6fd1.tar.gz
socket_wrapper-237c6e951a8268afeaa288d8ddf0c79da32f6fd1.tar.xz
socket_wrapper-237c6e951a8268afeaa288d8ddf0c79da32f6fd1.zip
Initial commit.
Diffstat (limited to 'src/socket.py')
-rw-r--r--src/socket.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/socket.py b/src/socket.py
new file mode 100644
index 0000000..ccbb820
--- /dev/null
+++ b/src/socket.py
@@ -0,0 +1,50 @@
+# Wrapper for socket wrapper (based on python socket wrapper)
+# Copyright (C) Amitay Isaacs 2011
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import _socket
+from _socket import *
+
+from samba.socket_wrapper import socket
+
+
+def getfqdn(name=''):
+ """Get fully qualified domain name from name.
+
+ An empty argument is interpreted as meaning the local host.
+
+ First the hostname returned by gethostbyaddr() is checked, then
+ possibly existing aliases. In case no FQDN is available, hostname
+ from gethostname() is returned.
+ """
+ name = name.strip()
+ if not name or name == '0.0.0.0':
+ name = gethostname()
+ try:
+ hostname, aliases, ipaddrs = gethostbyaddr(name)
+ except error:
+ pass
+ else:
+ aliases.insert(0, hostname)
+ for name in aliases:
+ if '.' in name:
+ break
+ else:
+ name = hostname
+ return name
+
+
+_GLOBAL_DEFAULT_TIMEOUT = object()