On Sun, Mar 10, 2002 at 12:38:49AM +0100, Szymon Juraszczyk wrote: > Actually I can't see the code of bla.c mentioned in that report > (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=136659). I guess there > should be an attachement with the code.
#include <netinet/ip.h> main() { unsigned char a[100]; static struct iphdr *tmp_iphdr; unsigned char b[100]; int x; int o = 2; memset(a, 'a', 100); memset(b, 'b', 100); tmp_iphdr = (void *) (a+o); x = ((void *)&tmp_iphdr->saddr)-(void *)tmp_iphdr; printf("Start of struct %p, content: a=%.14s rel-pos x=%d offset o=%d\n", a, a, x, o); printf("Now we are going to memcpy dst=a+x+o=%p\n", a+x+o); memcpy(&b,a + x + o,4); printf("result of a+x+o access: b=%.14s\n", b); printf("Now we are going to bcopy dst=&(tmp_iphdr->saddr)=%p\n", &(tmp_iphdr->saddr)); bcopy((void *)&(tmp_iphdr->saddr),&b,4); printf("result of bcopy &(tmp_iphdr->saddr) access: b=%.14s\n", b); printf("Now we are going to memcpy dst=&(tmp_iphdr->saddr)=%p\n", &(tmp_iphdr->saddr)); memcpy(&b,&(tmp_iphdr->saddr),4); printf("result of memcpy &(tmp_iphdr->saddr) access: b=%.14s\n", b); } this should work :) Greetings Bernd