Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
09fff7a8
Commit
09fff7a8
authored
Nov 05, 2010
by
Hirokazu Yamamoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed socket_gethostname() on windows.
parent
9696088b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
Modules/socketmodule.c
Modules/socketmodule.c
+9
-6
No files found.
Modules/socketmodule.c
View file @
09fff7a8
...
...
@@ -3097,17 +3097,20 @@ socket_gethostname(PyObject *self, PyObject *unused)
/* Don't use winsock's gethostname, as this returns the ANSI
version of the hostname, whereas we need a Unicode string.
Otherwise, gethostname apparently also returns the DNS name. */
wchar_t
buf
[
MAX_COMPUTERNAME_LENGTH
];
DWORD
size
=
sizeof
(
buf
);
wchar_t
buf
[
MAX_COMPUTERNAME_LENGTH
+
1
];
DWORD
size
=
sizeof
(
buf
)
/
sizeof
(
wchar_t
);
PyObject
*
result
;
if
(
!
GetComputerNameExW
(
ComputerNamePhysicalDnsHostname
,
buf
,
&
size
))
{
if
(
GetLastError
()
==
ERROR_MORE_DATA
)
{
/* MSDN says this may occur "because DNS allows longer names */
PyObject
*
result
=
PyUnicode_FromUnicode
(
NULL
,
size
);
if
(
size
==
0
)
/* XXX: I'm not sure how to handle this */
return
PyUnicode_FromUnicode
(
NULL
,
0
);
result
=
PyUnicode_FromUnicode
(
NULL
,
size
-
1
);
if
(
!
result
)
return
NULL
;
if
(
GetComputerName
(
ComputerNamePhysicalDnsHostname
,
PyUnicode_AS_UNICODE
(
result
),
size
+
1
))
if
(
GetComputerName
ExW
(
ComputerNamePhysicalDnsHostname
,
PyUnicode_AS_UNICODE
(
result
),
&
size
))
return
result
;
Py_DECREF
(
result
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment