I need to display all the IP addresses from my local computer, using the C language. How can this be done?
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- how to get running process information in java?
Not a complete solution yet, but take a look in
/proc/net
!dev
lists the available interface devices by name,route
lists some routes, as doesipv6_route
,arp
lists devices in the actual routing table (does not include localhost).Not as high-tech as the other solution, but it can be done with simple file reading. Linux specific, though.
Another way to do it in C. I do have to say though.... there are so many ways to do it from the shell, what's the point?
You need POSIX function
getaddrinfo()
- it returns linked list of all IP addresses.See
man getaddrinfo
for details and examples.And you can put that into popen():
How about you simply cheat and look at the source of
/sbin/ifconfig/
? Nothing wrong with standing on the shoulders of other giants...