1 /******************************************************************************
2     (c) 2002-2003 Christine Caulfield                 christine.caulfield@googlemail.com
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 ******************************************************************************/
14 
15 // interfaces.h
16 
17 // Abstract out the linux-specific ioctls and interface stuff.
18 //
19 // To port latd, all you should need to do is extend this class with
20 // your platform-specific functions.
21 
22 // See linux-interface.cc for example implementation.
23 
24 #include <cstring>
25 #include <iostream>
26 
27 class LATinterfaces
28 {
29  protected:
30 
31     // Save a copy of the protocol
32     int protocol;
33 
34  public:
35 
36     LATinterfaces();
37     virtual ~LATinterfaces();
38 
39     // Initialise the LAT protocol
40     virtual int Start(int proto)=0;
41 
42     // Return a list of valid interface numbers and the count
43     virtual void get_all_interfaces(int ifs[], int &num)=0;
44 
45     // Print the name of an interface
46     virtual std::string ifname(int ifn) = 0;
47 
48     // Find an interface number by name
49     virtual int find_interface(char *name)=0;
50 
51     // true if this class defines one FD for each active
52     // interface, false if one fd is used for all interfaces.
53     virtual bool one_fd_per_interface()=0;
54 
55     // Return the FD for this interface (will only be called once for
56     // select if above returns false
57     virtual int get_fd(int ifn)=0;
58 
59     // Send a packet to a given macaddr
60     virtual int send_packet(int ifn, unsigned char macaddr[], unsigned char *data, int len)=0;
61 
62     // Receive a packet from a given FD (note FD not iface)
63     virtual int recv_packet(int fd, int &ifn, unsigned char macaddr[], unsigned char *data, int maxlen, bool &more)=0;
64 
65     // Enable reception of LAT multicast messages
66     virtual int set_lat_multicast(int ifn)=0;
67 
68     // Finished listening for LAT multicasts
69     virtual int remove_lat_multicast(int ifn)=0;
70 
71     // Bind a socket to an interface
72     virtual int bind_socket(int interface)=0;
73 
74     // Creates a platform-specifc interfaces class
75     static LATinterfaces *Create();
76 
77     // Protocols we can Start()
78     static int ProtoLAT;
79     static int ProtoMOP;
80 };
81 
82 // Make sure we have the packet types
83 #ifndef ETHERTYPE_LAT
84 #define ETHERTYPE_LAT 0x6004
85 #endif
86 
87 #ifndef ETHERTYPE_MOPRC
88 #define ETHERTYPE_MOPRC 0x6002
89 #endif
90 
91