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

Submitted by:  Kirill Kononenko <krokas>
Submitted on:  Sun 27 Feb 2005 06:41:10 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Invalid
Privacy: PublicAssigned to: None
Open/Closed: Closed

(Jump to the original submission 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>
Project 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>
Project 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>
Project 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>
Project 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>

 

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

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 10 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Sun 06 Mar 2005 10:07:22 PM UTCptahStatusNone=>Invalid
  Open/ClosedOpen=>Closed
Sat 05 Mar 2005 05:57:39 AM UTCptahSummaryBug in pnet=>Cannot retreive the local hostname
Fri 04 Mar 2005 09:05:32 PM UTCkrokasAttached File-=>Added client.cs, #2279
Fri 04 Mar 2005 09:03:49 PM UTCkrokasAttached File-=>Added server.cs, #2278
Fri 04 Mar 2005 08:57:55 PM UTCkrokasAttached File-=>Added fullgame.zip, #2277
Fri 04 Mar 2005 03:39:31 AM UTCkrokasAttached File-=>Added fullgame.zip, #2267
Thu 03 Mar 2005 03:02:12 PM UTCkrokasAttached File-=>Added client.cs, #2264
Thu 03 Mar 2005 02:58:19 PM UTCNoneAttached File-=>Added server.cs, #2263
Sun 27 Feb 2005 06:41:10 PM UTCkrokasAttached File-=>Added server.cs, #2245

Back to the top


Powered by Savane 3.1-cleanup1