blob: deff115781041d1bbc4e70ffa66f42d37899bee5 (
plain)
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
|
// 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 IPAddress& address) {
if (address.IsIPv4()) {
return ADDRESS_FAMILY_IPV4;
} else if (address.IsIPv6()) {
return ADDRESS_FAMILY_IPV6;
} else {
return ADDRESS_FAMILY_UNSPECIFIED;
}
}
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
|