bugDotGNU Portable.NET - Bugs: bug #12168, Cannot retreive the local hostname

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #12168: Cannot retreive the local hostname

Submitter:  Kirill Kononenko <krokas>
Submitted:  Sun 27 Feb 2005 06:41:10 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Closed

Jump to the original submission

Tue 08 Mar 2005 08:06:22 PM UTC, comment #8: 

Alright, I got that this is a not a pnet bug at all. Could you tell me how to configure my system, so that I can use the 127.0.0.1 ip and use my computer as a server? Should I install some package? Are the following steps enough?
http://www.togaware.com/linux/survivor/IP_Forwarding.shtml

Anonymous
Sun 06 Mar 2005 10:07:22 PM UTC, comment #7: 

Ah, now I understand what you're trying to do.

It's not a bug in pnet, but a configuration error by you.

"The domain name queries carried out by gethostbyname() and gethostbyaddr() use a combination of any or all of the name server named(8), a broken out line from /etc/hosts, and the Network Information Service (NIS or YP), depending upon the contents of the order line in /etc/host.conf." - gethostbyname(3), man page.

You see, even if the hostname is set to a certain value, you either need a name server to resolve the name to an address, or if you have defined the name in /etc/hosts to be able to actually resolve the name. It can't magically be resolved unless something specifies the address for the name.

Example:
ptah@bar:~$ cat /etc/hosts
127.0.0.1               localhost.localdomain   localhost
ptah@bar:~$ ping bar
ping: unkown host bar
root@bar:/home/ptah# echo 192.168.0.26 localhost.localdomain bar >> /etc/hosts
ptah@bar:~$ ping bar
PING localhost.localdomain (192.168.0.26) 56(84) bytes of data.
64 bytes from localhost.localdomain (192.168.0.26): icmp_seq=1 ttl=64 time=0.443 ms


Don't think I can be clearer than that...
This bug is bogus, closed Sunday, 6 March.

Carl-Adam Brengesjo <ptah>
Group Member
Sun 06 Mar 2005 07:43:29 PM UTC, comment #6: 

Command 'gethostname' is not defined in my system. However, there is a similar 'hostname'. The problem is solved with one of following strings - 'hostname 127.0.0.1' or 'hostname localhost'. Look below:
---->
127:~/Desktop/bug# hostname debian
127:~/Desktop/bug# ilrun server.out
Uncaught exception: System.Net.Sockets.SocketException: An error occured while accessing the socket
        at System.Net.Dns.GetHostByName(String) in ./Net/Dns.cs:238
        at System.Net.Dns.Resolve(String) in ./Net/Dns.cs:252
        at Server.Main()

127:~/Desktop/bug# hostname localhost
127:~/Desktop/bug# ilrun server.out
127.0.0.1
 Current ip address is 127.0.0.1
Connection in progress.
---->

Although after that, my client doesn't want to connect. But now it seems to be a problem with my Debian GNU/Linux system configuration and not a pnet one.


Kirill Kononenko <krokas>
Sun 06 Mar 2005 01:18:04 PM UTC, comment #5: 

Works for me with current cvs on suse 9.2

The man pages say:

 For  many  Linux  kernel / libc combinations gethostname will return an
 error instead of returning a truncated hostname.

Is this your problem ?

Klaus Treichel <ktreichel>
Group administrator
Sat 05 Mar 2005 03:28:16 PM UTC, comment #4: 

debian:/# gethostname
bash: gethostname: command not found
debian:/# uname -n
debian
debian:/#

Kirill Kononenko <krokas>
Sat 05 Mar 2005 05:57:39 AM UTC, comment #3: 

The return value from Dns.GetHostName() shouldn't be NULL, a SocketException should be thrown. However, that's not the reason why it fails.

Dns.GetHostName() uses an internal call to fetch the hostname,  and these C functions return null in two cases:
1) gethostname isn't defined on your system.
2) gethostname failed. See the man page gethostname(3).

I assume your system has a working glibc with gethostname defined... so is there an error when calling gethostname?

What does "uname -n" tells you?

Carl-Adam Brengesjo <ptah>
Group Member
Fri 04 Mar 2005 03:39:31 AM UTC, comment #2: 

I know another user with the problem. I added here a file with all my client-server source code.

Kirill Kononenko <krokas>
Thu 03 Mar 2005 08:54:54 AM UTC, comment #1: 

Not able to duplicate here.  Getting the following when ran as luser or root:

[newl@rogue Downloads]$ ilrun server
203.59.xxx.xxx
 Current ip address is 203.59.xxx.xxx
Uncaught exception: System.Net.Sockets.SocketException: Protocol not supported
        at System.Net.Sockets.Socket..ctor(AddressFamily, SocketType, ProtocolType) in ./Net/Sockets/Socket.cs:73
        at Server.Main()

Which would be correct based upon the current source System/Net/Sockets/Socket.cs lines 61 and 71, udp streams appear to currently not be supported at this point in time.

Deryk Robosson <drobosson>
Group Member
Sun 27 Feb 2005 06:41:10 PM UTC, original submission:  

The following code:

      IPAddress ipAddress =
      Dns.Resolve(Dns.GetHostName()).AddressList[0];
 
    Console.Write(" Current ip address is " + ipAddress + "\n");
 
    IPEndPoint ipEndpoint =
      new IPEndPoint(ipAddress, 58963);
 
 
 
 
    Socket listenSocket =
      new Socket(AddressFamily.InterNetwork,
                 SocketType.Stream,
 
                 ProtocolType.Tcp);
 
    listenSocket.Bind(ipEndpoint);
 
 
 
    listenSocket.Listen(1);

Report in GNU/Linux the following:

:~$ ilrun a.out

Uncaught exception: System.ArgumentNullException: Argument cannot be null
Parameter name: hostname
at System.Net.Dns.GetHostByName(String) in ./Net/Dns.cs:229
at System.Net.Dns.Resolve(String) in ./Net/Dns.cs:252
at test.Main(String[])

On Windows XP, 98 everything is alright.

Kirill Kononenko <krokas>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #2672:  client.cs added by krokas (15KiB - text/plain - The images need to run this game are in fullgame.zip)
file #2671:  server.cs added by krokas (5KiB - text/plain)
file #2670:  fullgame.zip added by krokas (10KiB - application/x-zip-compressed - A complete version of all the source code.)
file #2658:  fullgame.zip added by krokas (11KiB - application/x-zip-compressed - A complete version of all the source code.)
file #2652:  client.cs added by krokas (15KiB - text/plain)
file #2651:  server.cs added by None (5KiB - text/plain - UDP->TCP)
file #2623:  server.cs added by krokas (5KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

 

Follow 10 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2005-03-06 ptah StatusNone Invalid
    Open/ClosedOpen Closed
2005-03-05 ptah SummaryBug in pnet Cannot retreive the local hostname
2005-03-04 krokas Attached File- Added client.cs, #2279
2005-03-04 krokas Attached File- Added server.cs, #2278
2005-03-04 krokas Attached File- Added fullgame.zip, #2277
2005-03-04 krokas Attached File- Added fullgame.zip, #2267
2005-03-03 krokas Attached File- Added client.cs, #2264
2005-03-03 None Attached File- Added server.cs, #2263
2005-02-27 krokas Attached File- Added server.cs, #2245

Back to the top

Powered by Savane 3.13-02a9.
Corresponding source code