Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libcloud/utils/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -15,6 +15,7 @@

import socket
import struct
import platform

__all__ = [
'is_private_subnet',
Expand Down Expand Up @@ -73,7 +74,10 @@ def is_valid_ip_address(address, family=socket.AF_INET):
:return: ``bool`` True if the provided address is valid.
"""
try:
socket.inet_pton(family, address)
if (platform.system() == 'Windows'):
socket.inet_aton(address)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is still an edge case with IPv6 which inet_aton doesn't support, but inet_pton does.

Maybe we should throw if running on Windows and user specifies family=socket.AF_INET6.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact there is an issue with IPv6 when using inet_aton.
So we could throw an exception or use an external library dnspython wihich provide inet_aton for ipv4 and ipv6 and for windows also.
Let me know if adding such library is something acceptable or I will just add the throw.

else:
socket.inet_pton(family, address)
except socket.error:
return False

Expand Down