sb-bsd-sockets:get-host-by-name gives NIL with only loopback active

Bug #766159 reported by Ph. Marek
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Confirmed
Low
Unassigned

Bug Description

I cannot readily start SWANK while being on the train, because the defined TCP
port isn't used.

Investigating gives this:
sb-bsd-sockets:get-host-by-name returns NIL if only the loopback interface
(lo, 127.0.0.1) is active.

As soon as I give eth0 an ipv4 address (no matter which one, even with link
down) it works again.

SBCL 1.0.47.0.debian
Linux 2.6.38-2-amd64 #1 SMP Thu Apr 7 04:28:07 UTC 2011 x86_64 GNU/Linux

Here's a transcript:

(defparameter *l* "127.0.0.1")

(defun resolve (n)
  (car (sb-bsd-sockets:host-ent-addresses
         (sb-bsd-sockets:get-host-by-name n))))

(let ((s (make-instance ' sb-bsd-sockets:inet-socket
                        :type :stream
                        :protocol :tcp)))
  (sb-bsd-sockets:socket-bind s
                              (resolve *l*) 8002) ; EINVAL without ip on eth0
  (print s))

;;; result:

(let ((s (make-instance ' sb-bsd-sockets:inet-socket
                        :type :stream
                        :protocol :tcp)))
  (sb-bsd-sockets:socket-bind s
                              (resolve *l*) 8002) ; EINVAL without ip on eth0
  (print s))
  0: (RESOLVE "127.0.0.1")
    1: (SB-BSD-SOCKETS:GET-HOST-BY-NAME "127.0.0.1")
    1: SB-BSD-SOCKETS:GET-HOST-BY-NAME returned
         #<SB-BSD-SOCKETS:HOST-ENT {1002BF2CC1}>
    1: (SB-BSD-SOCKETS:HOST-ENT-ADDRESSES
        #<SB-BSD-SOCKETS:HOST-ENT {1002BF2CC1}>)
    1: SB-BSD-SOCKETS:HOST-ENT-ADDRESSES returned NIL

#<SB-BSD-SOCKETS:INET-SOCKET 0.0.0.0:33173, fd: 18 {1003EF7101}> #<SB-BSD-SOCKETS:INET-SOCKET 0.0.0.0:33173, fd: 18 {1003EF7101}>

;; when ok:
  0: (RESOLVE "127.0.0.1")
    1: (SB-BSD-SOCKETS:GET-HOST-BY-NAME "127.0.0.1")
      2: (SB-BSD-SOCKETS:HOST-ENT-ADDRESSES
          #<SB-BSD-SOCKETS:HOST-ENT {100421CCA1}>)
      2: SB-BSD-SOCKETS:HOST-ENT-ADDRESSES returned NIL
      2: (SB-BSD-SOCKETS:HOST-ENT-ADDRESSES
          #<SB-BSD-SOCKETS:HOST-ENT {100421CCA1}>)
      2: SB-BSD-SOCKETS:HOST-ENT-ADDRESSES returned (#(127 0 0 1))
      2: (SB-BSD-SOCKETS:HOST-ENT-ADDRESSES
          #<SB-BSD-SOCKETS:HOST-ENT {100421CCA1}>)
      2: SB-BSD-SOCKETS:HOST-ENT-ADDRESSES returned (#(127 0 0 1))
    1: SB-BSD-SOCKETS:GET-HOST-BY-NAME returned
         #<SB-BSD-SOCKETS:HOST-ENT {100421CCA1}>
    1: (SB-BSD-SOCKETS:HOST-ENT-ADDRESSES
        #<SB-BSD-SOCKETS:HOST-ENT {100421CCA1}>)
    1: SB-BSD-SOCKETS:HOST-ENT-ADDRESSES returned (#(127 0 0 1))
  0: RESOLVE returned #(127 0 0 1)

#<SB-BSD-SOCKETS:INET-SOCKET 127.0.0.1:8002, fd: 19 {1004219341}> #<SB-BSD-SOCKETS:INET-SOCKET 127.0.0.1:8002, fd: 19 {1004219341}>

Revision history for this message
Ph. Marek (ph-marek) wrote :

It's not a DNS problem; 1) the eth0 link isn't necessary; 2) 127.0.0.1 doesn't need /etc/hosts; 3) the name of the machine would return 127.0.1.1 via /etc/hosts.

Revision history for this message
Ph. Marek (ph-marek) wrote :

I could argue that bind-socket is wrong; for NIL 4005 it should bind to port 4005 and not to some random one.

Revision history for this message
Ph. Marek (ph-marek) wrote :

fe[nl]ix commented that network-manager might rewrite /etc/hosts; I cannot confirm this yet.

BTW, gethostbyname("127.0.0.1") should always work, right?

Revision history for this message
Ph. Marek (ph-marek) wrote :

perl doesn't have this problem; I just checked. sbcl returns NIL for the host name, while perl works just fine:

strace perl -e 'use IO::Socket::INET; $x = IO::Socket::INET->new(Listen=>5,LocalAddr=>"127.0.0.1",LocalPort=>3332)'
...
bind(3, {sa_family=AF_INET, sin_port=htons(3332), sin_addr=inet_addr("127.0.0.1")}, 16) = 0

Changed in sbcl:
importance: Undecided → Low
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.