forked from signal11/PlayCap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
InterfaceWindow.cpp
148 lines (111 loc) · 4.78 KB
/
InterfaceWindow.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**************************************************************************
Window for Selecting a Network Interface
Copyright 2009 Alan Ott, Signal 11 Software
10-18-2006
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 3 of the License, or
(at your option) 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***************************************************************************/
#include "InterfaceWindow.h"
#include <FXPNGIcon.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <netinet/in.h> // sockaddr_in
#include <arpa/inet.h> // inet_ntoa()
#endif
#include <iostream>
using std::cout;
using std::endl;
#include "tango/network-transmit-receive.png.h"
#include "tango/network-transmit-receive-48.png.h"
FXDEFMAP(InterfaceWindow) InterfaceWindowMap[] = {
FXMAPFUNC(SEL_TIMEOUT, InterfaceWindow::ID_TIME, InterfaceWindow::onTimeout),
FXMAPFUNC(SEL_COMMAND, InterfaceWindow::ID_CAPTURE, InterfaceWindow::onCapture),
};
FXIMPLEMENT(InterfaceWindow, FXVerticalFrame, InterfaceWindowMap, ARRAYNUMBER(InterfaceWindowMap));
InterfaceWindow::InterfaceWindow(FXComposite *parent, pcap_if_t *ifaces, FXString title, FXString buttonCaption)
: FXVerticalFrame(parent),
interfaces(ifaces)
{
selected_interface = NULL;
FXPNGIcon *capture_icon = new FXPNGIcon(getApp(), networktransmitreceive);
FXPNGIcon *capture_icon_48 = new FXPNGIcon(getApp(), networktransmitreceive48);
FXLabel *label = new FXLabel(this, title, capture_icon_48);
label->setFont(new FXFont(getApp(), "Helvetica", 14, FXFont::Bold));
new FXWindow(new FXVerticalFrame(this));
// Create the GUI.
#ifndef WIN32
//FXMatrix *matrix = new FXMatrix(this, 2, MATRIX_BY_COLUMNS);
#else
FXMatrix *matrix = new FXMatrix(this,2, MATRIX_BY_COLUMNS);
#endif
pcap_if_t *itr = interfaces;
while (itr) {
// Find the IP addr of this device (if any).
FXString ip_addr;
pcap_addr *addr = itr->addresses;
while (addr) {
if (addr->addr->sa_family == AF_INET) {
sockaddr_in *inaddr = (sockaddr_in*) addr->addr;
ip_addr = inet_ntoa(inaddr->sin_addr);
break;
}
addr = addr->next;
}
#ifndef WIN32
// Unix Platforms
FXHorizontalFrame *outerHF = new FXHorizontalFrame(this, LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0, 2*DEFAULT_SPACING, 0);
FXVerticalFrame *vf = new FXVerticalFrame(outerHF, LAYOUT_FILL_X, 0,0,0,0, 0,0,0,DEFAULT_SPACING);
FXHorizontalFrame *hf = new FXHorizontalFrame(vf, LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0);
FXLabel *l = new FXLabel(hf, itr->name);
l->setFont(new FXFont(getApp(), "Helvetica", 14, FXFont::Bold));
new FXLabel(hf, ip_addr, NULL, LABEL_NORMAL|LAYOUT_CENTER_Y|LAYOUT_RIGHT);
new FXLabel(vf, (itr->description)? itr->description: "");
#else
// Windows
FXHorizontalFrame *outerHF = new FXHorizontalFrame(this, LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0, 2*DEFAULT_SPACING, 0);
FXVerticalFrame *vf = new FXVerticalFrame(outerHF, LAYOUT_FILL_X, 0,0,0,0, 0,0,0,DEFAULT_SPACING);
//FXHorizontalFrame *hf = new FXHorizontalFrame(vf, LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0);
//FXLabel *l = new FXLabel(hf, itr->name);
//l->setFont(new FXFont(getApp(), "Helvetica", 14, FXFont::Bold));
new FXLabel(vf, (itr->description)? itr->description: "");
new FXLabel(vf, ip_addr, NULL, LABEL_NORMAL|LAYOUT_CENTER_Y);
//new FXLabel(matrix, (itr->description)? itr->description: "");
//new FXLabel(matrix, ip_addr, NULL, LABEL_NORMAL|LAYOUT_CENTER_Y|LAYOUT_RIGHT);
//FXHorizontalFrame *outerHF = new FXHorizontalFrame(this, LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0, 2*DEFAULT_SPACING, 0);
#endif
FXButton *btn = new FXButton(outerHF, buttonCaption, capture_icon, this, ID_CAPTURE, BUTTON_NORMAL|LAYOUT_CENTER_Y);
btn->setUserData(itr);
new FXSeparator(this);
itr = itr->next;
}
//getApp()->addTimeout(this, ID_TIME, 250);
}
InterfaceWindow::~InterfaceWindow()
{
cout << "removing InterfaceWindow Timer" << endl;
//getApp()->removeTimeout(this, ID_TIME);
}
long
InterfaceWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr)
{
//getApp()->addTimeout(this, ID_TIME, 250);
return 1;
}
long
InterfaceWindow::onCapture(FXObject *sender, FXSelector sel, void *ptr)
{
cout << "onCapture" << endl;
FXId *sender_id = (FXId*) sender;
selected_interface = (pcap_if_t *) sender_id->getUserData();
this->getParent()->handle(this, MKUINT(FXDialogBox::ID_ACCEPT,SEL_COMMAND), NULL);
return 1;
}