diff options
author | Rob Austein <sra@hactrn.net> | 2008-02-27 19:02:11 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2008-02-27 19:02:11 +0000 |
commit | e1bc9584d821857a9a1869f38b934812ff60f7fb (patch) | |
tree | c9c1f45818ab9f4e6dacefc1428c9a9dcb67c0fd /scripts/rpki/ipaddrs.py | |
parent | a9ecdddda7c364cd62dbd1c16fc0f19615fe288e (diff) |
Filename cleanup
svn path=/rpkid/Makefile; revision=1531
Diffstat (limited to 'scripts/rpki/ipaddrs.py')
-rw-r--r-- | scripts/rpki/ipaddrs.py | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/scripts/rpki/ipaddrs.py b/scripts/rpki/ipaddrs.py deleted file mode 100644 index 4de2f428..00000000 --- a/scripts/rpki/ipaddrs.py +++ /dev/null @@ -1,70 +0,0 @@ -# $Id$ - -# Copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH -# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, -# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -# PERFORMANCE OF THIS SOFTWARE. - -"""Classes to represent IP addresses. - -Given some of the other operations we need to perform on them, it's -most convenient to represent IP addresses as Python "long" values. -The classes in this module just wrap suitable read/write syntax around -the underlying "long" type. - -These classes also supply a "bits" attribute for use by other code -built on these classes; for the most part, IPv6 addresses really are -just IPv4 addresses with more bits, so we supply the number of bits -once, here, thus avoiding a lot of duplicate code elsewhere. -""" - -import socket, struct - -class v4addr(long): - """IPv4 address. - - Derived from long, but supports IPv4 print syntax. - """ - - bits = 32 - - def __new__(cls, x): - """Construct a v4addr object.""" - if isinstance(x, str): - x = ".".join(str(int(i)) for i in x.split(".")) - y = struct.unpack("!I", socket.inet_pton(socket.AF_INET, x)) - x = y[0] - return long.__new__(cls, x) - - def __str__(self): - """Convert a v4addr object to string format.""" - return socket.inet_ntop(socket.AF_INET, struct.pack("!I", long(self))) - -class v6addr(long): - """IPv6 address. - - Derived from long, but supports IPv6 print syntax. - """ - - bits = 128 - - def __new__(cls, x): - """Construct a v6addr object.""" - if isinstance(x, str): - y = struct.unpack("!QQ", socket.inet_pton(socket.AF_INET6, x)) - x = (y[0] << 64) | y[1] - return long.__new__(cls, x) - - def __str__(self): - """Convert a v6addr object to string format.""" - return socket.inet_ntop(socket.AF_INET6, - struct.pack("!QQ", long(self) >> 64, long(self) & 0xFFFFFFFFFFFFFFFF)) |