-
-
Save klange/7ea49475139da66964656aa770c8e214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <sys/ioctl.h> | |
#include <net/if.h> | |
#include <netinet/in.h> | |
int main(int argc, char * argv[]) { | |
if (argc < 5) { | |
fprintf(stderr,"usage: %s device ipaddr netmask gateway\n", argv[0]); | |
return 1; | |
} | |
char dev[100]; | |
snprintf(dev,100,"/dev/net/%s", argv[1]); | |
int netdev = open(dev,O_RDWR); | |
if (netdev < 0) return netdev; | |
int status; | |
in_addr_t ip = inet_addr(argv[2]); | |
if ((status = ioctl(netdev, SIOCSIFADDR, &ip))) return status; | |
ip = inet_addr(argv[3]); | |
if ((status = ioctl(netdev, SIOCSIFNETMASK, &ip))) return status; | |
ip = inet_addr(argv[4]); | |
if ((status = ioctl(netdev, SIOCSIFGATEWAY, &ip))) return status; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment