niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Unix internals
finding the IP address of the local machine.
Post new topic   Reply to topic Page 2 of 2 [21 Posts] View previous topic :: View next topic
Goto page:  Previous  1, 2
Author Message
Nils O. Selåsdal
*nix forums Guru Wannabe


Joined: 09 Mar 2005
Posts: 199

PostPosted: Thu Oct 13, 2005 12:50 pm    Post subject: Re: finding the IP address of the local machine. Reply with quote

David Schwartz wrote:
Quote:
kironv@gmail.com> wrote in message
news:1129122488.343468.236090@g49g2000cwa.googlegroups.com...


You need this info for protocols like SDP ( for ex: invite in SIP )
where you want to send the IP address of your machine and the other
machine will connect to it...


Why wouldn't it just connect to the machine it received the information
from using the address that was used to send the information to it?
What if it should connect to another machine ?


A common scenario is when the SIP signalling travels through
proxy servers, but you want audio to go directly between the peers.

Another scenario is when all call control processing is done one a
call server, and the media paths to be opened are between two media
gateways.
Back to top
Michael Wojcik
*nix forums Guru


Joined: 10 Apr 2005
Posts: 336

PostPosted: Thu Oct 13, 2005 9:02 pm    Post subject: Re: finding the IP address of the local machine. Reply with quote

In article <dijm5i$mc5$1@nntp.webmaster.com>, "David Schwartz" <davids@webmaster.com> writes:
Quote:

kironv@gmail.com> wrote in message
news:1129122488.343468.236090@g49g2000cwa.googlegroups.com...

You need this info for protocols like SDP ( for ex: invite in SIP )
where you want to send the IP address of your machine and the other
machine will connect to it...

Why wouldn't it just connect to the machine it received the information
from using the address that was used to send the information to it?

Because if NAT is being used, the source address of the packets the
host receives will not be an actual IP address of the peer. Replies
back to that address and source port will work, because the NAT
system will route them; but arbitrary SYNs to that address probably
will not, because the NAT system won't have any reason to direct them
to the (interface on the) system that originated the first
conversation.

Some NAT systems use heuristics to route incoming SYNs - for example,
if machine A is behind a NAT and it opens a conversation to machine
B, and no other system behind the NAT opens a conversation to machine
B, and machine B sends a SYN to the NAT address within a certain
time, some NATs will automatically route it to machine A. I had a
3Com ISDN modem with NAT that could be configured to do that. But
it's not foolproof, universally implemented, or always desirable.

--
Michael Wojcik michael.wojcik@microfocus.com

Please enjoy the stereo action fully that will surprise you. -- Pizzicato Five
Back to top
David Schwartz
*nix forums Guru


Joined: 26 Feb 2005
Posts: 914

PostPosted: Thu Oct 13, 2005 9:48 pm    Post subject: Re: finding the IP address of the local machine. Reply with quote

"Michael Wojcik" <mwojcik@newsguy.com> wrote in message
news:dimi0q0200c@news4.newsguy.com...

Quote:
In article <dijm5i$mc5$1@nntp.webmaster.com>, "David Schwartz"
davids@webmaster.com> writes:

kironv@gmail.com> wrote in message
news:1129122488.343468.236090@g49g2000cwa.googlegroups.com...

You need this info for protocols like SDP ( for ex: invite in SIP )
where you want to send the IP address of your machine and the other
machine will connect to it...

Why wouldn't it just connect to the machine it received the
information
from using the address that was used to send the information to it?

Because if NAT is being used, the source address of the packets the
host receives will not be an actual IP address of the peer.

Right, but it will be a more useful address than the actual IP address
of the peer.

Quote:
Replies
back to that address and source port will work, because the NAT
system will route them; but arbitrary SYNs to that address probably
will not, because the NAT system won't have any reason to direct them
to the (interface on the) system that originated the first
conversation.

If the host is behind NAT, SYNs to the real IP address *definitely*
won't work. So this argument actually supports my position that you should
use the address you got the packets from, not the address the other machine
sent them from.

Quote:
Some NAT systems use heuristics to route incoming SYNs - for example,
if machine A is behind a NAT and it opens a conversation to machine
B, and no other system behind the NAT opens a conversation to machine
B, and machine B sends a SYN to the NAT address within a certain
time, some NATs will automatically route it to machine A. I had a
3Com ISDN modem with NAT that could be configured to do that. But
it's not foolproof, universally implemented, or always desirable.

I agree. However, this still doesn't argue against my point that you
should want an address for the peer that is globally unique and routable
over the network, and that will be the source address of the data you
received, not the address the other end sent them from.

DS
Back to top
maxim.yegorushkin@gmail.c
*nix forums Guru Wannabe


Joined: 27 Jul 2005
Posts: 182

PostPosted: Fri Oct 14, 2005 6:51 am    Post subject: Re: finding the IP address of the local machine. Reply with quote

Michael Wojcik wrote:
Quote:
In article <dijm5i$mc5$1@nntp.webmaster.com>, "David Schwartz" <davids@webmaster.com> writes:

kironv@gmail.com> wrote in message
news:1129122488.343468.236090@g49g2000cwa.googlegroups.com...

You need this info for protocols like SDP ( for ex: invite in SIP )
where you want to send the IP address of your machine and the other
machine will connect to it...

Why wouldn't it just connect to the machine it received the information
from using the address that was used to send the information to it?

Because if NAT is being used, the source address of the packets the
host receives will not be an actual IP address of the peer. Replies
back to that address and source port will work, because the NAT
system will route them; but arbitrary SYNs to that address probably
will not, because the NAT system won't have any reason to direct them
to the (interface on the) system that originated the first
conversation.

I don't see how these SYN/NAT concerns apply here. The IP addresses
stated in SDP are used for video/audio streams which are delivered via
RTP, which is a UDP based protocol. For traversing NATs with UDP they
use techniques like UDP hole punching. A good paper on the subject is
referred here http://en.wikipedia.org/wiki/UDP_hole_punching.
Back to top
Michael Wojcik
*nix forums Guru


Joined: 10 Apr 2005
Posts: 336

PostPosted: Fri Oct 14, 2005 4:13 pm    Post subject: Re: finding the IP address of the local machine. Reply with quote

In article <dimkmc$o8a$1@nntp.webmaster.com>, "David Schwartz" <davids@webmaster.com> writes:
Quote:
"Michael Wojcik" <mwojcik@newsguy.com> wrote in message
news:dimi0q0200c@news4.newsguy.com...
In article <dijm5i$mc5$1@nntp.webmaster.com>, "David Schwartz"
davids@webmaster.com> writes:
kironv@gmail.com> wrote in message
news:1129122488.343468.236090@g49g2000cwa.googlegroups.com...

You need this info for protocols like SDP ( for ex: invite in SIP )
where you want to send the IP address of your machine and the other
machine will connect to it...

Why wouldn't it just connect to the machine it received the
information
from using the address that was used to send the information to it?

Because if NAT is being used, the source address of the packets the
host receives will not be an actual IP address of the peer.
[...]

I agree. However, this still doesn't argue against my point that you
should want an address for the peer that is globally unique and routable
over the network, and that will be the source address of the data you
received, not the address the other end sent them from.

Ah, I see your point. I thought you were asking, in effect, "why
wouldn't the source address always work (as a callback address)?",
not pointing out that the peer's actual (possibly unreachable) IP
address was even less useful.

In reality, neither may be useful, but (as in the case of the 3Com
ISDN modem I mentioned) there are some situations where the source
address might be more useful than the peer's actual address. I
agree with you there.

--
Michael Wojcik michael.wojcik@microfocus.com
Back to top
Pascal Bourguignon
*nix forums addict


Joined: 08 Mar 2005
Posts: 62

PostPosted: Wed Jun 28, 2006 1:51 pm    Post subject: Re: finding the IP address of the local machine. Reply with quote

"vineeth" <nvineeth@gmail.com> writes:

Quote:
hello,
Can anyone please tell me the way to find out the IP address of the
machine.
currently i am using gethostent(), but this always returns 127.0.0.1
pls share your ideas.

Yes. That's because computers don't get IP addresses on an IP network.

Only interfaces get IP addresses.

So you must first get the list of interfaces to this computer, then
the list of IP adresses to each interface.

Try:
ifconfig(1) ifconfig -a

On linux:
ip(Cool ip addr show
netdevice(7)

--
__Pascal Bourguignon__ http://www.informatimago.com/

CAUTION: The mass of this product contains the energy equivalent of
85 million tons of TNT per net ounce of weight.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 2 of 2 [21 Posts] Goto page:  Previous  1, 2
View previous topic :: View next topic
The time now is Tue Dec 02, 2008 5:45 am | All times are GMT
navigation Forum index » Programming » Unix internals
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts spoofed local email addresses watkykjy Postfix 0 Thu Nov 20, 2008 8:49 am
No new posts Postfix ldap and Rewriting sender email address endfx Postfix 2 Thu Apr 17, 2008 9:34 pm
No new posts recipient address restriction 3dd13 Postfix 0 Wed Mar 26, 2008 1:46 pm
No new posts Postfix sending problem for local domain remote email monkey_magix Postfix 0 Mon Sep 10, 2007 10:17 am
No new posts Bug#379087: ITP: libcomplearn -- data-compression based i... Rudi Cilibrasi devel 0 Fri Jul 21, 2006 7:40 am

Xbox Mod Chip | Internet Advertising | Auto Loans | Loans | Best Credit Cards
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3235s ][ Queries: 16 (0.2299s) ][ GZIP on - Debug on ]