inet.hh (6216:2f4020838149) inet.hh (7777:369f90d32e2e)
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 133 unchanged lines hidden (view full) ---

142 operator bool() const { return p; }
143 int off() const { return 0; }
144 int pstart() const { return off() + ((const EthHdr*)p->data)->size(); }
145};
146
147/*
148 * IP Stuff
149 */
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 133 unchanged lines hidden (view full) ---

142 operator bool() const { return p; }
143 int off() const { return 0; }
144 int pstart() const { return off() + ((const EthHdr*)p->data)->size(); }
145};
146
147/*
148 * IP Stuff
149 */
150struct IpAddress
151{
152 protected:
153 uint32_t _ip;
154
155 public:
156 IpAddress() : _ip(0)
157 {}
158 IpAddress(const uint32_t __ip) : _ip(__ip)
159 {}
160
161 uint32_t ip() const { return _ip; }
162
163 std::string string() const;
164};
165
166std::ostream &operator<<(std::ostream &stream, const IpAddress &ia);
167bool operator==(const IpAddress &left, const IpAddress &right);
168
169struct IpNetmask : public IpAddress
170{
171 protected:
172 uint8_t _netmask;
173
174 public:
175 IpNetmask() : IpAddress(), _netmask(0)
176 {}
177 IpNetmask(const uint32_t __ip, const uint8_t __netmask) :
178 IpAddress(__ip), _netmask(__netmask)
179 {}
180
181 uint8_t netmask() const { return _netmask; }
182
183 std::string string() const;
184};
185
186std::ostream &operator<<(std::ostream &stream, const IpNetmask &in);
187bool operator==(const IpNetmask &left, const IpNetmask &right);
188
189struct IpWithPort : public IpAddress
190{
191 protected:
192 uint16_t _port;
193
194 public:
195 IpWithPort() : IpAddress(), _port(0)
196 {}
197 IpWithPort(const uint32_t __ip, const uint16_t __port) :
198 IpAddress(__ip), _port(__port)
199 {}
200
201 uint8_t port() const { return _port; }
202
203 std::string string() const;
204};
205
206std::ostream &operator<<(std::ostream &stream, const IpWithPort &iwp);
207bool operator==(const IpWithPort &left, const IpWithPort &right);
208
150struct IpOpt;
151struct IpHdr : public ip_hdr
152{
153 uint8_t version() const { return ip_v; }
154 uint8_t hlen() const { return ip_hl * 4; }
155 uint8_t tos() const { return ip_tos; }
156 uint16_t len() const { return ntohs(ip_len); }
157 uint16_t id() const { return ntohs(ip_id); }

--- 259 unchanged lines hidden ---
209struct IpOpt;
210struct IpHdr : public ip_hdr
211{
212 uint8_t version() const { return ip_v; }
213 uint8_t hlen() const { return ip_hl * 4; }
214 uint8_t tos() const { return ip_tos; }
215 uint16_t len() const { return ntohs(ip_len); }
216 uint16_t id() const { return ntohs(ip_id); }

--- 259 unchanged lines hidden ---