forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress_family.cc
41 lines (34 loc) · 1012 Bytes
/
address_family.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2015 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.
#include "net/base/address_family.h"
#include "base/logging.h"
#include "net/base/ip_address.h"
#include "net/base/sys_addrinfo.h"
namespace net {
AddressFamily GetAddressFamily(const IPAddressNumber& address) {
switch (address.size()) {
case kIPv4AddressSize:
return ADDRESS_FAMILY_IPV4;
case kIPv6AddressSize:
return ADDRESS_FAMILY_IPV6;
default:
return ADDRESS_FAMILY_UNSPECIFIED;
}
}
AddressFamily GetAddressFamily(const IPAddress& address) {
return GetAddressFamily(address.bytes());
}
int ConvertAddressFamily(AddressFamily address_family) {
switch (address_family) {
case ADDRESS_FAMILY_UNSPECIFIED:
return AF_UNSPEC;
case ADDRESS_FAMILY_IPV4:
return AF_INET;
case ADDRESS_FAMILY_IPV6:
return AF_INET6;
}
NOTREACHED();
return AF_UNSPEC;
}
} // namespace net