ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/device-cygwin.C
Revision: 1.2
Committed: Tue Oct 14 03:22:09 2003 UTC (20 years, 7 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +6 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 /*
2 device-cygwin.C -- Stub for Cygwin environment
3 Copyright (C) 2003 Marc Lehmann <ocg@goof.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 // unfortunately, there is be no way to set MAC addresses under windows,
21 // and the default cipedrvr uses a different MAC address than we do,
22 // so this module tries to fix mac addresses in packets and arp packets.
23 // this is probably not very fast, but neither is cygwin nor poll.
24 //
25 // http://cipe-win32.sourceforge.net/
26
27 #include "config.h"
28
29 #include <stdio.h>
30 #include <errno.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34 #include <unistd.h>
35 #include <syslog.h>
36 #include <cstring>
37
38 #include "conf.h"
39 #include "util.h"
40
41 const char *
42 tap_device::info ()
43 {
44 return _("broken cygwin cipe device");
45 }
46
47 tap_device::tap_device ()
48 {
49 if ((fd = open (conf.ifname, O_RDWR)) < 0)
50 {
51 slog (L_CRIT, _("could not open %s: %s"), conf.ifname, strerror (errno));
52 exit (1);
53 }
54 }
55
56 tap_device::~tap_device ()
57 {
58 close (fd);
59 }
60
61 tap_packet *
62 tap_device::recv ()
63 {
64 tap_packet *pkt = new tap_packet;
65
66 pkt->len = read (fd, &((*pkt)[0]), MAX_MTU);
67
68 if (pkt->len <= 0)
69 {
70 slog (L_ERR, _("error while reading from %s %s: %s"),
71 info (), conf.ifname, strerror (errno));
72 free (pkt);
73 return 0;
74 }
75
76 id2mac (THISNODE->id, &((*pkt)[6]));
77
78 if (pkt->is_arp ())
79 {
80 if ((*pkt)[22] == 0x08) id2mac (THISNODE->id, &((*pkt)[22]));
81 if ((*pkt)[32] == 0x08) id2mac (THISNODE->id, &((*pkt)[32]));
82 }
83
84 return pkt;
85 }
86
87 void
88 tap_device::send (tap_packet *pkt)
89 {
90 (*pkt)[ 6] = 0x08; (*pkt)[ 7] = 0x00; (*pkt)[ 8] = 0x58;
91 (*pkt)[ 9] = 0x00; (*pkt)[10] = 0x00; (*pkt)[11] = 0x01;
92
93 if (pkt->is_arp ())
94 {
95 if ((*pkt)[22] == 0xfe && (*pkt)[27] == THISNODE->id)
96 memcpy (&(*pkt)[22], &(*pkt)[6], sizeof (mac));
97
98 if ((*pkt)[32] == 0xfe && (*pkt)[37] == THISNODE->id)
99 memcpy (&(*pkt)[32], &(*pkt)[6], sizeof (mac));
100 }
101
102 if (write (fd, &((*pkt)[0]), pkt->len) < 0)
103 slog (L_ERR, _("can't write to %s %s: %s"), info (), conf.ifname,
104 strerror (errno));
105 }