File: interfaces.h

package info (click to toggle)
latd 1.34
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,904 kB
  • ctags: 1,090
  • sloc: cpp: 8,485; sh: 879; makefile: 89
file content (90 lines) | stat: -rw-r--r-- 2,775 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/******************************************************************************
    (c) 2002-2003 Christine Caulfield                 christine.caulfield@googlemail.com

    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
    the Free Software Foundation; either version 2 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
******************************************************************************/

// interfaces.h

// Abstract out the linux-specific ioctls and interface stuff.
//
// To port latd, all you should need to do is extend this class with
// your platform-specific functions.

// See linux-interface.cc for example implementation.

#include <cstring>
#include <iostream>

class LATinterfaces
{
 protected:

    // Save a copy of the protocol
    int protocol;

 public:

    LATinterfaces();
    virtual ~LATinterfaces();

    // Initialise the LAT protocol
    virtual int Start(int proto)=0;

    // Return a list of valid interface numbers and the count
    virtual void get_all_interfaces(int ifs[], int &num)=0;

    // Print the name of an interface
    virtual std::string ifname(int ifn) = 0;

    // Find an interface number by name
    virtual int find_interface(char *name)=0;

    // true if this class defines one FD for each active
    // interface, false if one fd is used for all interfaces.
    virtual bool one_fd_per_interface()=0;

    // Return the FD for this interface (will only be called once for
    // select if above returns false
    virtual int get_fd(int ifn)=0;

    // Send a packet to a given macaddr
    virtual int send_packet(int ifn, unsigned char macaddr[], unsigned char *data, int len)=0;

    // Receive a packet from a given FD (note FD not iface)
    virtual int recv_packet(int fd, int &ifn, unsigned char macaddr[], unsigned char *data, int maxlen, bool &more)=0;

    // Enable reception of LAT multicast messages
    virtual int set_lat_multicast(int ifn)=0;

    // Finished listening for LAT multicasts
    virtual int remove_lat_multicast(int ifn)=0;

    // Bind a socket to an interface
    virtual int bind_socket(int interface)=0;

    // Creates a platform-specifc interfaces class
    static LATinterfaces *Create();

    // Protocols we can Start()
    static int ProtoLAT;
    static int ProtoMOP;
};

// Make sure we have the packet types
#ifndef ETHERTYPE_LAT
#define ETHERTYPE_LAT 0x6004
#endif

#ifndef ETHERTYPE_MOPRC
#define ETHERTYPE_MOPRC 0x6002
#endif