Skip to content

Option to show used IP source address in output#461

Open
gsnw-sebast wants to merge 1 commit intoschweikert:developfrom
gsnw:print-srcaddr
Open

Option to show used IP source address in output#461
gsnw-sebast wants to merge 1 commit intoschweikert:developfrom
gsnw:print-srcaddr

Conversation

@gsnw-sebast
Copy link
Collaborator

@gsnw-sebast gsnw-sebast commented Feb 14, 2026

New function for outputting the source IP address.
IPv6 is currently not supported. Major changes are necessary here.
Under Ubuntu 22.04, the test ./fping --print-srcaddr 127.0.0.1 always returns unknown.

Issues: #261

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gsnw-sebast, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new feature to fping that allows users to display the source IP address used for sending ICMP echo requests. This enhancement provides greater visibility into network path details, particularly useful in environments with multiple network interfaces or complex routing. The change involves adding a new command-line option, --print-srcaddr, and modifying the core ping logic to extract and present this information in the output.

Highlights

  • New --print-srcaddr option: Introduced a new command-line option to display the source IP address used for outgoing pings.
  • Source IP extraction: Implemented logic to extract the source IP address from IPv4 ICMP replies.
  • Output integration: Integrated the source IP address into both standard and JSON output formats.
  • IPv6 limitation: Explicitly noted that source address printing is not currently supported for IPv6.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • CHANGELOG.md
    • Added a new feature entry for --print-srcaddr.
  • ci/test-11-unpriv.pl
    • Increased the number of planned tests.
    • Included a new test case for fping --print-srcaddr in unprivileged mode.
  • ci/test-16-json-output.pl
    • Increased the number of planned tests.
    • Added a test case for fping -J --print-srcaddr to verify JSON output includes the source address.
  • doc/fping.pod
    • Documented the new --print-srcaddr option, explaining its function and current IPv6 limitation.
  • src/flags.c
    • Declared opt_print_srcaddr_on to control the new feature.
  • src/flags.h
    • Added extern int opt_print_srcaddr_on; for global access.
  • src/fping.c
    • Modified default_ip_header_result to initialize the new src_addr field.
    • Registered --print-srcaddr as a long option.
    • Set opt_print_srcaddr_on when the --print-srcaddr option is parsed.
    • Updated decode_icmp_ipv4 to extract and store the source IP address from the IP header.
    • Modified decode_icmp_ipv6 to explicitly state 'not supported' for source address printing.
    • Adjusted the wait_for_reply function signature for decode_icmp_ipv6 to pass IP_HEADER_RESULT.
    • Added --print-srcaddr to the usage output.
  • src/fping.h
    • Added char src_addr[INET6_ADDRSTRLEN]; to the IP_HEADER_RESULT struct to store the source IP address.
  • src/output.c
    • Modified print_recv_ext to append the source IP address to the output if opt_print_srcaddr_on is set.
    • Modified print_recv_ext_json to include the source IP address in the JSON output.
Activity
  • The pull request was created by @gsnw-sebast with the title 'Option to show used IP source address in output' and a description outlining the new function, current IPv6 limitations, and a test observation on Ubuntu 22.04.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new --print-srcaddr option to display the source IP address of ping packets. The implementation correctly handles IPv4 and adds appropriate documentation, option parsing, and tests. For IPv6, it correctly indicates that the feature is not yet supported.

The code is well-structured, but I have a couple of suggestions for improvement. I've recommended a small refactoring in src/fping.c to simplify the source address retrieval logic. Additionally, I've suggested an update to one of the new tests in ci/test-16-json-output.pl to make it more robust by handling all possible outputs for the source address, which you also noted in the PR description.

Overall, this is a great addition to fping.

Comment on lines +104 to +105
$cmd->stdout_like(qr/^\{"resp":\s\{"host":\s"127\.0\.0\.1",\s"seq":\s0,\s"size":\s\d+,\s"rtt":\s\d+\.\d+,\s"src":\s"\d+\.\d+\.\d+\.\d+"\}\}
\{"summary":\s\{"host":\s"127\.0\.0\.1",\s"xmt":\s\d+,\s"rcv":\s\d+,\s"loss":\s\d+,\s"rttMin":\s\d+\.\d+,\s"rttAvg":\s\d+\.\d+,\s"rttMax":\s\d+\.\d+\}\}\n?$/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The regular expression for testing --print-srcaddr with JSON output doesn't account for the case where the source address is unknown. As you noted in the pull request description, this can happen in some environments (like unprivileged mode on Linux). To make the test more robust, it should be updated to handle this case, similar to the test in ci/test-11-unpriv.pl.

$cmd->stdout_like(qr/^\{"resp":\s\{"host":\s"127\.0\.0\.1",\s"seq":\s0,\s"size":\s\d+,\s"rtt":\s\d+\.\d+,\s"src":\s"(?:\d+\.\d+\.\d+\.\d+|unknown)"\}\}
\{"summary":\s\{"host":\s"127\.0\.0\.1",\s"xmt":\s\d+,\s"rcv":\s\d+,\s"loss":\s\d+,\s"rttMin":\s\d+\.\d+,\s"rttAvg":\s\d+\.\d+,\s"rttMax":\s\d+\.\d+\}\}\n?$/);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under Ubuntu 22.04, the test ./fping --print-srcaddr 127.0.0.1 always returns unknown.
I tested this with ubuntu-latest on Azure DevOps, and the behavior does not occur there.

@coveralls
Copy link

coveralls commented Feb 14, 2026

Coverage Status

coverage: 88.245% (+0.2%) from 88.037%
when pulling c4b1982 on gsnw:print-srcaddr
into b862609 on schweikert:develop.

@gsnw-sebast
Copy link
Collaborator Author

I've already finished the version with IPv6, but I'll submit it in a separate pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to show used IP source address in output

2 participants