sockaddr_storage.cc 802 B

123456789101112131415161718192021222324252627
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "net/base/sockaddr_storage.h"
  5. #include <string.h>
  6. namespace net {
  7. SockaddrStorage::SockaddrStorage()
  8. : addr_len(sizeof(addr_storage)),
  9. addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {}
  10. SockaddrStorage::SockaddrStorage(const SockaddrStorage& other)
  11. : addr_len(other.addr_len),
  12. addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {
  13. memcpy(addr, other.addr, addr_len);
  14. }
  15. void SockaddrStorage::operator=(const SockaddrStorage& other) {
  16. addr_len = other.addr_len;
  17. // addr is already set to &this->addr_storage by default ctor.
  18. memcpy(addr, other.addr, addr_len);
  19. }
  20. } // namespace net