~ubuntu-branches/ubuntu/trusty/xprobe/trusty

« back to all changes in this revision

Viewing changes to libs-external/USI++/src/Layer2.cc

  • Committer: Bazaar Package Importer
  • Author(s): Richard Atterer
  • Date: 2005-02-22 22:54:24 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050222225424-6cqy8rr45pkna819
Tags: 0.2.2-1
New upstream version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*** This Programs/Libraries are (C)opyright by Sebastian Krahmer.
 
2
 *** You may use it under the terms of the GPL. You should have
 
3
 *** already received the file COPYING that shows you your rights.
 
4
 *** Please look at COPYING for further license-details.
 
5
 ***  
 
6
 *** THERE IS ABSOLUTELY NO WARRANTY. SO YOU USE IT AT YOUR OWN RISK.
 
7
 *** IT WAS WRITTEN IN THE HOPE THAT IT WILL BE USEFULL. I AM NOT RESPONSIBLE
 
8
 *** FOR ANY DAMAGE YOU MAYBE GET DUE TO USING MY PROGRAMS.
 
9
 ***/
 
10
#include "config.h"
 
11
#include "usi++/usi-structs.h"
 
12
#include "usi++/RX.h"
 
13
#include "usi++/TX.h"
 
14
#include "usi++/Layer2.h"
 
15
#include "usi++/datalink.h"
 
16
#include "usi++/TX_IP.h"
 
17
#include <stdio.h>
 
18
#include <string.h>
 
19
 
 
20
namespace usipp {
 
21
 
 
22
Layer2::Layer2(RX *r, TX *t)
 
23
{
 
24
        if (!r)
 
25
                d_rx = new Pcap;
 
26
        else
 
27
                d_rx = r;
 
28
                
 
29
        if (!t)
 
30
                d_tx = new TX_IP;
 
31
        else
 
32
                d_tx = t;
 
33
}
 
34
 
 
35
Layer2::Layer2(const Layer2& rhs) {
 
36
        d_rx = new Pcap;
 
37
        d_tx = new TX_IP;
 
38
        
 
39
}
 
40
 
 
41
Layer2::~Layer2() 
 
42
{
 
43
    if (d_rx) {
 
44
            delete d_rx;
 
45
                        d_rx = NULL;
 
46
        }
 
47
 
 
48
    if (d_tx) {
 
49
            delete d_tx;
 
50
                        d_tx=NULL;
 
51
        }
 
52
}
 
53
 
 
54
int Layer2::sendpack(void *buf, size_t len, struct sockaddr *s)
 
55
{
 
56
        return d_tx->sendpack(buf, len, s);
 
57
}
 
58
 
 
59
// delegate sniff request to the receiver
 
60
int Layer2::sniffpack(void *buf, size_t len)
 
61
{
 
62
        return d_rx->sniffpack(buf, len);
 
63
}
 
64
 
 
65
int Layer2::setfilter(char *fstring)
 
66
{
 
67
        return d_rx->setfilter(fstring);
 
68
}
 
69
 
 
70
int Layer2::init_device(char *dev, int p, size_t snaplen)
 
71
{
 
72
        return d_rx->init_device(dev, p, snaplen);
 
73
}
 
74
 
 
75
int Layer2::timeout(struct timeval tv)
 
76
{
 
77
        if (d_rx) return d_rx->timeout(tv);
 
78
        if (d_tx) return d_tx->timeout(tv);
 
79
    return -1;
 
80
}
 
81
 
 
82
bool Layer2::timeout()
 
83
{
 
84
        if (d_rx) return d_rx->timeout();
 
85
        if (d_tx) return d_tx->timeout();
 
86
    return false;
 
87
}
 
88
 
 
89
Layer2& Layer2::operator=(const Layer2 &rhs )
 
90
{
 
91
        if (this == &rhs)
 
92
                return *this;
 
93
        d_rx = new Pcap;
 
94
        d_tx = new TX_IP;
 
95
        return *this;
 
96
}
 
97
 
 
98
} // namespace usipp