cmd_ip.c 988 Bytes
Newer Older
1 2 3 4 5 6 7 8
/*
 * This work is part of the White Rabbit project
 *
 * Copyright (C) 2012 GSI (www.gsi.de)
 * Author: Wesley W. Terpstra <w.terpstra@gsi.de>
 *
 * Released according to the GNU GPL, version 2 or any later version.
 */
9 10 11
#include <stdlib.h>
#include <string.h>
#include <errno.h>
12
#include <wrc.h>
13 14 15 16 17

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

18
static void decode_ip(const char *str, unsigned char *ip)
19 20
{
	int i, x;
21

22 23 24 25 26 27 28
	/* 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;
	}
29 30
}

31 32
int cmd_ip(const char *args[])
{
33
	unsigned char ip[4];
34

35 36 37 38 39 40 41 42
	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;
	}
43

44 45 46 47 48 49
	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]);
	}
50
	return 0;
51
}