Opened 12 years ago

Closed 8 years ago

Last modified 8 years ago

#12034 closed Bug Report - General (fixed)

Ping incorrectly sets the TTL rather than the timeout - setting an http proxy fails

Reported by: Greg Brackley <greg.brackley-mythtv-trac-2014@…> Owned by: Stuart Auchterlonie
Priority: minor Milestone: 29.1
Component: MythTV - General Version: Master Head
Severity: medium Keywords:
Cc: Ticket locked: no

Description

The function:

  bool ping(const QString &host, int timeout) file mythmiscutil.cpp line 220

has a timeout parameter, but in both the win32 and other code paths it is passed as a TTL parameter.

This means attempts to ping a host more than one hop away will fail. If I run the command manually it fails as I would expect:

# ping -t 1 -c 1 proxy.lucidsolutions.co.nz
PING proxy.lucidsolutions.co.nz (10.20.5.3) 56(84) bytes of data.
From gbe-12.orange.lucidsolutions.co.nz (10.20.12.1) icmp_seq=1 Time to live exceeded

--- proxy.lucidsolutions.co.nz ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 1ms

The function:

  void setHttpProxy(void), file mythmiscutil.cpp line 831

uses the ping function to check if the proxy is available. My proxy is on another network. When I run mythfilldatabase I get the error:

E  setHttpProxy() - cannot locate host proxy.lucidsolutions.co.nz
                        Please check HTTP_PROXY environment variable!

I am having this issue with 0.27. The code appears to be the same on master.

Fix

The non-WIN32 ping command is:

 QString cmd = QString("ping -t %1 -c 1 %2 >/dev/null 2>&1")
                  .arg(timeout).arg(host);

I think the '-t' option should be '-W'.

The WIN32 ping command is:

    QString cmd = QString("%systemroot%\\system32\\ping.exe -i %1 -n 1 %2>NUL")
                  .arg(timeout).arg(host);

I think it should use the '-w' switch instead of '-i' and convert the 1 second to 1000 milli-seconds.

I believe the current code will appear to work if the proxy is on the same network as the machine running the mythtv code. If the proxy is down, then the intended short timeout behaviour will not be observed.

https://github.com/MythTV/mythtv/blob/fixes/0.27/mythtv/libs/libmythbase/mythmiscutil.cpp https://github.com/MythTV/mythtv/blob/master/mythtv/libs/libmythbase/mythmiscutil.cpp

Change History (8)

comment:1 Changed 12 years ago by Greg Brackley <greg.brackley-mythtv-trac-2014@…>

FreeBSD seems to support the '-t' parameter.

CentOS 6 and Fedora

Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]
            [-p pattern] [-s packetsize] [-t ttl] [-I interface or address]
            [-M mtu discovery hint] [-S sndbuf]
            [ -T timestamp option ] [ -Q tos ] [hop1 ...] destination

Windows 7

Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name

Options:
    -t             Ping the specified host until stopped.
                   To see statistics and continue - type Control-Break;
                   To stop - type Control-C.
    -a             Resolve addresses to hostnames.
    -n count       Number of echo requests to send.
    -l size        Send buffer size.
    -f             Set Don't Fragment flag in packet (IPv4-only).
    -i TTL         Time To Live.
    -v TOS         Type Of Service (IPv4-only. This setting has been deprecated
                   and has no effect on the type of service field in the IP Header).
    -r count       Record route for count hops (IPv4-only).
    -s count       Timestamp for count hops (IPv4-only).
    -j host-list   Loose source route along host-list (IPv4-only).
    -k host-list   Strict source route along host-list (IPv4-only).
    -w timeout     Timeout in milliseconds to wait for each reply.
    -R             Use routing header to test reverse route also (IPv6-only).
    -S srcaddr     Source address to use.
    -4             Force using IPv4.
    -6             Force using IPv6.

FreeBSD 9

usage: ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize]
            [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]
            [-P policy] [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]
            [-W waittime] [-z tos] host
       ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]
            [-M mask | time] [-m ttl] [-P policy] [-p pattern] [-S src_addr]
            [-s packetsize] [-T ttl] [-t timeout] [-W waittime]
            [-z tos] mcast-group

comment:2 Changed 10 years ago by Karl Dietz <dekarl@…>

In 48ee1ab672587525c09981558f907f7f6808ffba/mythtv:

Error: Processor CommitTicketReference failed
GIT backend not available

comment:3 Changed 8 years ago by David Hampton <mythtv@…>

Added a patch at ​​https://github.com/MythTV/mythtv/pull/145 to compile in the correct timeout flag for the operating system.

comment:4 Changed 8 years ago by Stuart Auchterlonie

Milestone: unknown30.0
Owner: set to Stuart Auchterlonie
Status: newaccepted
Version: UnspecifiedMaster Head

comment:5 Changed 8 years ago by David Hampton <mythtv@…>

Resolution: fixed
Status: acceptedclosed

In e2d0c1693ddb2f7be9521eaa31c9cf212f64b08a/mythtv:

Error: Processor CommitTicketReference failed
GIT backend not available

comment:6 Changed 8 years ago by Stuart Auchterlonie <stuarta@…>

In e03bee0c7eb381f488d3d09c7d0bc66a663a820a/mythtv:

Error: Processor CommitTicketReference failed
GIT backend not available

comment:7 Changed 8 years ago by David Hampton <mythtv@…>

In afb2a83edd5e6f94572e5550bd9ae47dbc6834db/mythtv:

Error: Processor CommitTicketReference failed
GIT backend not available

comment:8 Changed 8 years ago by Stuart Auchterlonie

Milestone: 30.029.1
Note: See TracTickets for help on using tickets.