[C] Change IP and MAC address

Hello, I need to write a program using C language which allow me to change the IP and MAC addresses of a given interface... Now I fork the process and by exec I'm using the "ifconfig interf X.X.X.X" command... but i can't use this solution because i have to avoid the context switch... Can someone help me? I just need 2 functions who look like this:

int change_IP(char *name, char *newIP);
int change_MAC(char *name, char *newMAC);

obviously this is a "wrap" salple... but it usefull to understand that i need just to modify the 2 addresses!
Thank you and see you soon

What operating system are you on? There is no standardized API for what you want to do but all Unix and Unix-like operating systems have their own methods.

1 Like

I'm on Ubuntu now... but it have to work on Angstrom too...

You realize that any system call can cause this context switch? That a system call is in fact a context switch? Running a system call stops the process until the system call finishes! What you're looking for doesn't exist.

Running strace on ifconfig in linux, I see it using ioctl with SIOCSIFADDR, SIOCGIFFLAGS, and SIOCSIFNETMASK.

Coronna made a pertinent remark. Is your motivation to avoid system(...) (or fork+exec) really sound? Do you have such constraints that definitively impeach you doing so? Quoting Albert: Make it as simple as possible, but not simpler...

Cheers, Lo�c