writev workaround

K. Richard Pixley rpixley at sj.symbol.com
Thu Sep 2 19:33:17 UTC 2004


At least one operating system vendor, (LynxOs from Lynuxwork,
http://www.lnxw.com), releases a system with a broken writev
implentation, at least for bpf.  This problem was reported to
Lynuxworks by a supported customer, (yours truley) on August 8, 2004
as call reference number 46678.

In the mean time, this patch works around the problem in the most
obvious and transparent method I could think of, (although this does
presuppose gcc or some other compiler capable of allocating dynamic
arrays).

--rich

diff -u -r dhcp-3.0.1/common/bpf.c dhcp-work2/common/bpf.c
--- dhcp-3.0.1/common/bpf.c	2004-06-17 13:54:38.000000000 -0700
+++ dhcp-work2/common/bpf.c	2004-08-27 09:43:29.000000000 -0700
@@ -366,6 +366,7 @@
 				(unsigned char *)raw, len);
 
 	/* Fire it off */
+#ifndef HAVE_BROKEN_WRITEV
 	iov [0].iov_base = ((char *)hw);
 	iov [0].iov_len = hbufp;
 	iov [1].iov_base = ((char *)ip);
@@ -374,6 +375,18 @@
 	iov [2].iov_len = len;
 
 	result = writev(interface -> wfdesc, iov, 3);
+#else
+	{
+	  int l = hbufp + ibufp + len;
+	  char b[l];
+
+	  memcpy(b, (char *)hw, hbufp);
+	  memcpy(b + hbufp, (char *)ip, ibufp);
+	  memcpy(b + hbufp + ibufp, (char *)raw, len);
+
+	  result = write(interface -> wfdesc, b, l);
+	}
+#endif
 	if (result < 0)
 		log_error ("send_packet: %m");
 	return result;



More information about the dhcp-hackers mailing list