On Fri, 23.09.05 10:53, pHilipp Zabel ([EMAIL PROTECTED]) wrote: > > The pointer d is not necessarily aligned to 32bit multiples. The fix > > is easy: just write all four bytes of the uint32_t value seperately > > and manually to the memory d points to. > > Do you mean something like this? > > uint8_t *avahi_dns_packet_append_uint32(AvahiDnsPacket *p, uint32_t v) { > uint8_t *d; > uint32_t tmp_v; > assert(p); > > if (!(d = avahi_dns_packet_extend(p, sizeof(uint32_t)))) > return NULL; > > tmp_v = htonl(v); > d[0] = tmp_v & 0xFF000000 >> 24; > d[1] = tmp_v & 0xFF0000 >> 16; > d[2] = tmp_v & 0xFF00 >> 8; > d[3] = tmp_v & 0xFF; > > return d; > }
No, this is bogus. If you write the bytes one-by-one to the memory you should not call htonl() first. In addition I am wondering why the compiler doesn't complain about the fact that you assign an uint32_t to an uint8_t variable. Unless I mixed up LE with BE, this should do it: d[0] = (uint8_t) (v >> 24); d[1] = (uint8_t) (v >> 16); d[2] = (uint8_t) (v >> 8); d[3] = (uint8_t) v; Lennart -- Lennart Poettering; lennart [at] poettering [dot] de ICQ# 11060553; GPG 0x1A015CC4; http://0pointer.de/lennart/ _______________________________________________ avahi mailing list avahi@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/avahi