diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 03:21:31 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 03:21:31 +0000 |
commit | 76ff86af64d9260bc6042b3ab80adf78cc1a1582 (patch) | |
tree | a8c81194db224fcef75c6696a9c06def27171ad8 /net/base/ip_endpoint.h | |
parent | 211486bd44160962954c2b10874323f4ac6c838e (diff) | |
download | chromium_src-76ff86af64d9260bc6042b3ab80adf78cc1a1582.zip chromium_src-76ff86af64d9260bc6042b3ab80adf78cc1a1582.tar.gz chromium_src-76ff86af64d9260bc6042b3ab80adf78cc1a1582.tar.bz2 |
Add an IPEndPoint class as a simple class for dealing with struct sockaddr.
BUG=none
TEST=ip_endpoint_unittest
Review URL: http://codereview.chromium.org/6592096
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76868 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/ip_endpoint.h')
-rw-r--r-- | net/base/ip_endpoint.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/net/base/ip_endpoint.h b/net/base/ip_endpoint.h new file mode 100644 index 0000000..66aea71 --- /dev/null +++ b/net/base/ip_endpoint.h @@ -0,0 +1,53 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_BASE_IP_ENDPOINT_H_ +#define NET_BASE_IP_ENDPOINT_H_ +#pragma once + +#include "base/basictypes.h" +#include "net/base/net_util.h" + +struct sockaddr; + +namespace net { + +// An IPEndPoint represents the address of a transport endpoint: +// * IP address (either v4 or v6) +// * Port +class IPEndPoint { + public: + IPEndPoint(); + IPEndPoint(const IPAddressNumber& address, int port); + IPEndPoint(const IPEndPoint& endpoint); + + const IPAddressNumber& address() const { return address_; } + int port() const { return port_; } + + // Convert to a provided sockaddr struct. + // |address| is the sockaddr to copy into. Should be at least + // sizeof(struct sockaddr_storage) bytes. + // |address_length| is an input/output parameter. On input, it is the + // size of data in |address| available. On output, it is the size of + // the address that was copied into |address|. + // Returns true on success, false on failure. + bool ToSockaddr(struct sockaddr* address, size_t* address_length) const; + + // Convert from a sockaddr struct. + // |address| is the address. + // |address_length| is the length of |address|. + // Returns true on success, false on failure. + bool FromSockAddr(const struct sockaddr* address, size_t address_length); + + bool operator<(const IPEndPoint& that) const; + bool operator==(const IPEndPoint& that) const; + + private: + IPAddressNumber address_; + int port_; +}; + +} // namespace net + +#endif // NET_BASE_IP_ENDPOINT_H_ |