# How to get the interface's ip address aliases ?



## milleroff (Nov 6, 2009)

An interface has multiple IP addresses. There is the SIOCGIFADDR ioctl to get the main IP address, the SIOCAIFADDR to add an alias, and the SIOCDIFADDR to delete it.

What about the aliases ? How do i get them ?

Thanks.


----------



## graudeejs (Nov 6, 2009)

have you tried running `$ ifconfig` without arguments, or with one argument (interface you want)


```
killasmurf86 % ifconfig rl0
rl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=8<VLAN_MTU>
	ether 00:50:8d:e7:8d:d7
	inet 192.168.128.100 netmask 0xffffff00 broadcast 192.168.128.255
	inet 192.168.128.98 netmask 0xffffff00 broadcast 192.168.128.255
	inet 192.168.128.99 netmask 0xffffffff broadcast 192.168.128.99
	inet 192.168.128.96 netmask 0xffffffff broadcast 192.168.128.96
	media: Ethernet autoselect (100baseTX <full-duplex>)
	status: active
```
last 3 are aliases


----------



## milleroff (Nov 6, 2009)

I know how to get them with ifconfig =) But i need it in C ...


----------



## graudeejs (Nov 6, 2009)

I'd look in source of ifconfig, if i was you.

I'll check my "Advanced Programming in the Unix environment" book, perhaps I'll find some info there


----------



## graudeejs (Nov 6, 2009)

take a look at getifaddrs(3)
Is it getting warmer?


P.S.
I'm not familiar with all this, so excuse me if I'm wrong.


----------



## milleroff (Nov 6, 2009)

OK. I've got it. The getifaddrs returns all the addresses (using family AF_INET) =)

Another question: if there is a SIOCGIFADDR ctl to get the main IP Address, maybe there is such a ctl to get the aliases only (because the are ctls to set and delete them).


----------

