Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Networking > Getting Local IP of current machine (internet sockets)
 Linux Networking   Hardware/Software related, Modems, Internet connection sharing, IPTables etc.

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 11-23-2006   #1 (permalink)
Just Joined!
 
Join Date: Nov 2006
Posts: 17
Getting Local IP of current machine (internet sockets)

Hi!

I'm doing some application in C/C++ using pure berkeley sockets.

I want to know, what is the best way to get the adress from the current local machine, right now what I do is returning me 127.1.1.0, i want to have 192.168.0.100 for insntace

i gethostname() -> gives me my computer name ( marcd-linuxbox )
and then i create a hostent struct with the gethostbyname()

it works on Windows machine, probably because Windows is dumb, i found it more logical to have something like 127.0.0.1 or something like that returned. But i really need to find a way to get this local IP for my local network broadcast thingy.

Thanks for any help
md_lasalle is offline  

Reply With Quote
Old 11-23-2006   #2 (permalink)
Just Joined!
 
Join Date: Nov 2006
Posts: 17
ok i managed to find this talking about ioctl() function and i managed to get that the second interface returned 192.168.0.102 like i wanted

But this brings me to another question, how can i know if the second interface will always return the right local adress, as the first one currently returns 127.0.0.1
md_lasalle is offline   Reply With Quote
Old 11-23-2006   #3 (permalink)
Linux User
 
Join Date: Aug 2006
Location: Croydon, PA
Posts: 392
Send a message via AIM to Skiboy

ifconfig -a


This gives all the IP ethernet addresses on the machine.
__________________
Good Luck,
Ski
RHCT
Skiboy is offline   Reply With Quote
Old 11-23-2006   #4 (permalink)
Just Joined!
 
Join Date: Nov 2006
Posts: 17
Quote:
Originally Posted by Skiboy

ifconfig -a


This gives all the IP ethernet addresses on the machine.
Yes but not inside a C program, thats why i had to use the ioctl() function
md_lasalle is offline   Reply With Quote
Old 02-15-2007   #5 (permalink)
Just Joined!
 
Join Date: Feb 2007
Posts: 1
Quote:
Originally Posted by md_lasalle
Yes but not inside a C program, thats why i had to use the ioctl() function

hi md_lasalle,

now..i'm facing the same problem with you. Can u teach me how to use the ioctl() function in C program.

tq
nyache is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Free Network Mapping Tool for Microsoft® Office Visio® Professional 2007 Users
Don't map your network by hand – let LANsurveyor Express for Microsoft Visio Professional 2007 automatically create network diagrams for you.
subscribe
Free eBook:"Vulnerability Management for Dummies"
Get all the Facts and See How to Implement a Successful Vulnerability Management Program.
subscribe
Google vs The World: The Battle of the Message Security Vendors
With such a powerful name behind it, Google Message Security stands out in a sea of products that do exactly the same thing - or so they say.
subscribe

Safe, Secure Backup


All times are GMT. The time now is 01:03 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2