1de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz/*
2de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz * Copyright (C) 2017 The Android Open Source Project
3de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz *
4de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz * Licensed under the Apache License, Version 2.0 (the "License");
5de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz * you may not use this file except in compliance with the License.
6de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz * You may obtain a copy of the License at
7de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz *
8de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz *      http://www.apache.org/licenses/LICENSE-2.0
9de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz *
10de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz * Unless required by applicable law or agreed to in writing, software
11de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz * distributed under the License is distributed on an "AS IS" BASIS,
12de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz * See the License for the specific language governing permissions and
14de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz * limitations under the License.
15de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz */
16de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz
17de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz#include <arpa/inet.h>
18de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz
19de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz#include "netdutils/Slice.h"
20de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz#include "netdutils/Socket.h"
21de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz
22de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelznamespace android {
23de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelznamespace netdutils {
24de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz
25de9379641d5fc4b5912d6838075df9490518cca6Joel ScherpelzStatusOr<std::string> toString(const in6_addr& addr) {
26de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz    std::array<char, INET6_ADDRSTRLEN> out = {};
27de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz    auto* rv = inet_ntop(AF_INET6, &addr, out.data(), out.size());
28de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz    if (rv == nullptr) {
29de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz        return statusFromErrno(errno, "inet_ntop() failed");
30de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz    }
31de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz    return std::string(out.data());
32de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz}
33de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz
34de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz}  // namespace netdutils
35de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz}  // namespace android
36