[commits] [batctl] next: batctl: Add support for IPv6 to address resolver (c760fb3)

postmaster at open-mesh.org postmaster at open-mesh.org
Tue Sep 24 14:14:18 CEST 2013


Repository : ssh://git@open-mesh.org/batctl

On branch  : next

>---------------------------------------------------------------

commit c760fb3c8029edf40657d283dc47af2fef9b3a6f
Author: Sven Eckelmann <sven at narfation.org>
Date:   Sun Sep 22 16:43:03 2013 +0200

    batctl: Add support for IPv6 to address resolver
    
    Signed-off-by: Sven Eckelmann <sven at narfation.org>


>---------------------------------------------------------------

c760fb3c8029edf40657d283dc47af2fef9b3a6f
 functions.c |   25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/functions.c b/functions.c
index 697c217..7d9c44e 100644
--- a/functions.c
+++ b/functions.c
@@ -427,6 +427,7 @@ static int resolve_l3addr(int ai_family, const char *asc, void *l3addr)
 	struct addrinfo hints;
 	struct addrinfo *res;
 	struct sockaddr_in *inet4;
+	struct sockaddr_in6 *inet6;
 
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = ai_family;
@@ -441,6 +442,11 @@ static int resolve_l3addr(int ai_family, const char *asc, void *l3addr)
 			memcpy(l3addr, &inet4->sin_addr.s_addr,
 			       sizeof(inet4->sin_addr.s_addr));
 			break;
+		case AF_INET6:
+			inet6 = (struct sockaddr_in6 *)res->ai_addr;
+			memcpy(l3addr, &inet6->sin6_addr.s6_addr,
+			       sizeof(inet6->sin6_addr.s6_addr));
+			break;
 		default:
 			ret = -EINVAL;
 		}
@@ -454,6 +460,7 @@ static void request_mac_resolve(int ai_family, const void *l3addr)
 {
 	const struct sockaddr *sockaddr;
 	struct sockaddr_in inet4;
+	struct sockaddr_in6 inet6;
 	size_t sockaddr_len;
 	int sock;
 	char t = 0;
@@ -472,6 +479,15 @@ static void request_mac_resolve(int ai_family, const void *l3addr)
 		sockaddr = (const struct sockaddr *)&inet4;
 		sockaddr_len = sizeof(inet4);
 		break;
+	case AF_INET6:
+		memset(&inet6, 0, sizeof(inet6));
+		inet6.sin6_family = ai_family;
+		inet6.sin6_port = htons(9);
+		memcpy(&inet6.sin6_addr.s6_addr, l3addr,
+		       sizeof(inet6.sin6_addr.s6_addr));
+		sockaddr = (const struct sockaddr *)&inet6;
+		sockaddr_len = sizeof(inet6);
+		break;
 	default:
 		close(sock);
 		return;
@@ -630,6 +646,9 @@ static struct ether_addr *resolve_mac_from_cache(int ai_family,
 	case AF_INET:
 		l3_len = 4;
 		break;
+	case AF_INET6:
+		l3_len = 16;
+		break;
 	default:
 		l3_len = 0;
 	}
@@ -679,6 +698,7 @@ err:
 static struct ether_addr *resolve_mac_from_addr(int ai_family, const char *asc)
 {
 	uint8_t ipv4_addr[4];
+	uint8_t ipv6_addr[16];
 	void *l3addr;
 	int ret;
 	int retries = 5;
@@ -688,6 +708,9 @@ static struct ether_addr *resolve_mac_from_addr(int ai_family, const char *asc)
 	case AF_INET:
 		l3addr = ipv4_addr;
 		break;
+	case AF_INET6:
+		l3addr = ipv6_addr;
+		break;
 	default:
 		return NULL;
 	}
@@ -710,7 +733,7 @@ static struct ether_addr *resolve_mac_from_addr(int ai_family, const char *asc)
 struct ether_addr *resolve_mac(const char *asc)
 {
 	struct ether_addr *mac_result = NULL;
-	static const int ai_families[] = {AF_INET};
+	static const int ai_families[] = {AF_INET, AF_INET6};
 	size_t i;
 
 	mac_result = ether_aton(asc);



More information about the commits mailing list