--- BasiliskII/src/AmigaOS/ether_amiga.cpp 2000/04/10 18:52:35 1.4 +++ BasiliskII/src/AmigaOS/ether_amiga.cpp 2001/07/15 02:34:23 1.10 @@ -1,7 +1,7 @@ /* * ether_amiga.cpp - Ethernet device driver, AmigaOS specific stuff * - * Basilisk II (C) 1997-2000 Christian Bauer + * Basilisk II (C) 1997-2001 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -116,11 +116,11 @@ static int16 send_to_proc(uint32 what, u * Initialization */ -void EtherInit(void) +bool ether_init(void) { // Do nothing if no Ethernet device specified if (PrefsFindString("ether") == NULL) - return; + return false; // Initialize protocol list NewList(&prot_list); @@ -151,8 +151,7 @@ void EtherInit(void) goto open_error; // Everything OK - net_open = true; - return; + return true; open_error: net_proc = NULL; @@ -160,6 +159,7 @@ open_error: DeleteMsgPort(reply_port); reply_port = NULL; } + return false; } @@ -167,7 +167,7 @@ open_error: * Deinitialization */ -void EtherExit(void) +void ether_exit(void) { // Stop process if (net_proc) { @@ -188,10 +188,10 @@ void EtherExit(void) * Reset */ -void EtherReset(void) +void ether_reset(void) { // Remove all protocols - if (net_open) + if (net_proc) send_to_proc(MSG_CLEANUP); } @@ -346,6 +346,8 @@ static __saveds __regargs LONG copy_from static __saveds void net_func(void) { + const char *str; + BYTE od_error; struct MsgPort *write_port = NULL, *control_port = NULL; struct IOSana2Req *write_io = NULL, *control_io = NULL; bool opened = false; @@ -388,13 +390,41 @@ static __saveds void net_func(void) // Parse device name char dev_name[256]; ULONG dev_unit; - if (sscanf(PrefsFindString("ether"), "%[^/]/%ld", dev_name, &dev_unit) < 2) + + str = PrefsFindString("ether"); + if (str) { + const char *FirstSlash = strchr(str, '/'); + const char *LastSlash = strrchr(str, '/'); + + if (FirstSlash && FirstSlash && FirstSlash != LastSlash) { + + // Device name contains path, i.e. "Networks/xyzzy.device" + const char *lp = str; + char *dp = dev_name; + + while (lp != LastSlash) + *dp++ = *lp++; + *dp = '\0'; + + if (strlen(dev_name) < 1) + goto quit; + + if (sscanf(LastSlash, "/%ld", &dev_unit) != 1) + goto quit; + } else { + if (sscanf(str, "%[^/]/%ld", dev_name, &dev_unit) != 2) + goto quit; + } + } else goto quit; // Open device control_io->ios2_BufferManagement = buffer_tags; - if (OpenDevice((UBYTE *)dev_name, dev_unit, (struct IORequest *)control_io, 0) || control_io->ios2_Req.io_Device == 0) + od_error = OpenDevice((UBYTE *)dev_name, dev_unit, (struct IORequest *)control_io, 0); + if (od_error != 0 || control_io->ios2_Req.io_Device == 0) { + printf("WARNING: OpenDevice(<%s>, unit=%d) returned error %d)\n", (UBYTE *)dev_name, dev_unit, od_error); goto quit; + } opened = true; // Is it Ethernet? @@ -548,10 +578,9 @@ static __saveds void net_func(void) } write_io->ios2_DataLength = len; - // Get destination address, set source address + // Get destination address uint32 hdr = ReadMacInt32(wds + 2); Mac2Host_memcpy(write_io->ios2_DstAddr, hdr, 6); - Host2Mac_memcpy(hdr + 6, ether_addr, 6); // Get packet type uint32 type = ReadMacInt16(hdr + 12);