Module Name:    src
Committed By:   kefren
Date:           Wed Jan 16 08:28:46 UTC 2013

Modified Files:
        src/usr.sbin/ldpd: mpls_routes.h socketops.c

Log Message:
Make sure there is enough space for sockaddr subtypes
Use u_char for IP_MULTICAST_LOOP as specified in in.h


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/mpls_routes.h
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/ldpd/socketops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ldpd/mpls_routes.h
diff -u src/usr.sbin/ldpd/mpls_routes.h:1.1 src/usr.sbin/ldpd/mpls_routes.h:1.2
--- src/usr.sbin/ldpd/mpls_routes.h:1.1	Wed Dec  8 07:20:15 2010
+++ src/usr.sbin/ldpd/mpls_routes.h	Wed Jan 16 08:28:44 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_routes.h,v 1.1 2010/12/08 07:20:15 kefren Exp $ */
+/* $NetBSD: mpls_routes.h,v 1.2 2013/01/16 08:28:44 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -49,6 +49,7 @@
 union sockunion {
 	struct sockaddr sa;
 	struct sockaddr_in sin;
+	struct sockaddr_in6 sin6;
 	struct sockaddr_mpls smpls;
 	struct sockaddr_dl sdl;
 };

Index: src/usr.sbin/ldpd/socketops.c
diff -u src/usr.sbin/ldpd/socketops.c:1.15 src/usr.sbin/ldpd/socketops.c:1.16
--- src/usr.sbin/ldpd/socketops.c:1.15	Tue Nov 13 06:58:58 2012
+++ src/usr.sbin/ldpd/socketops.c	Wed Jan 16 08:28:45 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: socketops.c,v 1.15 2012/11/13 06:58:58 kefren Exp $ */
+/* $NetBSD: socketops.c,v 1.16 2013/01/16 08:28:45 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -147,8 +147,8 @@ create_hello_sockets()
 #endif
 
 	/* We don't need to receive back our messages */
-	if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &(uint8_t){0},
-	    sizeof(uint8_t)) == -1) {
+	if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &(u_char){0},
+	    sizeof(u_char)) == -1) {
 		fatalp("INET setsockopt IP_MCAST_LOOP: %s\n", strerror(errno));
 		goto chs_error;
 	}
@@ -260,27 +260,25 @@ socket_reuse_port(int s)
 static int
 bind_socket(int s, uint8_t stype)
 {
-	struct sockaddr sa;
+	union sockunion su;
 
 	assert (stype == 4 || stype == 6);
 
 	if (stype == 4) {
-		struct sockaddr_in *sa_inet = (struct sockaddr_in *)(&sa);
-		sa_inet->sin_len = sizeof(*sa_inet);
-		sa_inet->sin_family = AF_INET;
-		sa_inet->sin_addr.s_addr = INADDR_ANY;
-		sa_inet->sin_port = htons(LDP_PORT);
+		su.sin.sin_len = sizeof(su.sin);
+		su.sin.sin_family = AF_INET;
+		su.sin.sin_addr.s_addr = INADDR_ANY;
+		su.sin.sin_port = htons(LDP_PORT);
 	}
 #ifdef INET6
 	else if (stype == 6) {
-		struct sockaddr_in6 *sa_inet6 = (struct sockaddr_in6 *)(&sa);
-		sa_inet6->sin6_len = sizeof(*sa_inet6);
-		sa_inet6->sin6_family = AF_INET6;
-		sa_inet6->sin6_addr = in6addr_any;
-		sa_inet6->sin6_port = htons(LDP_PORT);
+		su.sin6.sin6_len = sizeof(su.sin6);
+		su.sin6.sin6_family = AF_INET6;
+		su.sin6.sin6_addr = in6addr_any;
+		su.sin6.sin6_port = htons(LDP_PORT);
 	}
 #endif
-	if (bind(s, &sa, sa.sa_len)) {
+	if (bind(s, &su.sa, su.sa.sa_len)) {
 		fatalp("bind_socket: %s\n", strerror(errno));
 		return -1;
 	}

Reply via email to