1 Index: chillispot-1.1.0/src/dhcp.c
2 ===================================================================
3 --- chillispot-1.1.0.orig/src/dhcp.c 2006-09-24 19:48:25.000000000 +0200
4 +++ chillispot-1.1.0/src/dhcp.c 2007-09-25 15:35:12.521055038 +0200
11 + * wrapper for fixing the big endian bugs within dhcp server code.its surelly not the best.
12 + * all dhcp packet fields must be handled in little endian
15 +static uint16_t swap16(uint16_t word) {
16 +#if __BYTE_ORDER == __BIG_ENDIAN
17 + unsigned char low = word>>8;
18 + unsigned char high = word&0xff;
19 + return ((uint16_t)(high<<8))|low;
20 +#elif __BYTE_ORDER == __LITTLE_ENDIAN
23 +#error "Could not determine the system's endianness"
29 * Generates an IPv4 header checksum.
33 for (i=0; i<(pack->iph.ihl * 2); i++) {
34 - sum += ((uint16_t*) &pack->iph)[i];
35 + sum += swap16(((uint16_t*) &pack->iph)[i]); /* brainslayer */
38 sum = (sum & 0xFFFF)+(sum >> 16);
39 - pack->iph.check = ~sum;
40 + pack->iph.check = swap16(~sum); /* brainslayer */
47 /* Sum UDP header and payload */
49 for (i=0; i<(udp_len/2); i++) {
50 - sum += ((uint16_t*) &pack->udph)[i];
51 + sum += swap16(((uint16_t*) &pack->udph)[i]); /* brainslayer */
54 - /* Sum any uneven payload octet */
57 sum += ((uint8_t*) &pack->udph)[udp_len-1];
60 /* Sum both source and destination address */
62 - sum += ((uint16_t*) &pack->iph.saddr)[i];
63 + sum += swap16(((uint16_t*) &pack->iph.saddr)[i]); /* brainslayer */
66 /* Sum both protocol and udp_len (again) */
67 - sum = sum + pack->udph.len + ((pack->iph.protocol<<8)&0xFF00);
68 + sum = sum + swap16(pack->udph.len) + ((pack->iph.protocol<<8)&0xFF00); /* brainslayer */
71 sum = (sum & 0xFFFF)+(sum >> 16);
73 - pack->udph.check = ~sum;
74 + pack->udph.check = swap16(~sum); /* brainslayer */
80 /* Sum TCP header and payload */
81 for (i=0; i<(tcp_len/2); i++) {
82 - sum += ((uint16_t*) pack->payload)[i];
83 + sum += swap16(((uint16_t*) pack->payload)[i]); /* brainslayer */
86 /* Sum any uneven payload octet */
89 /* Sum both source and destination address */
91 - sum += ((uint16_t*) &pack->iph.saddr)[i];
92 + sum += swap16(((uint16_t*) &pack->iph.saddr)[i]); /* brainslayer */
95 /* Sum both protocol and tcp_len */
96 - sum = sum + htons(tcp_len) + ((pack->iph.protocol<<8)&0xFF00);
97 + sum = sum + swap16(htons(tcp_len)) + ((pack->iph.protocol<<8)&0xFF00); /* brainslayer */
100 sum = (sum & 0xFFFF)+(sum >> 16);
102 - tcph->check = ~sum;
103 + tcph->check = swap16(~sum); /* brainslayer */
107 Index: chillispot-1.1.0/src/dhcp.h
108 ===================================================================
109 --- chillispot-1.1.0.orig/src/dhcp.h 2006-09-24 19:48:25.000000000 +0200
110 +++ chillispot-1.1.0/src/dhcp.h 2007-09-25 15:35:12.533055724 +0200
117 /* Constants for IP packet */
118 #define DHCP_IP_ALEN 4
119 #define DHCP_IP_HLEN 20
121 #define DHCP_IP_UDP 17 /* UDP Protocol number */
123 struct dhcp_iphdr_t {
124 +#if __BYTE_ORDER == __LITTLE_ENDIAN /* nbd fix for swapped version and length field */
127 +#elif __BYTE_ORDER == __BIG_ENDIAN
131 +#error "Could not determine the system's endianness"