Jump to ID:
Networking

Project Home

Discussions

Wiki

Project Info
Forum Topic - How to programmatically set the net mask of an IP alias: (2 Items)
   
 
 
How to programmatically set the net mask of an IP alias  
I am adding an IP alias to en0 using ioctl SIOCAIFADDR function in my application.  This works OK.  Next, I try to set 
the subnet mask using ioctl SIOCSIFNETMASK, but this changes the network mask of the primary IP address.  I tried to 
'bind' the alias address to the socket before calling ioctl but this didn't work.  How do I set the subnet mask (and 
broadcast address) for an IP alias?
Re: How to programmatically set the net mask of an IP alias  
For the benefit of those struggling to figure out how to do the seemingly simple task of setting network parameters, I 
have found out through much Google searching and experimentation that getting the information involves the super-secret 
poorly documented  'syctl' function and setting them involves the equally poorly documented AF_ROUTE socket interface.  
Avoid 'ioctl' because it doesn't handle IP aliases and is not threadsafe.  If my employer is feeling magnanimous I will 
post code snippets on what I have learned on company time when I get it all working