/* I think this example to trivial to claim any copyright on it
 * I wrote it with some help of ##c@irc.freenode.net
 *
 * Stefan de Konink
 */

#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>


int main(int argc, char *argv[]) {
	if (argc != 2) exit(-1);

	struct addrinfo *ai;
	struct addrinfo hints;
	memset (&hints, 0, sizeof hints);
	hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
	int e = getaddrinfo (argv[1], NULL, &hints, &ai);
	printf("%s\n", argv[1]);
	if (e == 0) {
		char buf[INET6_ADDRSTRLEN];
		struct sockaddr_in const *sin = (void *)ai->ai_addr;
		struct in_addr sin_addr = sin->sin_addr;

		sin_addr.s_addr = htonl(ntohl(sin_addr.s_addr) + 1);
		
		printf("%s\n", inet_ntop(ai->ai_family, &sin_addr, buf, sizeof buf));
	}
	freeaddrinfo (ai);
}

