Messages in this thread | | | Date | Thu, 19 Dec 1996 09:41:03 -0500 (EST) | From | "Richard B. Johnson" <> | Subject | Re: Socket header |
| |
On Thu, 19 Dec 1996, Alan Modra wrote:
> > > root@analogic.com (Richard B. Johnson) > > In the following include file, cmsg_data[0] is not properly declared. > > We need to declare the first element in an array of unknown size. ANSI > > allows cmsg_data[1], but not cmsg_data[0]. I have recompiled the kernel > > with this change and everything is okay. I also recompiled several > > network programs that use sockets and they compile and work. > > > > [erroneous patch deleted] > > Hum. You'll also need to fix all the length calculations that use > sizeof(struct cmsghdr). See net/core/scm.c >
If true, the first element of the unknown length string (the data) should not be in that stucture. Look at the problems.........
struct foo { char a[100]; short b[100]; long c[100]; char d[1]; } zap;
struct bar { char a[100]; short b[100]; long c[100]; char d[0]; /* Like the original header */ } zim;
main() { printf("zim = %d\n", sizeof(zim)); printf("zap = %d\n", sizeof(zap)); }
The output of this program is NOT what one would expect.....
zim = 700 zap = 704
There is a 4-byte difference!! Hint. I deliberately put elements in the order which will force a bad alignment so the compiler defaults to filling in the holes. Using a zero-sized array will cause many problems with portability, asside from the fact that it is "illegal". Since much of the network code has been rewritten (and improved), it would be a shame to not fix these reference problems.
Cheers, Dick Johnson -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Richard B. Johnson Project Engineer Analogic Corporation Voice : (508) 977-3000 ext. 3754 Fax : (508) 532-6097 Modem : (508) 977-6870 Ftp : ftp@boneserver.analogic.com Email : rjohnson@analogic.com, johnson@analogic.com Penguin : Linux version 2.1.15 on an i586 machine. Warning : It's hard to remain at the trailing edge of technology. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| |