Add netctl back
This commit is contained in:
parent
4df8f04583
commit
5ee8044d5e
2
Makefile
2
Makefile
@ -22,6 +22,7 @@ STAGE_BIN=$(STAGE)/init \
|
||||
$(STAGE)/bin/date \
|
||||
$(STAGE)/bin/login \
|
||||
$(STAGE)/bin/insmod \
|
||||
$(STAGE)/bin/netctl \
|
||||
$(STAGE)/test.ko
|
||||
|
||||
# TODO
|
||||
@ -32,7 +33,6 @@ STAGE_BIN=$(STAGE)/init \
|
||||
# $(STAGE)/bin/reboot \
|
||||
|
||||
|
||||
# $(STAGE)/bin/netctl \
|
||||
# $(STAGE)/bin/netmeow \
|
||||
# $(STAGE)/bin/netdump \
|
||||
# $(STAGE)/bin/ping \
|
||||
|
@ -1,44 +1,33 @@
|
||||
#include <sys/netctl.h>
|
||||
#include <ygg/netctl.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static int nc_addr_show(int argc, char **argv) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int nc_addr(int argc, char **argv) {
|
||||
if (argc == 0) {
|
||||
return nc_addr_show(argc, argv);
|
||||
}
|
||||
|
||||
fprintf(stderr, "addr: unknown command: %s\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc == 2) {
|
||||
uint32_t inaddr;
|
||||
|
||||
if (netctl(argv[1], NETCTL_GET_INADDR, &inaddr) != 0) {
|
||||
if (errno == ENOENT) {
|
||||
printf("No address\n");
|
||||
return 0;
|
||||
}
|
||||
perror("netctl()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("%d.%d.%d.%d\n", inaddr >> 24, (inaddr >> 16) & 0xFF, (inaddr >> 8) & 0xFF, inaddr & 0xFF);
|
||||
return 0;
|
||||
} else if (argc == 3) {
|
||||
uint32_t inaddr_bytes[4];
|
||||
|
||||
if (sscanf(argv[2], "%d.%d.%d.%d", &inaddr_bytes[0], &inaddr_bytes[1], &inaddr_bytes[2], &inaddr_bytes[3]) != 4) {
|
||||
printf("Invalid address format\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t inaddr = (inaddr_bytes[0] & 0xFF) << 24 |
|
||||
(inaddr_bytes[1] & 0xFF) << 16 |
|
||||
(inaddr_bytes[2] & 0xFF) << 8 |
|
||||
(inaddr_bytes[3] & 0xFF);
|
||||
|
||||
|
||||
if (netctl(argv[1], NETCTL_SET_INADDR, &inaddr) != 0) {
|
||||
perror("netctl()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
printf("Usage: netctl <interface> [<address>]\n");
|
||||
if (argc <= 1) {
|
||||
fprintf(stderr, "Usage: %s COMMAND [ ARGS ... ]\n", argv[0]);
|
||||
fprintf(stderr, "Possible commands:\n");
|
||||
fprintf(stderr, " if Interface control\n");
|
||||
fprintf(stderr, " addr Address control\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "addr")) {
|
||||
return nc_addr(argc - 2, &argv[2]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
6
init.c
6
init.c
@ -1,4 +1,4 @@
|
||||
//#include <sys/netctl.h>
|
||||
#include <ygg/netctl.h>
|
||||
// TODO:
|
||||
//#include <sys/mount.h>
|
||||
#include <sys/wait.h>
|
||||
@ -32,8 +32,8 @@ int main(int argc, char **argv) {
|
||||
mount(NULL, "/sys", "sysfs", 0, NULL);
|
||||
mount("/dev/sda1", "/mnt", NULL, 0, NULL);
|
||||
|
||||
//uint32_t inaddr = 0x0A000001;
|
||||
//netctl("eth0", NETCTL_SET_INADDR, &inaddr);
|
||||
uint32_t inaddr = 0x0A000001;
|
||||
netctl("eth0", NETCTL_SET_INADDR, &inaddr);
|
||||
|
||||
return start_login();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user