This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: Unresolved external -- read_random( )
- From: Andrew Lunn <andrew at lunn dot ch>
- To: Matt Jerdonek <maj1224 at yahoo dot com>
- Cc: ecos-patches at sources dot redhat dot com
- Date: Mon, 8 Sep 2003 19:28:54 +0200
- Subject: Re: Unresolved external -- read_random( )
- References: <20030908162715.725.qmail@web14202.mail.yahoo.com>
On Mon, Sep 08, 2003 at 09:27:15AM -0700, Matt Jerdonek wrote:
> Index: support.c
> ===================================================================
> RCS file:
> /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/src/ecos/support.c,v
> retrieving revision 1.9
> diff -r1.9 support.c
> 564a565,582
> > int
> > read_random(void *buf, int count)
> > {
> > int randval;
> > int size, i;
> >
> > /* Fill buf[] with random output */
> > for (i = 0; i < count; i+= (int)sizeof(int)) {
> > randval = arc4random();
> > size = (count - i) < (int)sizeof(int)
> > ? (count - i)
> > : sizeof(int);
> > memcpy(&((char *)buf)[i], &randval,
> (size_t)size);
> > }
> >
> > return count;
> > }
Looks a bit ugly to me with all these casts. My preferred solution is:
Index: net/bsd_tcpip/current//ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/ChangeLog,v
retrieving revision 1.31
diff -u -r1.31 ChangeLog
--- net/bsd_tcpip/current//ChangeLog 30 Jul 2003 07:42:31 -0000 1.31
+++ net/bsd_tcpip/current//ChangeLog 8 Sep 2003 17:24:22 -0000
@@ -1,3 +1,9 @@
+2003-09-08 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * src/ecos/support.c (read_random): New function which is needed
+ when CYGSEM_NET_RANDOMID is enabled.
+ * include/sys/param.h: Prototype for new function.
+
2003-07-25 Andrew Lunn <andrew.lunn@ascom.ch>
* include/netinet/icmp_var.h
Index: net/bsd_tcpip/current//include/sys/param.h
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/include/sys/param.h,v
retrieving revision 1.4
diff -u -r1.4 param.h
--- net/bsd_tcpip/current//include/sys/param.h 30 Jul 2003 07:42:32 -0000
1.4
+++ net/bsd_tcpip/current//include/sys/param.h 8 Sep 2003 17:24:25 -0000
@@ -877,6 +877,7 @@
extern void get_mono_time(void);
extern int arc4random(void);
extern void get_random_bytes(void *buf, size_t len);
+extern void read_random(void *buf, size_t len);
extern void read_random_unlimited(void *buf, size_t len);
extern void *hashinit(int elements, void *type, u_long *hashmask);
Index: net/bsd_tcpip/current//src/ecos/support.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/bsd_tcpip/current/src/ecos/support.c,v
retrieving revision 1.9
diff -u -r1.9 support.c
--- net/bsd_tcpip/current//src/ecos/support.c 23 Jun 2003 09:45:11 -0000
1.9
+++ net/bsd_tcpip/current//src/ecos/support.c 8 Sep 2003 17:24:28 -0000
@@ -562,6 +562,13 @@
get_random_bytes(buf, len);
}
+void read_random(void *buf, size_t len)
+{
+ CYG_ASSERT(0 == (len & ~3), "Only multiple of words allowed");
+
+ get_random_bytes(buf, len);
+}
+
void
microtime(struct timeval *tp)
{
This compiles cleanly, but i've not run it. I hope i got that assert
correct! I checked where read_random is called from and len is always
4. I just put the assert there for the case somebody adds new code
which passed a funny value for len which we don't deal with.