cmd_ip.c 734 Bytes
Newer Older
1 2 3 4 5 6 7 8
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "softpll_ng.h"
#include "shell.h"
#include "../lib/ipv4.h"

9 10 11
static decode_ip(const char *str, unsigned char *ip)
{
	int i, x;
12

13 14 15 16 17 18 19
	/* Don't try to detect bad input; need small code */
	for (i = 0; i < 4; ++i) {
		str = fromdec(str, &x);
		ip[i] = x;
		if (*str == '.')
			++str;
	}
20 21
}

22 23
int cmd_ip(const char *args[])
{
24
	unsigned char ip[4];
25

26 27 28 29 30 31 32 33
	if (!args[0] || !strcasecmp(args[0], "get")) {
		getIP(ip);
	} else if (!strcasecmp(args[0], "set") && args[1]) {
		decode_ip(args[1], ip);
		setIP(ip);
	} else {
		return -EINVAL;
	}
34

35 36 37 38 39 40
	if (needIP) {
		mprintf("IP-address: in training\n");
	} else {
		mprintf("IP-address: %d.%d.%d.%d\n",
			ip[0], ip[1], ip[2], ip[3]);
	}
41
}