LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-11-2006, 02:45 PM   #1
swodniw
Member
 
Registered: Jan 2006
Posts: 35

Rep: Reputation: 16
loopback ip


Hi I am new to linux programming, which doesn't help because currently I'm trying to port my app which is using sockets.

In windows the loopback ip is 127.0.0.1 and doing a netstat -r on my linux box gives me 255.0.0.0 as the loopback but i can never bind or connect to this ip. If i use the following I can bind
Code:
sock.sin_addr.s_addr = INADDR_ANY
but the ip this is using is 0.0.0.0
In the client if I try and connect to this zero ip it fails.

is 255.0.0.0 the correct ip i want to be using for a loopback and therefore something else wrong?
 
Old 01-11-2006, 02:58 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
It doesn't sound correct to me. The loopback should be 127.0.0.1
 
Old 01-11-2006, 04:04 PM   #3
swodniw
Member
 
Registered: Jan 2006
Posts: 35

Original Poster
Rep: Reputation: 16
No joy using that i just get "Cannot assign requested address".
Ive even tried doing it this way but gethostbyname fails returning 0;

Code:
	sockaddr_in server_info;
	hostent* host = 0;
	char hostname[100];
	memset(hostname,0,sizeof(hostname));
	
	//get the host name of the machine
	//if(  gethostname( hostname, sizeof(hostname) ) == -1 )  
	{
		//put error message...
	}
	else
	{	
		//lets see the damn name
		std::cout <<hostname <<std::endl;
		//convert the hostname into a hostent struct
		if( ( host = gethostbyname( hostname ) ) == 0 )
                {
			//-----------this always fails here
		}
	}...........

Last edited by swodniw; 01-11-2006 at 04:08 PM.
 
Old 01-11-2006, 04:14 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
I think your /etc/hosts file could have issues.

What does your /etc/hosts look like?

Last edited by jim mcnamara; 01-11-2006 at 04:17 PM.
 
Old 01-11-2006, 06:14 PM   #5
swodniw
Member
 
Registered: Jan 2006
Posts: 35

Original Poster
Rep: Reputation: 16
This shows my the local as 127.0.0.1 so I really have no idea what is wrong. Any help on this would be appreciated. Thanks

Code:
$
# hosts         This file describes a number of hostname-to-address$
#               mappings for the TCP/IP subsystem.  It is mostly$
#               used at boot time, when no name servers are running.$
#               On small systems, this file can be used instead of a$
#               "named" name server.$
# Syntax:$
#    $
# IP-Address  Full-Qualified-Hostname  Short-Hostname$
#$
$
127.0.0.1       localhost$
$
# special IPv6 addresses$
::1             localhost ipv6-localhost ipv6-loopback$
$
fe00::0         ipv6-localnet$
$
ff00::0         ipv6-mcastprefix$
ff02::1         ipv6-allnodes$
ff02::2         ipv6-allrouters$
ff02::3         ipv6-allhosts$
127.0.0.2       linux.site home$
this is from netstat -r
Code:
link-local      *               255.255.0.0     U         0 0          0 eth1
loopback        *               255.0.0.0       U         0 0          0 lo
 
Old 01-11-2006, 06:34 PM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I think the third column is the network mask not the IP address. Your IP address has been resolved to the name loopback. try

Code:
netstat -r --numeric-hosts
graeme.
 
Old 01-11-2006, 08:01 PM   #7
swodniw
Member
 
Registered: Jan 2006
Posts: 35

Original Poster
Rep: Reputation: 16
Code:
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
82.42.120.0     0.0.0.0         255.255.248.0   U         0 0          0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth1
127.0.0.0       0.0.0.0         255.0.0.0       U         0 0          0 lo
0.0.0.0         82.42.120.1     0.0.0.0         UG        0 0          0 eth1
My current ip is similar to 82.42.120.* but neither are my actual ip. Does this have something to do with it?
 
Old 01-12-2006, 01:41 AM   #8
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by swodniw
Code:
sock.sin_addr.s_addr = INADDR_ANY
but the ip this is using is 0.0.0.0
In the client if I try and connect to this zero ip it fails.
Using INADDR_ANY is correct. It implies that the server listens to requests on any network interface.
To connect to it, you can use e.g.
Code:
telnet localhost portno
telnet 127.0.0.1 portno
telnet hostname portno
telnet 82.42.120.x portno
Instead of INADDR_ANY, you can specify an address (as long int), in which case the server only listens to request on the interface with the specified address.

I'm not sure why you have a problem. Your result of netstat -r is the same for the loopback device as on my system.
What does ifconfig give you? There should be a lo interface with address 127.0.0.1
What is the result of a ping localhost?
 
Old 01-14-2006, 07:20 AM   #9
swodniw
Member
 
Registered: Jan 2006
Posts: 35

Original Poster
Rep: Reputation: 16
Thanks for the replies on this matter, but the error was due to a coding mistake when trying to port from windows to linux.

Can anybody tell me if there is a free remote cvs service, so that i can log files out from within windows and linux with ease.

I know of sourceforge, but the project doesn't meet the required licence. I want the project executables to be freely available to the general public but not to companies and neither to have the source. I don't even know what licence this should be!

Thanks again.

Last edited by swodniw; 01-14-2006 at 07:39 AM.
 
Old 01-16-2006, 02:08 AM   #10
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
I'm not that familiar with CVS but you should be able to setup CVS on a Linux box and access it from both the Linux machine as well as from the Windows machine.
I'm quite sure that my RH8 box came with CVS installed, not sure about my Slack box.
 
Old 01-16-2006, 01:52 PM   #11
swodniw
Member
 
Registered: Jan 2006
Posts: 35

Original Poster
Rep: Reputation: 16
Thanks for the reply Wim Sturkenboom.
The problem is there is only one box, I use a dual boot machine, thus meaning I could set it up on linux yet not then access it from windows. ;(
 
Old 01-16-2006, 02:27 PM   #12
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I've not tried CVS but on my dual boot system I have a shared disk (Fat 32) which both Windows and Linux can access. YOu might want to try that and put the repository on the shared drive.

Another thought is can you put a repository on a removable drive - such as a flash drive (thumb drive)?

graeme,

(all questions no answers this time!)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
server loopback? lilmul123 Linux - Networking 2 08-16-2005 07:32 PM
How to get back my loopback? JazzMastaJim Suse/Novell 6 07-30-2005 01:46 PM
Loopback won't come up Paul_assheton Linux - Networking 8 05-20-2003 09:31 AM
debian on loopback? kamdh Linux - Distributions 0 03-17-2003 09:47 PM
loopback problems Ismark Linux - Newbie 1 01-04-2002 07:05 PM


All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration