blob: 6a825f7dd8a8a915710b6518b236cd05357780bd [file] [log] [blame]
Hugo Benichi2ac4d072019-05-28 14:51:23 +09001// Copyright 2019 The Chromium OS 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
5#include "arc/network/net_util.h"
6
Long Chenge4c86762019-09-24 18:52:40 +00007#include <arpa/inet.h>
Hugo Benichi2ac4d072019-05-28 14:51:23 +09008
9namespace arc_networkd {
10
11std::string IPv4AddressToString(uint32_t addr) {
12 char buf[INET_ADDRSTRLEN] = {0};
13 struct in_addr ia;
14 ia.s_addr = addr;
15 return !inet_ntop(AF_INET, &ia, buf, sizeof(buf)) ? "" : buf;
16}
17
18std::string IPv4AddressToCidrString(uint32_t addr, uint32_t prefix_length) {
19 return IPv4AddressToString(addr) + "/" + std::to_string(prefix_length);
20}
21
Hugo Benichi2ac4d072019-05-28 14:51:23 +090022} // namespace arc_networkd