os-ken/ryu/lib/ip.py
YAMAMOTO Takashi d31b5dd367 addrconv: use bytes instead of int to represent ipv4 addresses
change ipv4 representation from int to bytes in many places.
replace homegrown bin<->text routines with addrconv for ipv4.

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
2013-07-24 04:12:07 +09:00

31 lines
739 B
Python

from ryu.lib import addrconv
def ipv4_to_bin(ip):
'''
Parse an IP address and return an unsigned int.
The IP address is in dotted decimal notation.
'''
return addrconv.ipv4.text_to_bin(ip)
def ipv4_to_str(ip):
"""Generate IP address string from an unsigned int.
ip: unsigned int of form w << 24 | x << 16 | y << 8 | z
returns: ip address string w.x.y.z"""
return addrconv.ipv4.bin_to_text(ip)
def ipv6_to_bin(ipv6):
'''
convert ipv6 string to binary representation
'''
return addrconv.ipv6.text_to_bin(ipv6)
def ipv6_to_str(bin_addr):
'''
convert binary representation to human readable string
'''
return addrconv.ipv6.bin_to_text(bin_addr)