LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 12-11-2009, 04:12 PM   #1
microstarwww
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Rep: Reputation: 0
how to get network ip address?


I use getaddrinfo to get the ip address of the server, it works well on other 3 machines, but always get local address 127.0.0.1 on an 64 bit linux machine. Therefore, other remote clients can not connect to the socket server because the server binds local address l27.0.0.1.

I have also tried pass 0.0.0.0 to getaddrinfo, now the server bind on 0.0.0.0(all available interface). But now I can not print the correct network address of the server, as it is always 0.0.0.0 which is provided by getsockname.

I do not know how to get the network address of the server, rather than the local address. Can anyone help me out? Thanks a lot.
 
Old 12-11-2009, 04:28 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
This probably would get better attention and the right kind of attention in the programming forums.

Without having a look at the relevant pieces of code to determine what might be going wrong, it's really hard to say what the specific problem is or maybe.
 
Old 12-11-2009, 04:32 PM   #3
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Network address belongs to NIC or NIC, just type from root console:
ifconfig -a

And you will see.
 
Old 12-11-2009, 04:46 PM   #4
microstarwww
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for your reply,

To make things clear,

A linux machine may have multiple ip address, for example,

127.0.0.1 (local ip address)
198.12.1.12 (external address)

if there a c function like getaddrinfo(..) which can get the external address(198.12.1.12), rather than the local address(127.0.0.1)?
 
Old 12-11-2009, 04:52 PM   #5
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
ifconfig -a
 
Old 12-11-2009, 04:59 PM   #6
microstarwww
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by nimnull22 View Post
ifconfig -a

Yes, but I want to get the address by c program. Thanks.
 
Old 12-11-2009, 05:10 PM   #7
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
You can parse output with perl for example.

But may be someone else here gives you a better solution.
 
Old 12-14-2009, 04:07 PM   #8
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by microstarwww View Post
Yes, but I want to get the address by c program. Thanks.
To be honest I'd suggest posting how you're currently getting the ip address, hard to guess what you may or may not be doing correctly without seeing the code itself. Because it works on one particular subset of machines does not mean its portable or correct.
 
  


Reply

Tags
getaddrinfo



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
[SOLVED] dhcp-client get assigned a network address instead of a regular IP address kenneho Linux - Networking 3 11-27-2009 03:43 AM
Changing Network Address of Network Printer MTUser2007 Linux - Newbie 3 10-15-2008 08:52 AM
FC4 I get IP address (on any network) but I can't access to outside the network bodhisattva Fedora 10 02-07-2006 06:58 AM
What is Gateway address and what is Network address? abefroman Linux - Networking 1 03-17-2004 08:25 PM
question about network address and broadcast address yuzuohong Linux - Networking 1 09-18-2002 11:47 AM

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

All times are GMT -5. The time now is 08:14 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