Browse Source

Safer code for net_read32 and net_write32. It may have been possible for them

to cause failure on some architectures because of unaligned fetch/write of
integers.
master
Richard Nyberg 19 years ago
parent
commit
6214255bbb
1 changed files with 8 additions and 2 deletions
  1. +8
    -2
      btpd/net.c

+ 8
- 2
btpd/net.c View File

@@ -128,13 +128,19 @@ net_active(struct torrent *tp)
void
net_write32(void *buf, uint32_t num)
{
*(uint32_t *)buf = htonl(num);
uint8_t *p = buf;
*p = (num >> 24) & 0xff;
*(p + 1) = (num >> 16) & 0xff;
*(p + 2) = (num >> 8) & 0xff;
*(p + 3) = num & 0xff;
}

uint32_t
net_read32(const void *buf)
{
return ntohl(*(uint32_t *)buf);
const uint8_t *p = buf;
return (uint32_t)*p << 24 | (uint32_t)*(p + 1) << 16
| (uint16_t)*(p + 2) << 8 | *(p + 3);
}

static unsigned long


Loading…
Cancel
Save