ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/ether.cpp
(Generate patch)

Comparing BasiliskII/src/ether.cpp (file contents):
Revision 1.6 by cebix, 2001-07-13T15:39:21Z vs.
Revision 1.9 by cebix, 2002-01-15T14:58:32Z

# Line 1 | Line 1
1   /*
2   *  ether.cpp - Ethernet device driver
3   *
4 < *  Basilisk II (C) 1997-2001 Christian Bauer
4 > *  Basilisk II (C) 1997-2002 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 56 | Line 56 | using std::map;
56   #define MONITOR 0
57  
58  
59 + #ifdef __BEOS__
60 + #define CLOSESOCKET closesocket
61 + #else
62 + #define CLOSESOCKET close
63 + #endif
64 +
65 +
66   // Global variables
67   uint8 ether_addr[6];                    // Ethernet address (set by ether_init())
68   static bool net_open = false;   // Flag: initialization succeeded, network device open (set by EtherInit())
# Line 101 | Line 108 | void EtherInit(void)
108                  sa.sin_port = htons(udp_port);
109                  if (bind(udp_socket, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
110                          perror("bind");
111 <                        close(udp_socket);
111 >                        CLOSESOCKET(udp_socket);
112                          udp_socket = -1;
113                          return;
114                  }
# Line 130 | Line 137 | void EtherInit(void)
137  
138                  // Set socket options
139                  int on = 1;
140 + #ifdef __BEOS__
141 +                setsockopt(udp_socket, SOL_SOCKET, SO_NONBLOCK, &on, sizeof(on));
142 + #else
143                  setsockopt(udp_socket, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
144                  ioctl(udp_socket, FIONBIO, &on);
145 + #endif
146  
147                  // Start thread for packet reception
148                  if (!ether_start_udp_thread(udp_socket)) {
149 <                        close(udp_socket);
149 >                        CLOSESOCKET(udp_socket);
150                          udp_socket = -1;
151                          return;
152                  }
# Line 159 | Line 170 | void EtherExit(void)
170                  if (udp_tunnel) {
171                          if (udp_socket >= 0) {
172                                  ether_stop_udp_thread();
173 <                                close(udp_socket);
173 >                                CLOSESOCKET(udp_socket);
174                                  udp_socket = -1;
175                          }
176                  } else
# Line 182 | Line 193 | void EtherReset(void)
193  
194  
195   /*
196 < *  Check whether Ethernet address is AppleTalk broadcast address
196 > *  Check whether Ethernet address is AppleTalk or Ethernet broadcast address
197   */
198  
199   static inline bool is_apple_talk_broadcast(uint8 *p)
# Line 191 | Line 202 | static inline bool is_apple_talk_broadca
202              && p[3] == 0xff && p[4] == 0xff && p[5] == 0xff;
203   }
204  
205 + static inline bool is_ethernet_broadcast(uint8 *p)
206 + {
207 +        return p[0] == 0xff && p[1] == 0xff && p[2] == 0xff
208 +            && p[3] == 0xff && p[4] == 0xff && p[5] == 0xff;
209 + }
210 +
211  
212   /*
213   *  Driver Open() routine
# Line 290 | Line 307 | int16 EtherControl(uint32 pb, uint32 dce
307  
308                  case kENetWrite: {              // Transmit raw Ethernet packet
309                          uint32 wds = ReadMacInt32(pb + ePointer);
310 <                        D(bug(" EtherWrite\n"));
310 >                        D(bug(" EtherWrite "));
311                          if (ReadMacInt16(wds) < 14)
312                                  return eLenErr; // Header incomplete
313 +
314 +                        // Set source address
315 +                        uint32 hdr = ReadMacInt32(wds + 2);
316 +                        Host2Mac_memcpy(hdr + 6, ether_addr, 6);
317 +                        D(bug("to %08x%04x, type %04x\n", ReadMacInt32(hdr), ReadMacInt16(hdr + 4), ReadMacInt16(hdr + 12)));
318 +
319                          if (net_open) {
320   #if SUPPORTS_UDP_TUNNEL
321                                  if (udp_tunnel) {
# Line 301 | Line 324 | int16 EtherControl(uint32 pb, uint32 dce
324                                          uint8 packet[1514];
325                                          int len = ether_wds_to_buffer(wds, packet);
326  
327 <                                        // Set source address and extract destination address
305 <                                        memcpy(packet + 6, ether_addr, 6);
327 >                                        // Extract destination address
328                                          uint32 dest_ip;
329                                          if (packet[0] == 'B' && packet[1] == '2')
330                                                  dest_ip = (packet[2] << 24) | (packet[3] << 16) | (packet[4] << 8) | packet[5];
331 <                                        else if (is_apple_talk_broadcast(packet))
331 >                                        else if (is_apple_talk_broadcast(packet) || is_ethernet_broadcast(packet))
332                                                  dest_ip = INADDR_BROADCAST;
333                                          else
334                                                  return eMultiErr;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines