Index: configure =================================================================== --- configure (révision 88640) +++ configure (copie de travail) @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 88624 . +# From configure.in Revision: 88625 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.65 for python 3.3. # @@ -9319,7 +9319,7 @@ mkfifoat mknod mknodat mktime mremap nice openat pathconf pause plock poll \ pthread_init putenv readlink readlinkat realpath renameat \ select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \ - setgid \ + setgid sethostname \ setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \ sigaction siginterrupt sigrelse snprintf strftime strlcpy symlinkat \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ Index: configure.in =================================================================== --- configure.in (révision 88640) +++ configure.in (copie de travail) @@ -2542,7 +2542,7 @@ mkfifoat mknod mknodat mktime mremap nice openat pathconf pause plock poll \ pthread_init putenv readlink readlinkat realpath renameat \ select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \ - setgid \ + setgid sethostname \ setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \ sigaction siginterrupt sigrelse snprintf strftime strlcpy symlinkat \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ Index: Doc/library/socket.rst =================================================================== --- Doc/library/socket.rst (révision 88640) +++ Doc/library/socket.rst (copie de travail) @@ -521,6 +521,15 @@ meanings. +.. function:: sethostname(name) + + Sets the machine's hostname to *name*. + + Availability: Unix. + + .. versionadded:: 3.3 + + .. data:: SocketType This is a Python type object that represents the socket object type. It is the Index: Lib/test/test_socket.py =================================================================== --- Lib/test/test_socket.py (révision 88640) +++ Lib/test/test_socket.py (copie de travail) @@ -325,6 +325,26 @@ if not fqhn in all_host_names: self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names))) + @unittest.skipUnless(hasattr(socket, 'sethostname'), "test needs socket.sethostname()") + @unittest.skipUnless(hasattr(socket, 'gethostname'), "test needs socket.gethostname()") + def test_sethostname(self): + oldhn = socket.gethostname() + try: + socket.sethostname('new') + except socket.error as e: + if e.errno == errno.EPERM: + self.skipTest("test should be run as root") + else: + raise + try: + # running test as root! + self.assertEqual(socket.gethostname(), 'new') + # Should work with bytes objects too + socket.sethostname(b'bar') + self.assertEqual(socket.gethostname(), 'bar') + finally: + socket.sethostname(oldhn) + def testRefCountGetNameInfo(self): # Testing reference count for getnameinfo if hasattr(sys, "getrefcount"): Index: Modules/socketmodule.c =================================================================== --- Modules/socketmodule.c (révision 88640) +++ Modules/socketmodule.c (copie de travail) @@ -3135,7 +3135,38 @@ \n\ Return the current host name."); +#ifdef HAVE_SETHOSTNAME +PyDoc_STRVAR(sethostname_doc, +"sethostname(name)\n\n\ +Sets the hostname to name."); +static PyObject * +socket_sethostname(PyObject *self, PyObject *args) +{ + PyObject *hnobj; + Py_buffer buf; + int res, flag = 0; + + if (!PyArg_ParseTuple(args, "S:sethostname", &hnobj)) { + PyErr_Clear(); + if (!PyArg_ParseTuple(args, "O&:sethostname", + PyUnicode_FSConverter, &hnobj)) + return NULL; + flag = 1; + } + res = PyObject_GetBuffer(hnobj, &buf, PyBUF_SIMPLE); + if (!res) { + res = sethostname(buf.buf, buf.len); + PyBuffer_Release(&buf); + } + if (flag) + Py_DECREF(hnobj); + if (res) + return set_error(); + Py_RETURN_NONE; +} +#endif + /* Python interface to gethostbyname(name). */ /*ARGSUSED*/ @@ -4233,6 +4264,10 @@ METH_VARARGS, gethostbyaddr_doc}, {"gethostname", socket_gethostname, METH_NOARGS, gethostname_doc}, +#ifdef HAVE_SETHOSTNAME + {"sethostname", socket_sethostname, + METH_VARARGS, sethostname_doc}, +#endif {"getservbyname", socket_getservbyname, METH_VARARGS, getservbyname_doc}, {"getservbyport", socket_getservbyport, Index: pyconfig.h.in =================================================================== --- pyconfig.h.in (révision 88640) +++ pyconfig.h.in (copie de travail) @@ -635,6 +635,9 @@ /* Define if you have the 'setgroups' function. */ #undef HAVE_SETGROUPS +/* Define to 1 if you have the `sethostname' function. */ +#undef HAVE_SETHOSTNAME + /* Define to 1 if you have the `setitimer' function. */ #undef HAVE_SETITIMER