LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 02-08-2005, 09:58 AM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
get the IP-addr out from an int32_t value


I am playing around with utmp and I saw these two lines in the man:
Code:
int32_t ut_addr_v6[4];      /* IP address of remote host.  */
#define ut_addr ut_addr_v6[0]
Now, I have never heard of the type int32_t. Since the first index in the array is used to define ut_addr for backward compatibility I thought that index would explain something or at least give a clue.

I got the value 1387536345 which still not make a lot of sense to me.

I would like to get something so I can use inet_ntoa() or simular to get a v4 IP-addr.
 
Old 02-08-2005, 10:16 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
ut_addr_v6[0] is a 32-bit value (int32_t) containing the 4 bytes of the ip address in, I believe, host order. The following *SHOULD* work, I think:
Code:
inet_ntoa((struct in_addr)ut_addr_v6[0]);
Some minor modification may be neccessary.
 
Old 02-08-2005, 10:37 AM   #3
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Hm, I tried to play with that but I always get the error
Code:
error: no matching function for call to `in_addr::in_addr(
   int32_t&)'
/usr/include/netinet/in.h:135: error: candidates are: in_addr::in_addr()
/usr/include/netinet/in.h:135: error:                 in_addr::in_addr(const 
   in_addr&)
This must mean that I can't convert int32_t to in_addr that easy, right?

EDIT:
It was easy. Just assign the value of ut_addr_v6[0] to the s_addr in the inet_addr structure and then use that with inet_ntoa() to get the ip. :)

Code:
in_addr ipnetw;
ipnetw.s_addr = entry->ut_addr_v6[0];
string ipaddr = inet_ntoa(ipnetw);

Last edited by Ephracis; 02-08-2005 at 10:59 AM.
 
Old 02-09-2005, 09:03 AM   #4
gr33ndata
Member
 
Registered: Aug 2003
Location: DMZ
Distribution: Ubuntu
Posts: 144

Rep: Reputation: 15
BTW, Is there and equivalent function to inet_ntoa() in the kernel space?
 
  


Reply



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
in-addr-arpa HELP!! james.farrow Linux - Networking 8 10-10-2008 02:47 AM
Obtain IP addr. from MAC addr? Ryand833 Linux - Wireless Networking 3 06-30-2005 01:59 PM
set ip to fixed addr compzoo Linux - Newbie 16 01-29-2005 07:37 PM
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 > Non-*NIX Forums > Programming

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