author | mickeyl <mickeyl> | 2003-10-02 20:53:58 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-02 20:53:58 (UTC) |
commit | 78b29c765dbe70faec614796a4d1421eaf0ec773 (patch) (unidiff) | |
tree | 2db88636d14a462d8538003bcd282f3140b1d5f6 | |
parent | e4fc6c395dd0a7400ed2cf76b3148dd7f535c2ea (diff) | |
download | opie-78b29c765dbe70faec614796a4d1421eaf0ec773.zip opie-78b29c765dbe70faec614796a4d1421eaf0ec773.tar.gz opie-78b29c765dbe70faec614796a4d1421eaf0ec773.tar.bz2 |
prepare dhcp decoding
-rw-r--r-- | libopie2/opienet/dhcp.h | 200 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 79 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 28 | ||||
-rw-r--r-- | libopie2/opienet/opienet.pro | 4 |
4 files changed, 309 insertions, 2 deletions
diff --git a/libopie2/opienet/dhcp.h b/libopie2/opienet/dhcp.h new file mode 100644 index 0000000..3f2f775 --- a/dev/null +++ b/libopie2/opienet/dhcp.h | |||
@@ -0,0 +1,200 @@ | |||
1 | /* dhcp.h | ||
2 | |||
3 | Protocol structures... */ | ||
4 | |||
5 | /* | ||
6 | * Copyright (c) 1995-2001 The Internet Software Consortium. | ||
7 | * All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in the | ||
17 | * documentation and/or other materials provided with the distribution. | ||
18 | * 3. Neither the name of The Internet Software Consortium nor the names | ||
19 | * of its contributors may be used to endorse or promote products derived | ||
20 | * from this software without specific prior written permission. | ||
21 | * | ||
22 | * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND | ||
23 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
24 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
26 | * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR | ||
27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
29 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
30 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
33 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
34 | * SUCH DAMAGE. | ||
35 | * | ||
36 | * This software has been written for the Internet Software Consortium | ||
37 | * by Ted Lemon in cooperation with Vixie Enterprises. To learn more | ||
38 | * about the Internet Software Consortium, see ``http://www.isc.org''. | ||
39 | * To learn more about Vixie Enterprises, see ``http://www.vix.com''. | ||
40 | */ | ||
41 | |||
42 | #ifndef DHCP_H | ||
43 | #define DHCP_H | ||
44 | |||
45 | #define DHCP_UDP_OVERHEAD (14 + /* Ethernet header */ \ | ||
46 | 20 + /* IP header */ \ | ||
47 | 8) /* UDP header */ | ||
48 | #define DHCP_SNAME_LEN 64 | ||
49 | #define DHCP_FILE_LEN 128 | ||
50 | #define DHCP_FIXED_NON_UDP236 | ||
51 | #define DHCP_FIXED_LEN (DHCP_FIXED_NON_UDP + DHCP_UDP_OVERHEAD) | ||
52 | /* Everything but options. */ | ||
53 | #define DHCP_MTU_MAX 1500 | ||
54 | #define DHCP_OPTION_LEN (DHCP_MTU_MAX - DHCP_FIXED_LEN) | ||
55 | |||
56 | #define BOOTP_MIN_LEN 300 | ||
57 | #define DHCP_MIN_LEN 548 | ||
58 | |||
59 | struct dhcp_packet { | ||
60 | u_int8_t op; /* 0: Message opcode/type */ | ||
61 | u_int8_t htype;/* 1: Hardware addr type (net/if_types.h) */ | ||
62 | u_int8_t hlen; /* 2: Hardware addr length */ | ||
63 | u_int8_t hops; /* 3: Number of relay agent hops from client */ | ||
64 | u_int32_t xid; /* 4: Transaction ID */ | ||
65 | u_int16_t secs; /* 8: Seconds since client started looking */ | ||
66 | u_int16_t flags;/* 10: Flag bits */ | ||
67 | struct in_addr ciaddr;/* 12: Client IP address (if already in use) */ | ||
68 | struct in_addr yiaddr;/* 16: Client IP address */ | ||
69 | struct in_addr siaddr;/* 18: IP address of next server to talk to */ | ||
70 | struct in_addr giaddr;/* 20: DHCP relay agent IP address */ | ||
71 | unsigned char chaddr [16];/* 24: Client hardware address */ | ||
72 | char sname [DHCP_SNAME_LEN];/* 40: Server name */ | ||
73 | char file [DHCP_FILE_LEN];/* 104: Boot filename */ | ||
74 | unsigned char options [DHCP_OPTION_LEN]; | ||
75 | /* 212: Optional parameters | ||
76 | (actual length dependent on MTU). */ | ||
77 | }; | ||
78 | |||
79 | /* BOOTP (rfc951) message types */ | ||
80 | #define BOOTREQUEST1 | ||
81 | #define BOOTREPLY2 | ||
82 | |||
83 | /* Possible values for flags field... */ | ||
84 | #define BOOTP_BROADCAST 32768L | ||
85 | |||
86 | /* Possible values for hardware type (htype) field... */ | ||
87 | #define HTYPE_ETHER1 /* Ethernet 10Mbps */ | ||
88 | #define HTYPE_IEEE802 6 /* IEEE 802.2 Token Ring...*/ | ||
89 | #define HTYPE_FDDI 8 /* FDDI... */ | ||
90 | |||
91 | /* Magic cookie validating dhcp options field (and bootp vendor | ||
92 | extensions field). */ | ||
93 | #define DHCP_OPTIONS_COOKIE"\143\202\123\143" | ||
94 | |||
95 | /* DHCP Option codes: */ | ||
96 | |||
97 | #define DHO_PAD 0 | ||
98 | #define DHO_SUBNET_MASK 1 | ||
99 | #define DHO_TIME_OFFSET 2 | ||
100 | #define DHO_ROUTERS 3 | ||
101 | #define DHO_TIME_SERVERS 4 | ||
102 | #define DHO_NAME_SERVERS 5 | ||
103 | #define DHO_DOMAIN_NAME_SERVERS 6 | ||
104 | #define DHO_LOG_SERVERS 7 | ||
105 | #define DHO_COOKIE_SERVERS 8 | ||
106 | #define DHO_LPR_SERVERS 9 | ||
107 | #define DHO_IMPRESS_SERVERS 10 | ||
108 | #define DHO_RESOURCE_LOCATION_SERVERS11 | ||
109 | #define DHO_HOST_NAME 12 | ||
110 | #define DHO_BOOT_SIZE 13 | ||
111 | #define DHO_MERIT_DUMP 14 | ||
112 | #define DHO_DOMAIN_NAME 15 | ||
113 | #define DHO_SWAP_SERVER 16 | ||
114 | #define DHO_ROOT_PATH 17 | ||
115 | #define DHO_EXTENSIONS_PATH 18 | ||
116 | #define DHO_IP_FORWARDING 19 | ||
117 | #define DHO_NON_LOCAL_SOURCE_ROUTING20 | ||
118 | #define DHO_POLICY_FILTER 21 | ||
119 | #define DHO_MAX_DGRAM_REASSEMBLY22 | ||
120 | #define DHO_DEFAULT_IP_TTL 23 | ||
121 | #define DHO_PATH_MTU_AGING_TIMEOUT24 | ||
122 | #define DHO_PATH_MTU_PLATEAU_TABLE25 | ||
123 | #define DHO_INTERFACE_MTU 26 | ||
124 | #define DHO_ALL_SUBNETS_LOCAL 27 | ||
125 | #define DHO_BROADCAST_ADDRESS 28 | ||
126 | #define DHO_PERFORM_MASK_DISCOVERY29 | ||
127 | #define DHO_MASK_SUPPLIER 30 | ||
128 | #define DHO_ROUTER_DISCOVERY 31 | ||
129 | #define DHO_ROUTER_SOLICITATION_ADDRESS32 | ||
130 | #define DHO_STATIC_ROUTES 33 | ||
131 | #define DHO_TRAILER_ENCAPSULATION34 | ||
132 | #define DHO_ARP_CACHE_TIMEOUT 35 | ||
133 | #define DHO_IEEE802_3_ENCAPSULATION36 | ||
134 | #define DHO_DEFAULT_TCP_TTL 37 | ||
135 | #define DHO_TCP_KEEPALIVE_INTERVAL38 | ||
136 | #define DHO_TCP_KEEPALIVE_GARBAGE39 | ||
137 | #define DHO_NIS_DOMAIN 40 | ||
138 | #define DHO_NIS_SERVERS 41 | ||
139 | #define DHO_NTP_SERVERS 42 | ||
140 | #define DHO_VENDOR_ENCAPSULATED_OPTIONS43 | ||
141 | #define DHO_NETBIOS_NAME_SERVERS44 | ||
142 | #define DHO_NETBIOS_DD_SERVER 45 | ||
143 | #define DHO_NETBIOS_NODE_TYPE 46 | ||
144 | #define DHO_NETBIOS_SCOPE 47 | ||
145 | #define DHO_FONT_SERVERS 48 | ||
146 | #define DHO_X_DISPLAY_MANAGER 49 | ||
147 | #define DHO_DHCP_REQUESTED_ADDRESS50 | ||
148 | #define DHO_DHCP_LEASE_TIME 51 | ||
149 | #define DHO_DHCP_OPTION_OVERLOAD52 | ||
150 | #define DHO_DHCP_MESSAGE_TYPE 53 | ||
151 | #define DHO_DHCP_SERVER_IDENTIFIER54 | ||
152 | #define DHO_DHCP_PARAMETER_REQUEST_LIST55 | ||
153 | #define DHO_DHCP_MESSAGE 56 | ||
154 | #define DHO_DHCP_MAX_MESSAGE_SIZE57 | ||
155 | #define DHO_DHCP_RENEWAL_TIME 58 | ||
156 | #define DHO_DHCP_REBINDING_TIME 59 | ||
157 | #define DHO_VENDOR_CLASS_IDENTIFIER60 | ||
158 | #define DHO_DHCP_CLIENT_IDENTIFIER61 | ||
159 | #define DHO_NWIP_DOMAIN_NAME 62 | ||
160 | #define DHO_NWIP_SUBOPTIONS 63 | ||
161 | #define DHO_USER_CLASS 77 | ||
162 | #define DHO_FQDN 81 | ||
163 | #define DHO_DHCP_AGENT_OPTIONS 82 | ||
164 | #define DHO_SUBNET_SELECTION 118 /* RFC3011! */ | ||
165 | /* The DHO_AUTHENTICATE option is not a standard yet, so I've | ||
166 | allocated an option out of the "local" option space for it on a | ||
167 | temporary basis. Once an option code number is assigned, I will | ||
168 | immediately and shamelessly break this, so don't count on it | ||
169 | continuing to work. */ | ||
170 | #define DHO_AUTHENTICATE 210 | ||
171 | |||
172 | #define DHO_END 255 | ||
173 | |||
174 | /* DHCP message types. */ | ||
175 | #define DHCPDISCOVER1 | ||
176 | #define DHCPOFFER2 | ||
177 | #define DHCPREQUEST3 | ||
178 | #define DHCPDECLINE4 | ||
179 | #define DHCPACK 5 | ||
180 | #define DHCPNAK 6 | ||
181 | #define DHCPRELEASE7 | ||
182 | #define DHCPINFORM8 | ||
183 | |||
184 | /* Relay Agent Information option subtypes: */ | ||
185 | #define RAI_CIRCUIT_ID1 | ||
186 | #define RAI_REMOTE_ID2 | ||
187 | #define RAI_AGENT_ID3 | ||
188 | |||
189 | /* FQDN suboptions: */ | ||
190 | #define FQDN_NO_CLIENT_UPDATE 1 | ||
191 | #define FQDN_SERVER_UPDATE 2 | ||
192 | #define FQDN_ENCODED 3 | ||
193 | #define FQDN_RCODE1 4 | ||
194 | #define FQDN_RCODE2 5 | ||
195 | #define FQDN_HOSTNAME 6 | ||
196 | #define FQDN_DOMAINNAME 7 | ||
197 | #define FQDN_FQDN 8 | ||
198 | #define FQDN_SUBOPTION_COUNT 8 | ||
199 | |||
200 | #endif \ No newline at end of file | ||
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 1de7124..cc8ce7f 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -357,4 +357,5 @@ OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QOb | |||
357 | } | 357 | } |
358 | 358 | ||
359 | |||
359 | OUDPPacket::~OUDPPacket() | 360 | OUDPPacket::~OUDPPacket() |
360 | { | 361 | { |
@@ -362,4 +363,46 @@ OUDPPacket::~OUDPPacket() | |||
362 | 363 | ||
363 | 364 | ||
365 | int OUDPPacket::fromPort() const | ||
366 | { | ||
367 | return _udphdr->source; | ||
368 | } | ||
369 | |||
370 | |||
371 | int OUDPPacket::toPort() const | ||
372 | { | ||
373 | return _udphdr->dest; | ||
374 | } | ||
375 | |||
376 | |||
377 | int OUDPPacket::length() const | ||
378 | { | ||
379 | return _udphdr->len; | ||
380 | } | ||
381 | |||
382 | |||
383 | int OUDPPacket::checksum() const | ||
384 | { | ||
385 | return _udphdr->check; | ||
386 | } | ||
387 | |||
388 | |||
389 | /*====================================================================================== | ||
390 | * ODHCPPacket | ||
391 | *======================================================================================*/ | ||
392 | |||
393 | |||
394 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | ||
395 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | ||
396 | |||
397 | { | ||
398 | qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." ); | ||
399 | } | ||
400 | |||
401 | |||
402 | ODHCPPacket::~ODHCPPacket() | ||
403 | { | ||
404 | } | ||
405 | |||
406 | |||
364 | /*====================================================================================== | 407 | /*====================================================================================== |
365 | * OTCPPacket | 408 | * OTCPPacket |
@@ -374,4 +417,5 @@ OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QOb | |||
374 | } | 417 | } |
375 | 418 | ||
419 | |||
376 | OTCPPacket::~OTCPPacket() | 420 | OTCPPacket::~OTCPPacket() |
377 | { | 421 | { |
@@ -379,4 +423,39 @@ OTCPPacket::~OTCPPacket() | |||
379 | 423 | ||
380 | 424 | ||
425 | int OTCPPacket::fromPort() const | ||
426 | { | ||
427 | return _tcphdr->source; | ||
428 | } | ||
429 | |||
430 | |||
431 | int OTCPPacket::toPort() const | ||
432 | { | ||
433 | return _tcphdr->dest; | ||
434 | } | ||
435 | |||
436 | |||
437 | int OTCPPacket::seq() const | ||
438 | { | ||
439 | return _tcphdr->seq; | ||
440 | } | ||
441 | |||
442 | |||
443 | int OTCPPacket::ack() const | ||
444 | { | ||
445 | return _tcphdr->ack_seq; | ||
446 | } | ||
447 | |||
448 | |||
449 | int OTCPPacket::window() const | ||
450 | { | ||
451 | return _tcphdr->window; | ||
452 | } | ||
453 | |||
454 | |||
455 | int OTCPPacket::checksum() const | ||
456 | { | ||
457 | return _tcphdr->check; | ||
458 | } | ||
459 | |||
381 | /*====================================================================================== | 460 | /*====================================================================================== |
382 | * OPrismHeaderPacket | 461 | * OPrismHeaderPacket |
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 9119972..0c9e7da 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -56,5 +56,8 @@ extern "C" // work around a bpf/pcap conflict in recent headers | |||
56 | /* OPIE */ | 56 | /* OPIE */ |
57 | #include <opie2/onetutils.h> | 57 | #include <opie2/onetutils.h> |
58 | |||
59 | /* Custom Network Includes */ | ||
58 | #include "802_11_user.h" | 60 | #include "802_11_user.h" |
61 | #include "dhcp.h" | ||
59 | 62 | ||
60 | /* TYPEDEFS */ | 63 | /* TYPEDEFS */ |
@@ -478,4 +481,6 @@ class OUDPPacket : public QObject | |||
478 | int fromPort() const; | 481 | int fromPort() const; |
479 | int toPort() const; | 482 | int toPort() const; |
483 | int length() const; | ||
484 | int checksum() const; | ||
480 | 485 | ||
481 | private: | 486 | private: |
@@ -484,4 +489,20 @@ class OUDPPacket : public QObject | |||
484 | 489 | ||
485 | /*====================================================================================== | 490 | /*====================================================================================== |
491 | * ODHCPPacket | ||
492 | *======================================================================================*/ | ||
493 | |||
494 | class ODHCPPacket : public QObject | ||
495 | { | ||
496 | Q_OBJECT | ||
497 | |||
498 | public: | ||
499 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); | ||
500 | virtual ~ODHCPPacket(); | ||
501 | |||
502 | private: | ||
503 | const struct dhcp_packet* _dhcphdr; | ||
504 | }; | ||
505 | |||
506 | /*====================================================================================== | ||
486 | * OTCPPacket | 507 | * OTCPPacket |
487 | *======================================================================================*/ | 508 | *======================================================================================*/ |
@@ -497,4 +518,8 @@ class OTCPPacket : public QObject | |||
497 | int fromPort() const; | 518 | int fromPort() const; |
498 | int toPort() const; | 519 | int toPort() const; |
520 | int seq() const; | ||
521 | int ack() const; | ||
522 | int window() const; | ||
523 | int checksum() const; | ||
499 | 524 | ||
500 | private: | 525 | private: |
@@ -511,5 +536,6 @@ class OTCPPacket : public QObject | |||
511 | * | 536 | * |
512 | * This class is the base of a high-level interface to the well known packet capturing | 537 | * This class is the base of a high-level interface to the well known packet capturing |
513 | * library libpcap. ... | 538 | * library libpcap. |
539 | * @see http://tcpdump.org | ||
514 | */ | 540 | */ |
515 | class OPacketCapturer : public QObject | 541 | class OPacketCapturer : public QObject |
diff --git a/libopie2/opienet/opienet.pro b/libopie2/opienet/opienet.pro index 93389db..7a7adde 100644 --- a/libopie2/opienet/opienet.pro +++ b/libopie2/opienet/opienet.pro | |||
@@ -2,5 +2,7 @@ TEMPLATE = lib | |||
2 | CONFIG += qt warn_on debug | 2 | CONFIG += qt warn_on debug |
3 | DESTDIR = $(OPIEDIR)/lib | 3 | DESTDIR = $(OPIEDIR)/lib |
4 | HEADERS = omanufacturerdb.cpp \ | 4 | HEADERS = 802_11_user.h \ |
5 | dhcp.h \ | ||
6 | omanufacturerdb.cpp \ | ||
5 | onetutils.cpp \ | 7 | onetutils.cpp \ |
6 | onetwork.h \ | 8 | onetwork.h \ |