Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CPUnetLOG
TCPlivePLOT
Commits
23c477c1
Commit
23c477c1
authored
Oct 03, 2016
by
Michael König (Student)
Browse files
support for ipv6 (and 4) + parse hostnames
parent
1b7d1561
Changes
1
Hide whitespace changes
Inline
Side-by-side
tcpliveplot/backends/input/socket.py
View file @
23c477c1
...
@@ -28,14 +28,39 @@ class SocketInput(InputBase):
...
@@ -28,14 +28,39 @@ class SocketInput(InputBase):
self
.
socketUp
=
False
self
.
socketUp
=
False
self
.
__stopped
=
threading
.
Event
()
self
.
__stopped
=
threading
.
Event
()
ip
,
separator
,
port
=
self
.
options
.
logServer
.
rpartition
(
':'
)
if
(
":"
not
in
self
.
options
.
logServer
):
# only ipv4-address or hostname w/o port given
if
(
':'
not
in
self
.
options
.
logServer
or
port
is
''
):
ip
=
self
.
options
.
logServer
self
.
logServerPort
=
DEFAULT_SOCKETSERVER_PORT
port
=
DEFAULT_SOCKETSERVER_PORT
self
.
logServerIp
=
ip_address
(
socket
.
gethostbyname
(
self
.
options
.
logServer
.
strip
(
"[]"
)))
elif
(
self
.
options
.
logServer
.
count
(
":"
)
>
1
):
# ipv6-address given
try
:
ip
=
ip_address
(
self
.
options
.
logServer
)
except
ValueError
:
try
:
ip
,
separator
,
port
=
self
.
options
.
logServer
.
rpartition
(
':'
)
self
.
logServerIp
=
ip_address
(
ip
)
except
ValueError
:
print
(
"Fatal error (Log-Server location malformatted)... should not have done this..."
)
else
:
port
=
DEFAULT_SOCKETSERVER_PORT
else
:
# ipv4-address w/ port given
ip
,
separator
,
port
=
self
.
options
.
logServer
.
rpartition
(
':'
)
if
(
port
is
''
):
port
=
DEFAULT_SOCKETSERVER_PORT
try
:
self
.
logServerIp
=
ip_address
(
ip
)
except
ValueError
:
self
.
logServerIp
=
ip_address
(
socket
.
gethostbyname
(
ip
.
strip
(
"[]"
)))
else
:
else
:
self
.
logServerPort
=
int
(
port
)
pass
self
.
logServerIp
=
ip_address
(
socket
.
gethostbyname
(
ip
.
strip
(
"[]"
)))
self
.
logServerPort
=
int
(
port
)
self
.
dst
=
str
(
self
.
logServerIp
)
+
":"
+
str
(
self
.
logServerPort
)
self
.
dst
=
str
(
self
.
logServerIp
)
+
":"
+
str
(
self
.
logServerPort
)
if
(
self
.
options
.
debug
):
print
(
str
(
self
.
dst
))
def
startupCheck
(
self
):
def
startupCheck
(
self
):
pass
pass
...
@@ -52,7 +77,10 @@ class SocketInput(InputBase):
...
@@ -52,7 +77,10 @@ class SocketInput(InputBase):
def
createSocket
(
self
):
def
createSocket
(
self
):
try
:
try
:
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
if
(
ip_address
(
self
.
logServerIp
).
version
is
4
):
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
else
:
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_STREAM
)
except
socket
.
error
:
except
socket
.
error
:
print
(
"Failed to create socket"
)
print
(
"Failed to create socket"
)
else
:
else
:
...
...
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