endpoint2hostname() prints a byte-swapped port for IPv6 endpoints
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 86/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- cpp
- 領域
- networking
調査の方向性
issueで ExtendedEndPoint::to_hostname() が示され、そのすぐ上で ExtendedEndPoint::to(EndPointStr*) と比較されている src/butil/details/extended_endpoint.hpp から始めてください。IPv6のポート変換を確認し、報告で言及されているユニットテストを追加するか実行してください。IPv6のホスト名出力でエンドポイントのポートが保持され、たとえば [::1]:8080 に対して ip6-localhost:8080 となり、既存のIPv4経路も引き続き正しく動作すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
butil::endpoint2hostname() of an IPv6 endpoint prints the port in network byte order. For [::1]:8080 it returns ip6-localhost:36895 on x86_64 (8080 = 0x1F90, 36895 = 0x901F). endpoint2str() of the same endpoint prints [::1]:8080, and the IPv4 path of endpoint2hostname() prints the right port.
ExtendedEndPoint::to_hostname() (src/butil/details/extended_endpoint.hpp:318 at 05abb1c3) passes _u.in6.sin6_port to snprintf without ntohs(). ExtendedEndPoint::to(EndPointStr*) a few lines above does call ntohs().
In bRPC itself this affects /connections with -show_hostname_instead_of_ip=true for IPv6 peers (src/brpc/builtin/connections_service.cpp:65-66; taken from the code, the page itself was not exercised).
To Reproduce
The machine needs a reverse name for ::1 (here /etc/hosts maps it to ip6-localhost).
#include <stdio.h>
#include <string>
#include "butil/endpoint.h"
int main() {
butil::EndPoint ep;
if (butil::str2endpoint("[::1]:8080", &ep) != 0) {
return 2;
}
std::string host;
if (butil::endpoint2hostname(ep, &host) != 0) {
printf("::1 has no reverse name on this machine\n");
return 2;
}
printf("endpoint2str : %s\n", butil::endpoint2str(ep).c_str());
printf("endpoint2hostname : %s\n", host.c_str());
return 0;
}
Output on master:
endpoint2str : [::1]:8080
endpoint2hostname : ip6-localhost:36895
Expected behavior
endpoint2str : [::1]:8080
endpoint2hostname : ip6-localhost:8080
Versions
OS: Ubuntu 24.04, x86_64
Compiler: gcc 13.3.0
brpc: master @ 05abb1c3
protobuf: 28.3
Additional context/screenshots
- A PR with the fix (add
ntohs()) and a unit test follows. - This report was prepared with an AI coding assistant (Claude Code, model claude-fable-5-2): the bug was found by reading the code and reproduced with the program above on master @ 05abb1c3 on a Linux x86_64 machine; the output shown is from that run.
- 主要言語
- C++
- スター
- 17.6k
- フォーク
- 4.2k
- 平均マージ
- 3日 17時間
- マージ済み PR(30日)
- 72
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/brpc のほかの issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 2 日以内に返信
-
perf(butil): ARM64 (aarch64) performance and modernisation improvements across atomics, CRC32C, spin-wait hints, and fast timers対応中かも @jimmystewpot が 2 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 12/100
メンテナーはふだん 2 日以内に返信
-
file:// naming service takes a comment after the address as the tag対応中かも @0z5a が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
メンテナーはふだん 2 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
メンテナーはふだん 2 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
protocolbuffers/protobuf#31768 ·
メンテナーはふだん 1 日以内に返信
-
Needs: Triage :mag: Platform: Android
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
react/react-native#60167 ·
メンテナーはふだん 2 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
-
tests: ofx_render_test doesn't compile against FFmpeg 4.x (const AVCodec* to av_find_best_stream)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NatronGitHub/openfx-io#221 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
subsurface/subsurface#5145 ·
メンテナーはふだん 2 日以内に返信