Use sockaddr_in_init() and ifreq_setaddr() to initialize a sockaddr_in trunk
authordyoung <dyoung@NetBSD.org>
Fri, 31 Aug 2007 22:02:58 +0000
branchtrunk
changeset 161562 db1fbefdd74f
parent 161561 565f97d619a5
child 161563 94d22daafdb6
Use sockaddr_in_init() and ifreq_setaddr() to initialize a sockaddr_in and an ifreq.ifr_addr, respectively. Get rid of an extraneous cast---down the elevator shaft! Change 'ireq' to 'ifr', which is what the kernel calls a temporary struct ifreq virtually everywhere else.
sys/nfs/nfs_boot.c
--- a/sys/nfs/nfs_boot.c	Fri Aug 31 21:56:43 2007 +0000
+++ b/sys/nfs/nfs_boot.c	Fri Aug 31 22:02:58 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs_boot.c,v 1.68 2007/07/19 20:49:00 dyoung Exp $	*/
+/*	$NetBSD: nfs_boot.c,v 1.69 2007/08/31 22:02:58 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_boot.c,v 1.68 2007/07/19 20:49:00 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_boot.c,v 1.69 2007/08/31 22:02:58 dyoung Exp $");
 
 #include "opt_nfs.h"
 #include "opt_tftproot.h"
@@ -306,8 +306,9 @@
 	u_int32_t addr;
 {
 	struct socket *so;
-	struct ifreq ireq;
-	struct sockaddr_in *sin;
+	struct ifreq ifr;
+	struct sockaddr_in sin;
+	struct in_addr ia = {.s_addr = addr};
 	int error;
 
 	/*
@@ -320,15 +321,13 @@
 		return (error);
 	}
 
-	memset(&ireq, 0, sizeof(ireq));
-	memcpy(ireq.ifr_name, ifp->if_xname, IFNAMSIZ);
+	memset(&ifr, 0, sizeof(ifr));
+	memcpy(ifr.ifr_name, ifp->if_xname, IFNAMSIZ);
 
-	sin = (struct sockaddr_in *)&ireq.ifr_addr;
-	sin->sin_len = sizeof(*sin);
-	sin->sin_family = AF_INET;
-	sin->sin_addr.s_addr = addr;
+	sockaddr_in_init(&sin, &ia, 0);
+	ifreq_setaddr(SIOCDIFADDR, &ifr, sintocsa(&sin)); 
 
-	error = ifioctl(so, SIOCDIFADDR, (void *)&ireq, lwp);
+	error = ifioctl(so, SIOCDIFADDR, &ifr, lwp);
 	if (error) {
 		printf("deladdress, error=%d\n", error);
 		goto out;