Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymilter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
misc
pymilter
Commits
a43649f2
Commit
a43649f2
authored
13 years ago
by
Stuart Gathman
Browse files
Options
Downloads
Patches
Plain Diff
Make addr2bin and dynip handle IP6.
parent
de679b15
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Milter/dynip.py
+2
-1
2 additions, 1 deletion
Milter/dynip.py
Milter/utils.py
+10
-5
10 additions, 5 deletions
Milter/utils.py
with
12 additions
and
6 deletions
Milter/dynip.py
+
2
−
1
View file @
a43649f2
...
...
@@ -48,9 +48,10 @@ def is_dynip(host,addr):
True
"""
if
host
.
startswith
(
'
[
'
)
and
host
.
endswith
(
'
]
'
):
return
True
return
True
# no ptr
if
addr
:
if
host
.
find
(
addr
)
>=
0
:
return
True
if
addr
.
find
(
'
:
'
)
>=
0
:
return
False
# IP6
a
=
addr
.
split
(
'
.
'
)
ia
=
map
(
int
,
a
)
h
=
host
...
...
This diff is collapsed.
Click to expand it.
Milter/utils.py
+
10
−
5
View file @
a43649f2
...
...
@@ -28,16 +28,21 @@ ip6re = re.compile( '(?:%(hex4)s:){6}%(ls32)s$'
},
re
.
IGNORECASE
)
# from spf.py
def
addr2bin
(
s
tr
):
def
addr2bin
(
s
):
"""
Convert a string IPv4 address into an unsigned integer.
"""
if
s
.
find
(
'
:
'
)
>=
0
:
try
:
return
struct
.
unpack
(
"
!L
"
,
socket
.
inet_aton
(
str
))[
0
]
return
bin2long6
(
inet_pton
(
s
))
except
:
raise
socket
.
error
(
"
Invalid IP6 address:
"
+
s
)
try
:
return
struct
.
unpack
(
"
!L
"
,
socket
.
inet_aton
(
s
))[
0
]
except
socket
.
error
:
raise
socket
.
error
(
"
Invalid IP4 address:
"
+
s
tr
)
raise
socket
.
error
(
"
Invalid IP4 address:
"
+
s
)
def
bin2long6
(
s
tr
):
def
bin2long6
(
s
):
"""
Convert binary IP6 address into an unsigned Python long integer.
"""
h
,
l
=
struct
.
unpack
(
"
!QQ
"
,
s
tr
)
h
,
l
=
struct
.
unpack
(
"
!QQ
"
,
s
)
return
h
<<
64
|
l
if
hasattr
(
socket
,
'
has_ipv6
'
)
and
socket
.
has_ipv6
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment