I didn't think that inet_ntoa would work because I didn't have an in_addr structure to pass it, I only had a struct sockaddr_in, and I didn't see an in_addr structure residing within that. So I didn't want to sit and guess what part (if any) of that structure to pass it, or try and find something to extract that information. However the man page for what I ended up using (inet_ntop) does say that is equivalent to inet_ntoa, although it takes entirely different arguments.
Anyway, I found code (in the Steven's book) to obtain my desired results. I knew we had a copy laying around here somewhere, I just couldn't find it...but you're right it is the God of network books.
So (drumroll) for those curious, this is what I ended up doing. Keep in mind that I needed to go from an integer socket descriptor to an IP, so this code may not be exactly what you need.
Just a quick note, the saddr and slen variables work fine with the type I gave them for HP-UX (and Redhat - while it gives compile warnings it works)). However, some OSes want saddr to be of type struct sockaddr *, and some want slen to be of type socklen_t. And while that may work, sockaddr doesn't have the internet sin_addr field required...so some typecasting may need to be done to shut those compilers up.
Also, this isn't the exact code I used, but it does the job and presents the basics without all the garbage I put around it for my particular needs.
Also, if you wanted to know port information, you could get it with:
port = ntohs(saddr.sin_port);
Provided, of course, that saddr was filled in.
getMine allows you to get information regarding the local socket connection, otherwise (by passing it 0) you get information regarding the connection at the other end (the peer).
i m writing a program which finds the i.p address of the machine.
but it just prints out the first three character of the ifconfig output
but i want to just print my i.p address lik 10.0.0.222 which is in second line after inet addr:
code :
#include<iostream>
#include<cstdlib>
using... (1 Reply)
hi all
i want to set ip address to a vitrual machine i am using following command.
but it is not ifconfig -a command output.
what is wrong i dont know
bash# ifconfig interfacename plumb
bash# ifconfig interfacename auto-dhcp
Please use code tags next time for your code and data. (4 Replies)
Hi All
I am having a solaris 10 virtual machine on vista (using vmware 7) laptop.
Now i want to access virtual machine from vista using putty.
Problem is that i insalled the solaris machine as dhcp. and whenever i connect to internet or reboot my system the IP address of solaris... (1 Reply)
Hi
How to get the IP address / Host name of a particular user connected to Unix Server.
For example: If used 'DevUser1' is connected to Unix server. I need to find out from which PC this connection has been made.
How can this be achieved?
Thanks (6 Replies)
Hi
i want to know the Ip address of the machine from where i logged into the unix server and made some changes to a file.
Can I know the last changes made to a unix file ? (3 Replies)
I am using windows Xp. From windows I would connect to my IBM AIX unix machine using telnet client. Is there any command available to view the IP address of Windows machine from Unix? (Note that ifconfig will give unix mahcine's IP address currently logged in.) (3 Replies)
I have a need to allow only certain IP addresses to access a machine running solaris 9. I am not sure how this can be accomplished.
Thanks in advance for your help.
Patch (2 Replies)