Skip to content

Conversation

@gsnw-sebast
Copy link
Collaborator

This is my first working version for sending a traceroute with fping.

It can be tested with the following command. I have omitted IPv6 for now, and some of the text still needs to be revised.
The primary focus was on the function itself.

./fping --traceroute 8.8.8.8

@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 enhances the fping utility by integrating a new --traceroute option. This feature allows users to trace the network path to a destination by sending ICMP echo requests with incrementally increasing Time-To-Live values. The changes involve modifications to host data structures, command-line argument parsing, and the core ping and reply handling logic to support the progressive discovery and reporting of network hops, providing a basic but functional traceroute capability.

Highlights

  • New Traceroute Option: Introduced a new command-line option, --traceroute, allowing fping to perform traceroute-like functionality by progressively increasing the Time-To-Live (TTL) for outgoing ICMP echo requests.
  • TTL Management: Implemented per-host trace_ttl tracking, dynamically setting the IP_TTL socket option for outgoing packets, and scheduling subsequent pings with incrementing TTLs to discover network hops.
  • ICMP Time Exceeded Handling: Added specific logic to decode_icmp_ipv4 to correctly parse and extract information from ICMP_TIMXCEED messages, which are crucial for identifying intermediate routers in a traceroute.
  • Traceroute Output and State: Modified wait_for_reply to print detailed output for both intermediate hops (identified by ICMP_TIMXCEED) and the final destination (identified by ICMP_ECHOREPLY), and to manage the traceroute state for each host.
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.

@gsnw-sebast gsnw-sebast linked an issue Dec 7, 2025 that may be closed by this pull request
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 --traceroute option to fping, adding a trace_ttl field to the host_entry structure and a global traceroute_flag. The changes involve parsing the new option, setting the number of trials to 255 for traceroute, dynamically setting the IP TTL for outgoing IPv4 packets using setsockopt in the main loop, and handling ICMP_TIMXCEED and ICMP_ECHOREPLY messages to report hop information and manage the traceroute process. Review comments suggest improving the option parsing by using strcmp instead of strstr for exact matching, optimizing TTL setting by using sendmsg with ancillary data instead of setsockopt per packet (and noting the current lack of IPv6 support), standardizing time formatting with sprint_tm(), and replacing the magic number 100 with a named constant for better code clarity.

}else{
usage(1);
}
} else if (strstr(optparse_state.optlongname, "traceroute") != NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using strcmp is safer here than strstr for checking the long option name. strstr could lead to incorrect behavior if another option name contains "traceroute" as a substring (e.g., --traceroute-foo). Since --traceroute doesn't take an argument, optparse_state.optlongname will be an exact match.

            } else if (strcmp(optparse_state.optlongname, "traceroute") == 0) {

Comment on lines 1867 to 1864
if (traceroute_flag) {
int ttl_set = h->trace_ttl;
if (ttl_set > 30) ttl_set = 30;
if (socket4 >= 0) {
if (setsockopt(socket4, IPPROTO_IP, IP_TTL, &ttl_set, sizeof(ttl_set)))
perror("setsockopt IP_TTL");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

A couple of points on this section:

  • Efficiency: Calling setsockopt() for every packet sent is a system call and can be inefficient. A more performant approach is to use sendmsg() with ancillary data (cmsg) to set the TTL on a per-packet basis. This would involve modifying send_ping() and socket_sendto_ping_ipv4().
  • IPv6 Support: As noted in the PR description, this is IPv4-only. For completeness, IPv6 support would require adding similar logic for socket6 using setsockopt with IPPROTO_IPV6 and IPV6_UNICAST_HOPS.

@coveralls
Copy link

coveralls commented Dec 7, 2025

Coverage Status

coverage: 83.788% (-2.9%) from 86.652%
when pulling 799a495 on gsnw:issue/62-dev
into abc8c09 on schweikert:develop.

@gsnw-sebast gsnw-sebast force-pushed the issue/62-dev branch 3 times, most recently from cff90ac to 7cd41ff Compare December 10, 2025 17:05
Copy link
Collaborator

@auerswal auerswal left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, @gsnw-sebast!
At least on Linux, receiving ICMP error messages requires the use of raw sockets. Please add checks that fping opened raw sockets when using --traceroute.
I have not yet looked at all code in detail, this was a first glance.

@gsnw-sebast gsnw-sebast force-pushed the issue/62-dev branch 3 times, most recently from 5bbc365 to 5e5efb1 Compare December 19, 2025 07:54
@gsnw-sebast
Copy link
Collaborator Author

Checklist with options that allow and tested

Option Test Supported
--ipv4 (-4)
--ipv6 (-6)
--alive (-a)
--addr (-A)
--size (-b)
--backoff (-B)
--count (-c) Yes No
--vcount (-C) Yes No
--rdns (-d)
--timestamp (-D)
--elapsed (-e)
--file (-f)
--generate (-g)
--ttl (-H) Yes Yes (1-30)
--interval (-i)
--iface (-I)
--json (-j)
--icmp-timestamp
--fwmark (-k)
--loop (-l) Yes No
--all (-m)
--dontfrag (-M)
--name (-n)
--netdata (-N)
--outage (-o)
--tos (-O) Yes Yes
--period (-p)
--quiet (-q) Yes No
--squiet (-Q)
--retry (-r)
--random (-R)
--stats (-s)
--src (-S)
--timeout (-t)
(-T)
--unreach (-u)
--reachable (-r)
--fast-reachable (-X)
--check-source
--print-tos Yes No
--print-ttl Yes No
--seqmap-timeout
(-z)

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.

RFE: option for "ftraceroute" functionality

3 participants