[問題] gethostbyname得到不正確的ip

看板Linux作者 (石斛蘭)時間14年前 (2009/11/30 00:38), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ [本文轉錄自 LinuxDev 看板] 作者: dendrobium (石斛蘭) 看板: LinuxDev 標題: [問題] gethostbyname得到不正確的ip 時間: Mon Nov 30 00:34:43 2009 我有兩台機器 分別是在 60.198.35.85 140.117.37.129 兩台分別利用gethostbyname查ip卻得到不一樣的結果 部份程式碼如下 char fromhost[] = "60-198-35-85.dynamic.tfn.ent.tw"; char user_ip[512]; if (he = gethostbyname(fromhost)) strcpy(user_ip, inet_ntoa(*(struct in_addr *) he->h_addr_list[0])); printf("%s\n",user_ip); 其中 60.198.35.85主機得到的是正確的, 也就是自己的ip 而 140.117.37.129主機卻得到 220.128.96.184 這個不正確的ip ( 220.128.96.184是 hinet的ip 似乎是www.twbbs.org) 我在網路上有查到 通常會透過/etc/resolv.conf 裡面的nameserver 查詢 以下是 140.117.37.129主機的/etc/resolv.conf search twbbs.org #=> 主機的domain name 是 xxxx.twbbs.org nameserver 140.117.11.1 #=> nsysu的 nameserver 會不會是search twbbs.org 這行設錯了呢? 但是我把他註銷掉後用 service network restart還是得到一樣的結果 請問問題是出在哪呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.198.35.85 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.198.35.85
文章代碼(AID): #1B4gDtG1 (Linux)