LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-01-2005, 11:54 AM   #1
devito
Newbie
 
Registered: Aug 2005
Location: Portugal
Distribution: SuSE
Posts: 14

Rep: Reputation: 0
Returning localhost IP addr


Hey,

Does anyone know how to / if exists:

1) a shell command that simply replies my IP address? I can do 'ifconfig' and check it, but is there any other way to see the ip in which i'm connected?

2) Or a function in C, that returns my IP address?

Thanks
 
Old 10-01-2005, 12:41 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Actually, there are several - completely different - questions here. The answer to most of them is "Yes".

I think you're asking:
1. Are there 'C' functions or shell commands where I can find out all of my network interfaces (eth0, eth1, etc) and all of the (possibly multiple) IP addresses associated with each of these network interfaces?

But perhaps you're asking:
2. If I've established a TCP/IP connection with some other host, are there 'C' functions or shell commands where I can find out which (of possibly multiple) local IP addresses I'm actually communicating over (ie. "what is my endpoint?")?

You're probably not asking:
3. What is my localhost IP address?
A: "localhost" generally == "loopback" == 127.0.0.1.

In general, "ifconfig", "netstat -in", "netstat -a" and "lsof" are probably going to be the most useful shell commands.

As far as 'C', you can use "gethostbyname()" or look inside the internals of any active "struct sockaddr". There are lots and lots of other options as well, depending on your specific requirements.

'Hope that helps .. PSM

Last edited by paulsm4; 10-01-2005 at 12:43 PM.
 
Old 10-01-2005, 01:07 PM   #3
devito
Newbie
 
Registered: Aug 2005
Location: Portugal
Distribution: SuSE
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks, it did help =)
 
  


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
Obtain IP addr. from MAC addr? Ryand833 Linux - Wireless Networking 3 06-30-2005 01:59 PM
Message from syslogd@localhost localhost kernel: Disabling IRQ #21 ylts Linux - Hardware 0 02-26-2005 08:01 AM
get the IP-addr out from an int32_t value Ephracis Programming 3 02-09-2005 09:03 AM
Help, IP Addr. dolvmin Linux - Networking 3 01-23-2004 08:58 PM
ip addr but cant ping montgomeryi Linux - Networking 0 08-24-2003 11:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:06 PM.

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
Open Source Consulting | Domain Registration