[C] Change IP and MAC address


 
Thread Tools Search this Thread
Top Forums Programming [C] Change IP and MAC address
# 1  
Old 05-16-2011
[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
# 2  
Old 05-16-2011
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.
This User Gave Thanks to fpmurphy For This Post:
# 3  
Old 05-16-2011
I'm on Ubuntu now... but it have to work on Angstrom too...
# 4  
Old 05-16-2011
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.
# 5  
Old 05-19-2011
Quote:
Originally Posted by gilby985
Hello, I need to write a program using C language which allow me to change the IP and MAC addresses of a given interface...
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

MAC Address - Four Interfaces with the same MAC Address

four interfaces with ifconfig all interfaces have the same mac. If is not set for unique. but it still works. what difference does it make to have all macs the same or different? (4 Replies)
Discussion started by: rrodgers
4 Replies

2. IP Networking

Cannot change mac address

ubuntu / xubuntu 13.10 and 14.04 (this issue should exist in debian as well) I use wifi to connect to internet. I would like to change the wifi card mac address before connecting. Let's call the original mac address, macA, and the new mac address, macB. I do the following: ifconfig wlan0... (2 Replies)
Discussion started by: arpagon
2 Replies

3. IP Networking

Tracing a MAC address to IP address: Solaris

Hi there I lost connectivity to one of our remote systems and when I checked the messages log I found the following: Aug 10 23:42:34 host xntpd: time reset (step) 1.681729 s Aug 16 13:20:51 host ip: WARNING: node "mac address" is using our IP address x.x.x.x on aggr1 Aug 16 13:20:51 host... (9 Replies)
Discussion started by: notreallyhere
9 Replies

4. SCO

MAC address

hi every one please help i want to change mac address in sco unix 5.0.6 how can i do this (3 Replies)
Discussion started by: kaydream
3 Replies

5. Cybersecurity

MAC Address spoofing

There is a question in the SCO section asking for information on how to change the MAC address of a NIC. Is there a valid reason for wanting to change the MAC address? (1 Reply)
Discussion started by: jgt
1 Replies

6. Solaris

Get ip address from mac address

I have following message in my messages file on solaris 10 WARNING: e1000g3712000:3 has duplicate address 010.022.196.011 (in use by 00:50:56:85:25:ef); disabled Now is there any way i can find which server has 00:50:56:85:25:ef mac address either IP or Hostname ? (6 Replies)
Discussion started by: fugitive
6 Replies

7. Solaris

Host ID vs MAC Address

Hi, I've got a Sun Solaris machine with host ID (840f8e57) and MAC address (0:14:4f:f:8e:57), how do I: 1. Write the MAC address in standard (IEEE 802) format, i.e. xx-xx-xx-xx-xx-xx? Do I need to add 0's before or after the 'f', i.e. 00-14-4f-0f-8e-57 or 00-14-4f-f0-8e-57? 2. What is... (4 Replies)
Discussion started by: TheBlueSky
4 Replies

8. IP Networking

How to Achive IP address through MAC(Ethernet) address

Hi sir, i want to make such programe which takes MAC(Ethernet) address of any host & give me its IP address....... but i'm nt getting that how i can pass the MAC address to Frame........ Please give me an idea for making such program... Thanks & regards Krishna (3 Replies)
Discussion started by: krishnacins
3 Replies

9. UNIX for Dummies Questions & Answers

Mac address

Hi Can some one help me How do find out Mac address in Tru64 Unix Thank you (1 Reply)
Discussion started by: Syed_45
1 Replies

10. Programming

Get Mac Address

:( Hi I am trying to get Mac address of of my Sun server from my C program running on the host machine. Any suggestions . (1 Reply)
Discussion started by: ss_hpov
1 Replies
Login or Register to Ask a Question