[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: unalligned sparc memory access problem (memcpy vs bcopy)



On Mon, Mar 04, 2002 at 10:34:46AM +0100, Jan Nieuwenhuizen wrote:
> I looked at  #136659, but can't seem to find your program.  Would you
> mind posting it?

sorry forgot to attach it :)

Greetings
Bernd
#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);
}

Reply to: