From: Andrew MacIntyre Date: Mon, 12 Jul 2004 12:10:30 +0000 (+0000) Subject: FreeBSD's services file contains an additional echo service entry, with X-Git-Tag: v2.4a2~297 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18bf43c4a4ca170f175207e3875788709b296248;p=python FreeBSD's services file contains an additional echo service entry, with a non-standard protocol and on a lower port than the tcp/udp entries, which breaks the assumption that there will only be one service by a given name on a given port when no protocol is specified. Previous versions of this code have had other problems as a result of different service definitions amongst common platforms. As this platform has an extra, unexpected, service entry, I've special cased the platform rather than re-order the list of services checked to highlight the pitfall. --- diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 180d965b09..adeca569e4 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -289,7 +289,13 @@ class GeneralModuleTests(unittest.TestCase): # Find one service that exists, then check all the related interfaces. # I've ordered this by protocols that have both a tcp and udp # protocol, at least for modern Linuxes. - for service in ('echo', 'daytime', 'domain'): + if sys.platform in ('freebsd4', 'freebsd5'): + # avoid the 'echo' service on this platform, as there is an + # assumption breaking non-standard port/protocol entry + services = ('daytime', 'qotd', 'domain') + else: + services = ('echo', 'daytime', 'domain') + for service in services: try: port = socket.getservbyname(service, 'tcp') break