Stefan Schuermans commited on 2012-04-04 22:24:49
Showing 1 changed files, with 27 additions and 3 deletions.
| ... | ... |
@@ -223,17 +223,41 @@ void ip_send(void *ptr, unsigned int sz) |
| 223 | 223 |
(ip_pack->ip_hdr.dest[2] & config_ip.mask[2]) == |
| 224 | 224 |
(config_ip.ip[2] & config_ip.mask[2]) && |
| 225 | 225 |
(ip_pack->ip_hdr.dest[3] & config_ip.mask[3]) == |
| 226 |
- (config_ip.ip[3] & config_ip.mask[3])) |
|
| 226 |
+ (config_ip.ip[3] & config_ip.mask[3])) {
|
|
| 227 |
+ // broadcast |
|
| 228 |
+ if ((ip_pack->ip_hdr.dest[0] | config_ip.mask[0]) == 0xFF && |
|
| 229 |
+ (ip_pack->ip_hdr.dest[1] | config_ip.mask[1]) == 0xFF && |
|
| 230 |
+ (ip_pack->ip_hdr.dest[2] | config_ip.mask[2]) == 0xFF && |
|
| 231 |
+ (ip_pack->ip_hdr.dest[3] | config_ip.mask[3]) == 0xFF) {
|
|
| 232 |
+ mac_cpy(ip_pack->eth_hdr.dest, "\xFF\xFF\xFF\xFF\xFF\xFF"); |
|
| 233 |
+ i = 0; // MAC is available |
|
| 234 |
+ } |
|
| 235 |
+ // unicast |
|
| 236 |
+ else {
|
|
| 227 | 237 |
// lookup MAC address of destination |
| 228 | 238 |
i = arp_lookup(ip_pack->ip_hdr.dest, ip_pack->eth_hdr.dest); |
| 239 |
+ } |
|
| 240 |
+ } |
|
| 229 | 241 |
// destination is not in own subnet |
| 230 |
- else |
|
| 242 |
+ else {
|
|
| 243 |
+ // broadcast |
|
| 244 |
+ if (ip_pack->ip_hdr.dest[0] == 0xFF && |
|
| 245 |
+ ip_pack->ip_hdr.dest[1] == 0xFF && |
|
| 246 |
+ ip_pack->ip_hdr.dest[2] == 0xFF && |
|
| 247 |
+ ip_pack->ip_hdr.dest[3] == 0xFF) {
|
|
| 248 |
+ mac_cpy(ip_pack->eth_hdr.dest, "\xFF\xFF\xFF\xFF\xFF\xFF"); |
|
| 249 |
+ i = 0; // MAC is available |
|
| 250 |
+ } |
|
| 251 |
+ // unicast |
|
| 252 |
+ else {
|
|
| 231 | 253 |
// lookup MAC address of default gateway |
| 232 | 254 |
i = arp_lookup(config_ip.gw, ip_pack->eth_hdr.dest); |
| 255 |
+ } |
|
| 256 |
+ } |
|
| 233 | 257 |
|
| 234 | 258 |
// MAC available |
| 235 | 259 |
if (i == 0x00) {
|
| 236 |
- // sent IP packet |
|
| 260 |
+ // send IP packet |
|
| 237 | 261 |
ip_pack->eth_hdr.type = htons(0x0800); // ethernet packet type: IP |
| 238 | 262 |
ethernet_send(ip_pack, sz); |
| 239 | 263 |
return; |
| 240 | 264 |