diff options
author | Gabe Black <gblack@eecs.umich.edu> | 2010-11-23 15:54:43 -0500 |
---|---|---|
committer | Gabe Black <gblack@eecs.umich.edu> | 2010-11-23 15:54:43 -0500 |
commit | b3de4855c3dba9df80cca4540c4ee6625c26f9e1 (patch) | |
tree | 28f1876bd2d31904d1f3d4bdbde4ac6def7207a1 /src/base/inet.cc | |
parent | 40d434d5516affffe9ded9365e0d2da060aa7c78 (diff) | |
download | gem5-b3de4855c3dba9df80cca4540c4ee6625c26f9e1.tar.xz |
Params: Add parameter types for IP addresses in various forms.
New parameter forms are:
IP address in the format "a.b.c.d" where a-d are from decimal 0 to 255.
IP address with netmask which is an IP followed by "/n" where n is a netmask
length in bits from decimal 0 to 32 or by "/e.f.g.h" where e-h are from
decimal 0 to 255 and which is all 1 bits followed by all 0 bits when
represented in binary. These can also be specified as an integral IP and
netmask passed in separately.
IP address with port which is an IP followed by ":p" where p is a port index
from decimal 0 to 65535. These can also be specified as an integral IP and
port value passed in separately.
Diffstat (limited to 'src/base/inet.cc')
-rw-r--r-- | src/base/inet.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/base/inet.cc b/src/base/inet.cc index 1a280e993..93501018e 100644 --- a/src/base/inet.cc +++ b/src/base/inet.cc @@ -117,6 +117,73 @@ operator<<(ostream &stream, const EthAddr &ea) return stream; } +string +IpAddress::string() const +{ + stringstream stream; + stream << *this; + return stream.str(); +} + +bool +operator==(const IpAddress &left, const IpAddress &right) +{ + return left.ip() == right.ip(); +} + +ostream & +operator<<(ostream &stream, const IpAddress &ia) +{ + uint32_t ip = ia.ip(); + ccprintf(stream, "%x.%x.%x.%x", + (uint8_t)(ip >> 0), (uint8_t)(ip >> 8), + (uint8_t)(ip >> 16), (uint8_t)(ip >> 24)); + return stream; +} + +string +IpNetmask::string() const +{ + stringstream stream; + stream << *this; + return stream.str(); +} + +bool +operator==(const IpNetmask &left, const IpNetmask &right) +{ + return (left.ip() == right.ip()) && + (left.netmask() == right.netmask()); +} + +ostream & +operator<<(ostream &stream, const IpNetmask &in) +{ + ccprintf(stream, "%s/%d", (const IpAddress &)in, in.netmask()); + return stream; +} + +string +IpWithPort::string() const +{ + stringstream stream; + stream << *this; + return stream.str(); +} + +bool +operator==(const IpWithPort &left, const IpWithPort &right) +{ + return (left.ip() == right.ip()) && (left.port() == right.port()); +} + +ostream & +operator<<(ostream &stream, const IpWithPort &iwp) +{ + ccprintf(stream, "%s:%d", (const IpAddress &)iwp, iwp.port()); + return stream; +} + uint16_t cksum(const IpPtr &ptr) { |