1

How can I get ip address with C/glib of my local computer which get from route.

Cœur
  • 37,241
  • 25
  • 195
  • 267
0xAX
  • 20,957
  • 26
  • 117
  • 206
  • possibly a duplication of [Linux / C++: Get the IP Address of local computer](http://stackoverflow.com/a/265978/640650)? It's not a glib solution but a C one. – Yasushi Shoji Aug 14 '12 at 03:54

2 Answers2

0

I'm not really sure what you mean with "get from route".

But if want to get the IP you're using outside your LAN then just wrap up this command into a system call.

curl -s http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'

It always works.

Manuel Salvadores
  • 16,287
  • 5
  • 37
  • 56
0

You can use libgtop, in particular you can use a mix of netlist and netload. With netlist you can get the network interface list, and with netload you can get the information for each interface (or the interface you are interested in).

gpoo
  • 8,408
  • 3
  • 38
  • 53