Date: Tue, 08 Jan 2002 03:12:26 -0800 (PST) From: John Baldwin <jhb@FreeBSD.org> To: wpaul@FreeBSD.org, hackers@FreeBSD.org Subject: [PATCH] Fix endianness bug in YP Message-ID: <XFMail.020108031226.jhb@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
YP didn't work on my sparc64 testbox here until I crafted this patch. It's a simple combination of an endian problem on an arch where sizeof(long) != sizeof(IPv4 address). The patch can be found at http://www.freebsd.org/~jhb/patches/yp.patch and below: I've tested it on both sparc64 and i386. Both work fine. sparc64 didn't work prior to this. Unfortunately, my mailer is going to butcher it, so you probably want to fetch the version above. I'd like to commit it unless there are objections. Index: yplib.c =================================================================== RCS file: /usr/cvs/src/lib/libc/yp/yplib.c,v retrieving revision 1.36 diff -u -r1.36 yplib.c --- yplib.c 23 May 2001 15:37:10 -0000 1.36 +++ yplib.c 8 Jan 2002 10:30:39 -0000 @@ -402,10 +402,12 @@ bzero(&ysd->dom_server_addr, sizeof ysd->dom_server_addr); ysd->dom_server_addr.sin_family = AF_INET; ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in); - ysd->dom_server_addr.sin_addr.s_addr = - *(u_long *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr; - ysd->dom_server_addr.sin_port = - *(u_short *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port; + bcopy(&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr, + &ysd->dom_server_addr.sin_addr.s_addr, + sizeof(ysd->dom_server_addr.sin_addr.s_addr)); + bcopy(&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port, + &ysd->dom_server_addr.sin_port, + sizeof(ysd->dom_server_addr.sin_port)); ysd->dom_server_port = ysd->dom_server_addr.sin_port; _close(fd); @@ -497,10 +499,12 @@ bzero((char *)&ysd->dom_server_addr, sizeof ysd->dom_server_addr); ysd->dom_server_addr.sin_family = AF_INET; - ysd->dom_server_addr.sin_port = - *(u_short *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port; - ysd->dom_server_addr.sin_addr.s_addr = - *(u_long *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr; + bcopy(&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port, + &ysd->dom_server_addr.sin_port, + sizeof(ysd->dom_server_addr.sin_port)); + bcopy(&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr, + &ysd->dom_server_addr.sin_addr.s_addr, + sizeof(ysd->dom_server_addr.sin_addr.s_addr)); /* * We could do a reserved port check here too, but this -- John Baldwin <jhb@FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.020108031226.jhb>