Revision c5922d21 src/Tests/inet_test.c

View differences:

src/Tests/inet_test.c
18 18

  
19 19
int checkIPv4Translation()
20 20
{
21
	int res = 0;
21
	int res;
22
	const char *res1;
22 23
	struct sockaddr_storage s;
23 24
	struct sockaddr_storage c;
24 25
	char *buf = malloc(INET_ADDRSTRLEN);
......
31 32
		perror ("inet");
32 33
		return res;
33 34
	}
34
	printf("to network %d\n", ((struct sockaddr_in *)&s)->sin_addr);
35
	printf("\tTranslating IPv4 address %d...",((struct sockaddr_in *)&s)->sin_addr);
36
	res = inet_ntop(AF_INET, &((struct sockaddr_in *)&s)->sin_addr, buf, INET_ADDRSTRLEN);
37
	if(!res)
35
	printf("to network %d\n", ((struct sockaddr_in *)&s)->sin_addr.s_addr);
36
	printf("\tTranslating IPv4 address %d...", ((struct sockaddr_in *)&s)->sin_addr.s_addr);
37
	res1 = inet_ntop(AF_INET, &((struct sockaddr_in *)&s)->sin_addr, buf, INET_ADDRSTRLEN);
38
	if(!res1)
38 39
	{
39 40
		perror ("inet");
40 41
		return res;
......
46 47

  
47 48
int checkIPv6Translation()
48 49
{
49
	int res = 0, i;
50
	int res, i;
51
	const char *res1;
50 52
	struct sockaddr_storage s;
51 53
	struct sockaddr_storage c;
52 54
	char *buf = malloc(INET6_ADDRSTRLEN);
53
	char *ipv6 = malloc(INET6_ADDRSTRLEN);
54
	ipv6 = "fe80:0000:0000:0000:0223:aeff:fe54:ea0c";
55
	const char *ipv6 = "fe80:0000:0000:0000:0223:aeff:fe54:ea0c";
55 56
	printf("\tIPv6 Address string %s ", ipv6);
56 57
	res = inet_pton(AF_INET6, ipv6, &((struct sockaddr_in6 *)&s)->sin6_addr);
57 58
	if(!res)
......
74 75
		#else
75 76
		    printf("%02x%02x:", (uint8_t) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i]),(uint8_t) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i+1]));
76 77
		#endif
77
	res = inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&s)->sin6_addr, buf, INET6_ADDRSTRLEN);
78
	if(!res)
78
	res1 = inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&s)->sin6_addr, buf, INET6_ADDRSTRLEN);
79
	if(!res1)
79 80
	{
80 81
		perror ("inet");
81 82
		return res;

Also available in: Unified diff