ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/router/arp.cpp
Revision: 1.3
Committed: 2008-01-01T09:40:34Z (16 years, 5 months ago) by gbeauche
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
Log Message:
Happy New Year!

File Contents

# Content
1 /*
2 * arp.cpp - ip router
3 *
4 * Basilisk II (C) 1997-2008 Christian Bauer
5 *
6 * Windows platform specific code copyright (C) Lauri Pesonen
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #include "sysdeps.h"
24 #include "cpu_emulation.h"
25 #include "prefs.h"
26 #include "ether_windows.h"
27 #include "ether.h"
28 #include "router.h"
29 #include "router_types.h"
30 #include "iphelp.h"
31 #include "arp.h"
32 #include "icmp.h"
33 #include "dump.h"
34
35
36 #if DEBUG
37 #pragma optimize("",off)
38 #endif
39
40 #include "debug.h"
41
42
43 // ARP queries can be replied immediately.
44
45 bool write_arp( arp_t *req, int len )
46 {
47 D(bug("write_arp() len=%d, htype=%d, ptype=%04x, opcode=%d, halen=%d, palen=%d\r\n",len, ntohs(req->htype), ntohs(req->ptype), ntohs(req->opcode), req->halen, req->palen));
48
49 start_icmp_listen();
50
51 bool result = false;
52
53 if( len >= sizeof(arp_t) &&
54 req->htype == htons(arp_hwtype_enet) &&
55 req->ptype == htons(mac_type_ip4) &&
56 req->opcode == htons(arp_request) &&
57 req->halen == 6 &&
58 req->palen == 4
59 )
60 {
61 if(memcmp( req->srcp, req->dstp, 4 ) == 0) {
62 // No reply. MacOS is making sure that there are no duplicate ip addresses.
63 // Update localhost (==Mac) ip address (needed by incoming icmp)
64 macos_ip_address = ntohl( *((uint32 *)&req->srcp[0]) );
65 D(bug("Mac ip: %02x %02x %02x %02x\r\n", req->srcp[0], req->srcp[1], req->srcp[2], req->srcp[3]));
66 } else {
67 arp_t arp;
68
69 D(bug("Source NIC: %02x %02x %02x %02x\r\n", req->srcp[0], req->srcp[1], req->srcp[2], req->srcp[3]));
70 D(bug("Dest NIC: %02x %02x %02x %02x\r\n", req->dstp[0], req->dstp[1], req->dstp[2], req->dstp[3]));
71
72 // memcpy( arp.mac.dest, req->mac.src, 6 );
73 memcpy( arp.mac.dest, ether_addr, 6 );
74 memcpy( arp.mac.src, router_mac_addr, 6 );
75 arp.mac.type = htons(mac_type_arp);
76 arp.htype = htons(arp_hwtype_enet);
77 arp.ptype = htons(mac_type_ip4);
78 arp.halen = 6;
79 arp.palen = 4;
80 arp.opcode = htons(arp_reply);
81 memcpy( arp.srch, router_mac_addr, 6 );
82 memcpy( arp.srcp, req->dstp, 4 );
83 // memcpy( arp.dsth, req->srch, 6 );
84 memcpy( arp.dsth, ether_addr, 6 );
85 memcpy( arp.dstp, req->srcp, 4 );
86
87 // Update here, too, just in case.
88 macos_ip_address = ntohl( *((uint32 *)&req->srcp[0]) );
89
90 enqueue_packet( (uint8 *)&arp, sizeof(arp) );
91 }
92 result = true;
93 }
94 return result;
95 }