cvs commit: src/sbin/ifconfig ifconfig.c src/sys/net if.c if.h

Ken Smith kensmith at cse.Buffalo.EDU
Sun Dec 12 21:26:06 PST 2004


On Sun, Dec 12, 2004 at 04:55:40PM -0500, Ken Smith wrote:

> I didn't check as thoroughly as Brooks said he did but I whipped up
> a very crude little test and ran it on beast:
> 
> #include <sys/param.h>
> #include <sys/socket.h>
> #include "if.h"
> 
> main()
> {
>         struct if_data foo;
>         u_char *addr1, *addr2;
> 
>         printf("sizeof if_data %d\n", sizeof(foo));
>         addr1 = (u_char *)&foo;
>         addr2 = (u_char *)&foo.ifi_mtu;
>         printf("offset ifi_mtu %d\n", (int)(addr2 - addr1));
> }
> 

As a community service...  Don't write code like that... :-)

I was having a little trouble finding the right combination of headers
to get offsetof() working.  This should be better:

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <sys/param.h>
#include <sys/socket.h>
#include "if.h"

main()
{
        struct if_data foo;
        size_t distance;

        printf("sizeof if_data %d\n", sizeof(foo));
        distance = offsetof(struct if_data, ifi_mtu);
        printf("offset ifi_mtu %lu\n", (unsigned long)distance);
}

-- 
						Ken Smith
- From there to here, from here to      |       kensmith at cse.buffalo.edu
  there, funny things are everywhere.   |
                      - Theodore Geisel |


More information about the cvs-all mailing list