#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX_IP_LEN 16

/* Reverse the octets in IP address `ip' */
static char *revip4(char *ip)
{
        static char revip[MAX_IP_LEN];
        unsigned int a, b, c, d;

        if ((strlen(ip) >= MAX_IP_LEN) ||
                 sscanf(ip, "%d.%d.%d.%d", &a, &b, &c, &d) != 4) {
                 a = b = c = d = 0;     /* indicate error */
        }

        sprintf(revip, "%d.%d.%d.%d", d, c, b, a);
        return (revip);
}

int main(int argc, char **argv)
{
	if (argc != 2) {
		fprintf(stderr, "Usage: %s dotted-quad\n", *argv);
		exit(1);
	}
        printf("%s\n", revip4(argv[1]));
	return (0);
}

