author | zecke <zecke> | 2004-03-13 19:51:45 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-13 19:51:45 (UTC) |
commit | 6d08277737e22b7a1527124623f3571969073ddf (patch) (side-by-side diff) | |
tree | 4129e674e21df767b31299e873dd44e33a308e1b /libopie2/opienet | |
parent | 8e28911f7199f4450ac5eef09482069f9b9caea2 (diff) | |
download | opie-6d08277737e22b7a1527124623f3571969073ddf.zip opie-6d08277737e22b7a1527124623f3571969073ddf.tar.gz opie-6d08277737e22b7a1527124623f3571969073ddf.tar.bz2 |
Move XML class to internal PIM
Add namespaces!!!
Opie::Core and Opie::Core::Private
Opie::Net and Opie::Net::Private
Opie::Ui and Opie::Ui::Private
Opie::MM and Opie::MM::Private
Opie::DB and Opie::DB::Private
PIM classes are not yet converted because we will do other work
on it as well
-rw-r--r-- | libopie2/opienet/802_11_user.h | 1 | ||||
-rw-r--r-- | libopie2/opienet/dhcp.h | 2 | ||||
-rw-r--r-- | libopie2/opienet/odebugmapper.cpp | 10 | ||||
-rw-r--r-- | libopie2/opienet/odebugmapper.h | 10 | ||||
-rw-r--r-- | libopie2/opienet/omanufacturerdb.cpp | 7 | ||||
-rw-r--r-- | libopie2/opienet/omanufacturerdb.h | 8 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 9 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 15 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 9 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 31 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 8 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 52 | ||||
-rw-r--r-- | libopie2/opienet/ostation.cpp | 8 | ||||
-rw-r--r-- | libopie2/opienet/ostation.h | 9 |
14 files changed, 176 insertions, 3 deletions
diff --git a/libopie2/opienet/802_11_user.h b/libopie2/opienet/802_11_user.h index 7ae27c5..1a9a7a0 100644 --- a/libopie2/opienet/802_11_user.h +++ b/libopie2/opienet/802_11_user.h @@ -362,97 +362,98 @@ struct ieee_802_11_mgmt_body { // u_int16_t auth_trans_seq_num; // struct challenge_t challenge; u_int16_t capability_info; // struct ssid_t ssid; // struct rates_t rates; // struct ds_t ds; // struct cf_t cf; // struct fh_t fh; // struct tim_t tim; }; /* a 802.11 value */ struct val_80211 { unsigned int did; unsigned short status, len; unsigned int data; }; /* header attached during prism monitor mode */ struct prism_hdr { unsigned int msgcode, msglen; char devname[16]; struct val_80211 hosttime, mactime, channel, rssi, sq, signal, noise, rate, istx, frmlen; }; struct ieee_802_11_data_body { //FIXME }; struct ieee_802_11_control_body { //FIXME }; struct ctrl_rts_t { u_int16_t fc; u_int16_t duration; u_int8_t ra[6]; u_int8_t ta[6]; u_int8_t fcs[4]; }; #define CTRL_RTS_LEN (2+2+6+6+4) struct ctrl_cts_t { u_int16_t fc; u_int16_t duration; u_int8_t ra[6]; u_int8_t fcs[4]; }; #define CTRL_CTS_LEN (2+2+6+4) struct ctrl_ack_t { u_int16_t fc; u_int16_t duration; u_int8_t ra[6]; u_int8_t fcs[4]; }; #define CTRL_ACK_LEN (2+2+6+4) struct ctrl_ps_poll_t { u_int16_t fc; u_int16_t aid; u_int8_t bssid[6]; u_int8_t ta[6]; u_int8_t fcs[4]; }; #define CTRL_PS_POLL_LEN (2+2+6+6+4) struct ctrl_end_t { u_int16_t fc; u_int16_t duration; u_int8_t ra[6]; u_int8_t bssid[6]; u_int8_t fcs[4]; }; #define CTRL_END_LEN (2+2+6+6+4) struct ctrl_end_ack_t { u_int16_t fc; u_int16_t duration; u_int8_t ra[6]; u_int8_t bssid[6]; u_int8_t fcs[4]; }; #define CTRL_END_ACK_LEN (2+2+6+6+4) #define IV_IV(iv) ((iv) & 0xFFFFFF) #define IV_PAD(iv) (((iv) >> 24) & 0x3F) #define IV_KEYID(iv) (((iv) >> 30) & 0x03) + #endif diff --git a/libopie2/opienet/dhcp.h b/libopie2/opienet/dhcp.h index 368e375..6ba4c53 100644 --- a/libopie2/opienet/dhcp.h +++ b/libopie2/opienet/dhcp.h @@ -1,201 +1,203 @@ /* dhcp.h Protocol structures... */ /* * Copyright (c) 1995-2001 The Internet Software Consortium. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of The Internet Software Consortium nor the names * of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * This software has been written for the Internet Software Consortium * by Ted Lemon in cooperation with Vixie Enterprises. To learn more * about the Internet Software Consortium, see ``http://www.isc.org''. * To learn more about Vixie Enterprises, see ``http://www.vix.com''. */ #ifndef DHCP_H #define DHCP_H + #define DHCP_UDP_OVERHEAD (14 + /* Ethernet header */ \ 20 + /* IP header */ \ 8) /* UDP header */ #define DHCP_SNAME_LEN 64 #define DHCP_FILE_LEN 128 #define DHCP_FIXED_NON_UDP 236 #define DHCP_FIXED_LEN (DHCP_FIXED_NON_UDP + DHCP_UDP_OVERHEAD) /* Everything but options. */ #define DHCP_MTU_MAX 1500 #define DHCP_OPTION_LEN (DHCP_MTU_MAX - DHCP_FIXED_LEN) #define BOOTP_MIN_LEN 300 #define DHCP_MIN_LEN 548 struct dhcp_packet { u_int8_t op; /* 0: Message opcode/type */ u_int8_t htype; /* 1: Hardware addr type (net/if_types.h) */ u_int8_t hlen; /* 2: Hardware addr length */ u_int8_t hops; /* 3: Number of relay agent hops from client */ u_int32_t xid; /* 4: Transaction ID */ u_int16_t secs; /* 8: Seconds since client started looking */ u_int16_t flags; /* 10: Flag bits */ struct in_addr ciaddr; /* 12: Client IP address (if already in use) */ struct in_addr yiaddr; /* 16: Client IP address */ struct in_addr siaddr; /* 18: IP address of next server to talk to */ struct in_addr giaddr; /* 20: DHCP relay agent IP address */ unsigned char chaddr [16]; /* 24: Client hardware address */ char sname [DHCP_SNAME_LEN]; /* 40: Server name */ char file [DHCP_FILE_LEN]; /* 104: Boot filename */ unsigned char options [DHCP_OPTION_LEN]; /* 212: Optional parameters (actual length dependent on MTU). */ }; /* BOOTP (rfc951) message types */ #define BOOTREQUEST 1 #define BOOTREPLY 2 /* Possible values for flags field... */ #define BOOTP_BROADCAST 32768L /* Possible values for hardware type (htype) field... */ #define HTYPE_ETHER 1 /* Ethernet 10Mbps */ #define HTYPE_IEEE802 6 /* IEEE 802.2 Token Ring... */ #define HTYPE_FDDI 8 /* FDDI... */ /* Magic cookie validating dhcp options field (and bootp vendor extensions field). */ #define DHCP_OPTIONS_COOKIE "\143\202\123\143" /* DHCP Option codes: */ #define DHO_PAD 0 #define DHO_SUBNET_MASK 1 #define DHO_TIME_OFFSET 2 #define DHO_ROUTERS 3 #define DHO_TIME_SERVERS 4 #define DHO_NAME_SERVERS 5 #define DHO_DOMAIN_NAME_SERVERS 6 #define DHO_LOG_SERVERS 7 #define DHO_COOKIE_SERVERS 8 #define DHO_LPR_SERVERS 9 #define DHO_IMPRESS_SERVERS 10 #define DHO_RESOURCE_LOCATION_SERVERS 11 #define DHO_HOST_NAME 12 #define DHO_BOOT_SIZE 13 #define DHO_MERIT_DUMP 14 #define DHO_DOMAIN_NAME 15 #define DHO_SWAP_SERVER 16 #define DHO_ROOT_PATH 17 #define DHO_EXTENSIONS_PATH 18 #define DHO_IP_FORWARDING 19 #define DHO_NON_LOCAL_SOURCE_ROUTING 20 #define DHO_POLICY_FILTER 21 #define DHO_MAX_DGRAM_REASSEMBLY 22 #define DHO_DEFAULT_IP_TTL 23 #define DHO_PATH_MTU_AGING_TIMEOUT 24 #define DHO_PATH_MTU_PLATEAU_TABLE 25 #define DHO_INTERFACE_MTU 26 #define DHO_ALL_SUBNETS_LOCAL 27 #define DHO_BROADCAST_ADDRESS 28 #define DHO_PERFORM_MASK_DISCOVERY 29 #define DHO_MASK_SUPPLIER 30 #define DHO_ROUTER_DISCOVERY 31 #define DHO_ROUTER_SOLICITATION_ADDRESS 32 #define DHO_STATIC_ROUTES 33 #define DHO_TRAILER_ENCAPSULATION 34 #define DHO_ARP_CACHE_TIMEOUT 35 #define DHO_IEEE802_3_ENCAPSULATION 36 #define DHO_DEFAULT_TCP_TTL 37 #define DHO_TCP_KEEPALIVE_INTERVAL 38 #define DHO_TCP_KEEPALIVE_GARBAGE 39 #define DHO_NIS_DOMAIN 40 #define DHO_NIS_SERVERS 41 #define DHO_NTP_SERVERS 42 #define DHO_VENDOR_ENCAPSULATED_OPTIONS 43 #define DHO_NETBIOS_NAME_SERVERS 44 #define DHO_NETBIOS_DD_SERVER 45 #define DHO_NETBIOS_NODE_TYPE 46 #define DHO_NETBIOS_SCOPE 47 #define DHO_FONT_SERVERS 48 #define DHO_X_DISPLAY_MANAGER 49 #define DHO_DHCP_REQUESTED_ADDRESS 50 #define DHO_DHCP_LEASE_TIME 51 #define DHO_DHCP_OPTION_OVERLOAD 52 #define DHO_DHCP_MESSAGE_TYPE 53 #define DHO_DHCP_SERVER_IDENTIFIER 54 #define DHO_DHCP_PARAMETER_REQUEST_LIST 55 #define DHO_DHCP_MESSAGE 56 #define DHO_DHCP_MAX_MESSAGE_SIZE 57 #define DHO_DHCP_RENEWAL_TIME 58 #define DHO_DHCP_REBINDING_TIME 59 #define DHO_VENDOR_CLASS_IDENTIFIER 60 #define DHO_DHCP_CLIENT_IDENTIFIER 61 #define DHO_NWIP_DOMAIN_NAME 62 #define DHO_NWIP_SUBOPTIONS 63 #define DHO_USER_CLASS 77 #define DHO_FQDN 81 #define DHO_DHCP_AGENT_OPTIONS 82 #define DHO_SUBNET_SELECTION 118 /* RFC3011! */ /* The DHO_AUTHENTICATE option is not a standard yet, so I've allocated an option out of the "local" option space for it on a temporary basis. Once an option code number is assigned, I will immediately and shamelessly break this, so don't count on it continuing to work. */ #define DHO_AUTHENTICATE 210 #define DHO_END 255 /* DHCP message types. */ #define DHCPDISCOVER 1 #define DHCPOFFER 2 #define DHCPREQUEST 3 #define DHCPDECLINE 4 #define DHCPACK 5 #define DHCPNAK 6 #define DHCPRELEASE 7 #define DHCPINFORM 8 /* Relay Agent Information option subtypes: */ #define RAI_CIRCUIT_ID 1 #define RAI_REMOTE_ID 2 #define RAI_AGENT_ID 3 /* FQDN suboptions: */ #define FQDN_NO_CLIENT_UPDATE 1 #define FQDN_SERVER_UPDATE 2 #define FQDN_ENCODED 3 #define FQDN_RCODE1 4 #define FQDN_RCODE2 5 #define FQDN_HOSTNAME 6 #define FQDN_DOMAINNAME 7 #define FQDN_FQDN 8 #define FQDN_SUBOPTION_COUNT 8 + #endif diff --git a/libopie2/opienet/odebugmapper.cpp b/libopie2/opienet/odebugmapper.cpp index 7e4ab2b..f679afb 100644 --- a/libopie2/opienet/odebugmapper.cpp +++ b/libopie2/opienet/odebugmapper.cpp @@ -1,105 +1,111 @@ /* * debug value mapper - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de> */ #include <opie2/odebug.h> #include "odebugmapper.h" +using namespace Opie::Core; + +namespace Opie { +namespace Net { +namespace Private { + DebugMapper::DebugMapper() { odebug << "DebugMapper::DebugMapper()" << oendl; _map.insert( 0x8902, new QString("SIOCSPGRP") ); _map.insert( 0x8904, new QString("SIOCGPGRP") ); _map.insert( 0x8905, new QString("SIOCATMARK") ); _map.insert( 0x8906, new QString("SIOCGSTAMP") ); _map.insert( 0x890B, new QString("SIOCADDRT") ); _map.insert( 0x890C, new QString("SIOCDELRT") ); _map.insert( 0x890D, new QString("SIOCRTMSG") ); _map.insert( 0x8910, new QString("SIOCGIFNAME") ); _map.insert( 0x8911, new QString("SIOCSIFLINK") ); _map.insert( 0x8912, new QString("SIOCGIFCONF") ); _map.insert( 0x8913, new QString("SIOCGIFFLAGS") ); _map.insert( 0x8914, new QString("SIOCSIFFLAGS") ); _map.insert( 0x8915, new QString("SIOCGIFADDR") ); _map.insert( 0x8916, new QString("SIOCSIFADDR") ); _map.insert( 0x8917, new QString("SIOCGIFDSTADDR") ); _map.insert( 0x8918, new QString("SIOCSIFDSTADDR") ); _map.insert( 0x8919, new QString("SIOCGIFBRDADDR") ); _map.insert( 0x891a, new QString("SIOCSIFBRDADDR") ); _map.insert( 0x891b, new QString("SIOCGIFNETMASK") ); _map.insert( 0x891c, new QString("SIOCSIFNETMASK") ); _map.insert( 0x891d, new QString("SIOCGIFMETRIC") ); _map.insert( 0x891e, new QString("SIOCSIFMETRIC") ); _map.insert( 0x891f, new QString("SIOCGIFMEM") ); _map.insert( 0x8920, new QString("SIOCSIFMEM") ); _map.insert( 0x8921, new QString("SIOCGIFMTU") ); _map.insert( 0x8922, new QString("SIOCSIFMTU") ); _map.insert( 0x8923, new QString("SIOCSIFNAME") ); _map.insert( 0x8924, new QString("SIOCSIFHWADDR") ); _map.insert( 0x8925, new QString("SIOCGIFENCAP") ); _map.insert( 0x8926, new QString("SIOCSIFENCAP") ); _map.insert( 0x8927, new QString("SIOCGIFHWADDR") ); _map.insert( 0x8929, new QString("SIOCGIFSLAVE") ); _map.insert( 0x8930, new QString("SIOCSIFSLAVE") ); _map.insert( 0x8931, new QString("SIOCADDMULTI") ); _map.insert( 0x8932, new QString("SIOCDELMULTI") ); _map.insert( 0x8933, new QString("SIOCGIFINDEX") ); _map.insert( 0x8934, new QString("SIOCSIFPFLAGS") ); _map.insert( 0x8935, new QString("SIOCGIFPFLAGS") ); _map.insert( 0x8936, new QString("SIOCDIFADDR") ); _map.insert( 0x8937, new QString("SIOCSIFHWBROADCAST") ); _map.insert( 0x8938, new QString("SIOCGIFCOUNT") ); _map.insert( 0x8940, new QString("SIOCGIFBR") ); _map.insert( 0x8941, new QString("SIOCSIFBR") ); _map.insert( 0x8942, new QString("SIOCGIFTXQLEN") ); _map.insert( 0x8943, new QString("SIOCSIFTXQLEN") ); _map.insert( 0x8953, new QString("SIOCDARP") ); _map.insert( 0x8954, new QString("SIOCGARP") ); _map.insert( 0x8955, new QString("SIOCSARP") ); _map.insert( 0x8960, new QString("SIOCDRARP") ); _map.insert( 0x8961, new QString("SIOCGRARP") ); _map.insert( 0x8962, new QString("SIOCSRARP") ); _map.insert( 0x8970, new QString("SIOCGIFMAP") ); _map.insert( 0x8971, new QString("SIOCSIFMAP") ); _map.insert( 0x8980, new QString("SIOCADDDLCI") ); _map.insert( 0x8981, new QString("SIOCDELDLCI") ); _map.insert( 0x89F0, new QString("SIOCDEVPRIVATE") ); _map.insert( 0x89E0, new QString("SIOCPROTOPRIVATE") ); _map.insert( 0x1fff, new QString("SIOCPARM_MASK") ); _map.insert( 0x00000000, new QString("SIOC_VOID") ); _map.insert( 0x20000000, new QString("SIOC_OUT") ); _map.insert( 0x40000000, new QString("SIOC_IN") ); _map.insert( 0x8B00, new QString("SIOCSIWCOMMIT") ); _map.insert( 0x8B01, new QString("SIOCGIWNAME") ); _map.insert( 0x8B02, new QString("SIOCSIWNWID") ); _map.insert( 0x8B03, new QString("SIOCGIWNWID") ); _map.insert( 0x8B04, new QString("SIOCSIWFREQ") ); _map.insert( 0x8B05, new QString("SIOCGIWFREQ") ); _map.insert( 0x8B06, new QString("SIOCSIWMODE") ); _map.insert( 0x8B07, new QString("SIOCGIWMODE") ); _map.insert( 0x8B08, new QString("SIOCSIWSENS") ); _map.insert( 0x8B09, new QString("SIOCGIWSENS") ); _map.insert( 0x8B0A, new QString("SIOCSIWRANGE") ); _map.insert( 0x8B0B, new QString("SIOCGIWRANGE") ); _map.insert( 0x8B0C, new QString("SIOCSIWPRIV") ); _map.insert( 0x8B0D, new QString("SIOCGIWPRIV") ); _map.insert( 0x8B0E, new QString("SIOCSIWSTATS") ); _map.insert( 0x8B0F, new QString("SIOCGIWSTATS") ); _map.insert( 0x8B10, new QString("SIOCSIWSPY") ); _map.insert( 0x8B11, new QString("SIOCGIWSPY") ); _map.insert( 0x8B14, new QString("SIOCSIWAP") ); _map.insert( 0x8B15, new QString("SIOCGIWAP") ); _map.insert( 0x8B17, new QString("SIOCGIWAPLIST") ); _map.insert( 0x8B18, new QString("SIOCSIWSCAN") ); _map.insert( 0x8B19, new QString("SIOCGIWSCAN") ); _map.insert( 0x8B1A, new QString("SIOCSIWESSID") ); _map.insert( 0x8B1B, new QString("SIOCGIWESSID") ); _map.insert( 0x8B1C, new QString("SIOCSIWNICKN") ); _map.insert( 0x8B1D, new QString("SIOCGIWNICKN") ); _map.insert( 0x8B20, new QString("SIOCSIWRATE") ); _map.insert( 0x8B21, new QString("SIOCGIWRATE") ); _map.insert( 0x8B22, new QString("SIOCSIWRTS") ); @@ -119,97 +125,99 @@ DebugMapper::DebugMapper() _map.insert( 0x8B00, new QString("SIOCIWFIRST") ); _map.insert( 0x5000, new QString("SIOCGBPQETHPARAM") ); _map.insert( 0x5001, new QString("SIOCSBPQETHPARAM") ); _map.insert( 0x890B, new QString("SIOCADDRT") ); _map.insert( 0x890C, new QString("SIOCDELRT") ); _map.insert( 0x890D, new QString("SIOCRTMSG") ); _map.insert( 0x8910, new QString("SIOCGIFNAME") ); _map.insert( 0x8911, new QString("SIOCSIFLINK") ); _map.insert( 0x8912, new QString("SIOCGIFCONF") ); _map.insert( 0x8913, new QString("SIOCGIFFLAGS") ); _map.insert( 0x8914, new QString("SIOCSIFFLAGS") ); _map.insert( 0x8915, new QString("SIOCGIFADDR") ); _map.insert( 0x8916, new QString("SIOCSIFADDR") ); _map.insert( 0x8917, new QString("SIOCGIFDSTADDR") ); _map.insert( 0x8918, new QString("SIOCSIFDSTADDR") ); _map.insert( 0x8919, new QString("SIOCGIFBRDADDR") ); _map.insert( 0x891a, new QString("SIOCSIFBRDADDR") ); _map.insert( 0x891b, new QString("SIOCGIFNETMASK") ); _map.insert( 0x891c, new QString("SIOCSIFNETMASK") ); _map.insert( 0x891d, new QString("SIOCGIFMETRIC") ); _map.insert( 0x891e, new QString("SIOCSIFMETRIC") ); _map.insert( 0x891f, new QString("SIOCGIFMEM") ); _map.insert( 0x8920, new QString("SIOCSIFMEM") ); _map.insert( 0x8921, new QString("SIOCGIFMTU") ); _map.insert( 0x8922, new QString("SIOCSIFMTU") ); _map.insert( 0x8923, new QString("SIOCSIFNAME") ); _map.insert( 0x8924, new QString("SIOCSIFHWADDR") ); _map.insert( 0x8925, new QString("SIOCGIFENCAP") ); _map.insert( 0x8926, new QString("SIOCSIFENCAP") ); _map.insert( 0x8927, new QString("SIOCGIFHWADDR") ); _map.insert( 0x8929, new QString("SIOCGIFSLAVE") ); _map.insert( 0x8930, new QString("SIOCSIFSLAVE") ); _map.insert( 0x8931, new QString("SIOCADDMULTI") ); _map.insert( 0x8932, new QString("SIOCDELMULTI") ); _map.insert( 0x8933, new QString("SIOCGIFINDEX") ); _map.insert( 0x8934, new QString("SIOCSIFPFLAGS") ); _map.insert( 0x8935, new QString("SIOCGIFPFLAGS") ); _map.insert( 0x8936, new QString("SIOCDIFADDR") ); _map.insert( 0x8937, new QString("SIOCSIFHWBROADCAST") ); _map.insert( 0x8938, new QString("SIOCGIFCOUNT") ); _map.insert( 0x8940, new QString("SIOCGIFBR") ); _map.insert( 0x8941, new QString("SIOCSIFBR") ); _map.insert( 0x8942, new QString("SIOCGIFTXQLEN") ); _map.insert( 0x8943, new QString("SIOCSIFTXQLEN") ); _map.insert( 0x8944, new QString("SIOCGIFDIVERT") ); _map.insert( 0x8945, new QString("SIOCSIFDIVERT") ); _map.insert( 0x8946, new QString("SIOCETHTOOL") ); _map.insert( 0x8947, new QString("SIOCGMIIPHY") ); _map.insert( 0x8948, new QString("SIOCGMIIREG") ); _map.insert( 0x8949, new QString("SIOCSMIIREG") ); _map.insert( 0x894A, new QString("SIOCWANDEV") ); _map.insert( 0x8953, new QString("SIOCDARP") ); _map.insert( 0x8954, new QString("SIOCGARP") ); _map.insert( 0x8955, new QString("SIOCSARP") ); _map.insert( 0x8960, new QString("SIOCDRARP") ); _map.insert( 0x8961, new QString("SIOCGRARP") ); _map.insert( 0x8962, new QString("SIOCSRARP") ); _map.insert( 0x8970, new QString("SIOCGIFMAP") ); _map.insert( 0x8971, new QString("SIOCSIFMAP") ); _map.insert( 0x8980, new QString("SIOCADDDLCI") ); _map.insert( 0x8981, new QString("SIOCDELDLCI") ); _map.insert( 0x8982, new QString("SIOCGIFVLAN") ); _map.insert( 0x8983, new QString("SIOCSIFVLAN") ); _map.insert( 0x8990, new QString("SIOCBONDENSLAVE") ); _map.insert( 0x8991, new QString("SIOCBONDRELEASE") ); _map.insert( 0x8992, new QString("SIOCBONDSETHWADDR") ); _map.insert( 0x8993, new QString("SIOCBONDSLAVEINFOQUERY") ); _map.insert( 0x8994, new QString("SIOCBONDINFOQUERY") ); _map.insert( 0x8995, new QString("SIOCBONDCHANGEACTIVE") ); _map.insert( 0x89F0, new QString("SIOCDEVPRIVATE") ); _map.insert( 0x89E0, new QString("SIOCPROTOPRIVATE") ); }; DebugMapper::~DebugMapper() { odebug << "DebugMapper::~DebugMapper()" << oendl; } const QString& DebugMapper::map( int value ) const { QString* result = _map[ value ]; if ( !result ) { owarn << "DebugMapper::map() - value " << value << " is not found." << oendl; return QString::null; } else { return *result; } } - +} +} +} diff --git a/libopie2/opienet/odebugmapper.h b/libopie2/opienet/odebugmapper.h index 66b331d..f47db47 100644 --- a/libopie2/opienet/odebugmapper.h +++ b/libopie2/opienet/odebugmapper.h @@ -1,26 +1,36 @@ /* * debug value mapper - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de> */ #ifndef DEBUGMAPPER_H #define DEBUGMAPPER_H #include <qstring.h> #include <qintdict.h> +namespace Opie { +namespace Net { +namespace Private { + typedef QIntDict<QString> IntStringMap; class DebugMapper { public: DebugMapper(); ~DebugMapper(); const QString& map( int value ) const; private: IntStringMap _map; + class Private; + Private *d; }; +} +} +} + #endif diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp index b93b752..209ec94 100644 --- a/libopie2/opienet/omanufacturerdb.cpp +++ b/libopie2/opienet/omanufacturerdb.cpp @@ -1,135 +1,142 @@ /* This file is part of the Opie Project (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "omanufacturerdb.h" #define OPIE_IMPROVE_GUI_LATENCY 1 /* OPIE */ #include <opie2/odebug.h> #ifdef OPIE_IMPROVE_GUI_LATENCY #include <qpe/global.h> #endif /* QT */ #include <qapplication.h> #include <qfile.h> #include <qtextstream.h> +using namespace Opie::Core; +namespace Opie { +namespace Net { + OManufacturerDB* OManufacturerDB::_instance = 0; OManufacturerDB* OManufacturerDB::instance() { if ( !OManufacturerDB::_instance ) { odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; _instance = new OManufacturerDB(); } return _instance; } OManufacturerDB::OManufacturerDB() { #ifdef OPIE_IMPROVE_GUI_LATENCY Global::statusMessage( "Reading Manufacturers..." ); #endif QString filename( "/etc/manufacturers" ); odebug << "OManufacturerDB: trying to read " << filename << oendl; if ( !QFile::exists( filename ) ) { filename = "/opt/QtPalmtop/etc/manufacturers"; odebug << "OManufacturerDB: trying to read " << filename << oendl; if ( !QFile::exists( filename ) ) { filename = "/usr/share/wellenreiter/manufacturers"; odebug << "OManufacturerDB: trying to read " << filename << oendl; } } QFile file( filename ); bool hasFile = file.open( IO_ReadOnly ); if (!hasFile) { owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; } else { odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; QTextStream s( &file ); QString addr; QString manu; QString extManu; #ifdef OPIE_IMPROVE_GUI_LATENCY int counter = 0; #endif while (!s.atEnd()) { s >> addr; s >> manu; s >> extManu; manufacturers.insert( addr, manu ); manufacturersExt.insert( addr, extManu ); // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; #ifdef OPIE_IMPROVE_GUI_LATENCY counter++; if ( counter == 50 ) { qApp->processEvents(); counter = 0; } #endif } odebug << "OManufacturerDB: manufacturer list completed." << oendl; #ifdef OPIE_IMPROVE_GUI_LATENCY Global::statusMessage( "Manufacturers Complete..." ); #endif } } OManufacturerDB::~OManufacturerDB() { } const QString& OManufacturerDB::lookup( const QString& macaddr ) const { return manufacturers[macaddr.upper().left(8)]; } const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const { QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); return it == manufacturersExt.end() ? lookup( macaddr ) : *it; } +} +} + diff --git a/libopie2/opienet/omanufacturerdb.h b/libopie2/opienet/omanufacturerdb.h index c2712e5..5c1940e 100644 --- a/libopie2/opienet/omanufacturerdb.h +++ b/libopie2/opienet/omanufacturerdb.h @@ -1,69 +1,77 @@ /* This file is part of the Opie Project (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OMANUFACTURERDB_H #define OMANUFACTURERDB_H #include <qmap.h> +namespace Opie { +namespace Net { + /** * @brief A Ethernet card vendor database. * * This class encapsulates the lookup of Ethernet vendor given a * certain Mac Address. Only the first three bytes define the vendor. */ class OManufacturerDB { public: /** * @returns the one-and-only @ref OManufacturerDB instance. */ static OManufacturerDB* instance(); /** * @returns the short manufacturer string given a @a macaddr. */ const QString& lookup( const QString& macaddr ) const; /** * @returns the enhanced manufacturer string given a @a macaddr. */ const QString& lookupExt( const QString& macaddr ) const; protected: OManufacturerDB(); virtual ~OManufacturerDB(); private: QMap<QString, QString> manufacturers; QMap<QString, QString> manufacturersExt; static OManufacturerDB* _instance; + class Private; + Private *d; }; +} +} + #endif diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index 48cfa43..7794334 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp @@ -1,232 +1,241 @@ /* This file is part of the Opie Project (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <opie2/onetutils.h> #include <opie2/onetwork.h> #include <opie2/omanufacturerdb.h> #include <net/if.h> #include <assert.h> #include <stdio.h> +namespace Opie { +namespace Net { + /*====================================================================================== * OMacAddress *======================================================================================*/ // static initializer for broadcast and unknown MAC Adresses const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); //TODO: Incorporate Ethernet Manufacturer database here! (inline or so) OMacAddress::OMacAddress() { memcpy( _bytes, __unknown, 6 ); } OMacAddress::OMacAddress( unsigned char* p ) { memcpy( _bytes, p, 6 ); } OMacAddress::OMacAddress( const unsigned char* p ) { memcpy( _bytes, p, 6 ); } OMacAddress::OMacAddress( struct ifreq& ifr ) { memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); } OMacAddress::~OMacAddress() { } //#ifdef QT_NO_DEBUG //inline //#endif const unsigned char* OMacAddress::native() const { return (const unsigned char*) &_bytes; } OMacAddress OMacAddress::fromString( const QString& str ) { QString addr( str ); unsigned char buf[6]; bool ok = true; int index = 14; for ( int i = 5; i >= 0; --i ) { buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); if ( !ok ) return OMacAddress::unknown; addr.truncate( index ); index -= 3; } return (const unsigned char*) &buf; } QString OMacAddress::toString( bool substitute ) const { QString manu; manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff ); QString serial; serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); if ( !substitute ) return manu+serial; // fallback - if no vendor is found, just use the number QString textmanu = OManufacturerDB::instance()->lookup( manu ); return textmanu.isNull() ? manu+serial : textmanu+serial; } QString OMacAddress::manufacturer() const { return OManufacturerDB::instance()->lookupExt( toString() ); } bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) { return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; } /*====================================================================================== * OHostAddress *======================================================================================*/ /*====================================================================================== * OPrivateIOCTL *======================================================================================*/ OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) { } OPrivateIOCTL::~OPrivateIOCTL() { } int OPrivateIOCTL::numberGetArgs() const { return _getargs & IW_PRIV_SIZE_MASK; } int OPrivateIOCTL::typeGetArgs() const { return _getargs & IW_PRIV_TYPE_MASK >> 12; } int OPrivateIOCTL::numberSetArgs() const { return _setargs & IW_PRIV_SIZE_MASK; } int OPrivateIOCTL::typeSetArgs() const { return _setargs & IW_PRIV_TYPE_MASK >> 12; } void OPrivateIOCTL::invoke() const { ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); } void OPrivateIOCTL::setParameter( int num, u_int32_t value ) { u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; arglist[num] = value; } + + +namespace Private { /*====================================================================================== * assorted functions *======================================================================================*/ void dumpBytes( const unsigned char* data, int num ) { printf( "Dumping %d bytes @ %0x", num, data ); printf( "-------------------------------------------\n" ); for ( int i = 0; i < num; ++i ) { printf( "%02x ", data[i] ); if ( !((i+1) % 32) ) printf( "\n" ); } printf( "\n\n" ); } int stringToMode( const QString& mode ) { if ( mode == "auto" ) return IW_MODE_AUTO; else if ( mode == "adhoc" ) return IW_MODE_ADHOC; else if ( mode == "managed" ) return IW_MODE_INFRA; else if ( mode == "master" ) return IW_MODE_MASTER; else if ( mode == "repeater" ) return IW_MODE_REPEAT; else if ( mode == "secondary" ) return IW_MODE_SECOND; else if ( mode == "monitor" ) return IW_MODE_MONITOR; else assert( 0 ); } QString modeToString( int mode ) { switch ( mode ) { case IW_MODE_AUTO: return "auto"; case IW_MODE_ADHOC: return "adhoc"; case IW_MODE_INFRA: return "managed"; case IW_MODE_MASTER: return "master"; case IW_MODE_REPEAT: return "repeater"; case IW_MODE_SECOND: return "second"; case IW_MODE_MONITOR: return "monitor"; default: assert( 0 ); } } +} +} +} diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h index bddfab9..ca6815d 100644 --- a/libopie2/opienet/onetutils.h +++ b/libopie2/opienet/onetutils.h @@ -1,181 +1,196 @@ /* This file is part of the Opie Project (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef ONETUTILS_H #define ONETUTILS_H #include <qdict.h> #include <qmap.h> #include <qstring.h> #include <qhostaddress.h> #include <qobject.h> #include <sys/types.h> struct ifreq; + +namespace Opie { +namespace Net { + class OWirelessNetworkInterface; /*====================================================================================== * OMacAddress *======================================================================================*/ class OMacAddress { public: // QString c'tor? -zecke OMacAddress(); OMacAddress( unsigned char* ); OMacAddress( const unsigned char* ); OMacAddress( struct ifreq& ); ~OMacAddress(); QString manufacturer() const; QString toString( bool substitute = false ) const; const unsigned char* native() const; // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? static OMacAddress fromString( const QString& ); public: static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff static const OMacAddress& unknown; // 44:44:44:44:44:44 private: unsigned char _bytes[6]; friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); + class Private; + Private *d; }; bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); /*====================================================================================== * OHostAddress *======================================================================================*/ class OHostAddress : public QHostAddress { /*public: OHostAddress(); ~OHostAddress(); */ + private: + class Private; + Private *d; }; /*====================================================================================== * OPrivateIOCTL *======================================================================================*/ class OPrivateIOCTL : public QObject { public: OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); ~OPrivateIOCTL(); int numberGetArgs() const; int typeGetArgs() const; int numberSetArgs() const; int typeSetArgs() const; // FIXME return int? as ::ioctl does? -zecke void invoke() const; void setParameter( int, u_int32_t ); private: u_int32_t _ioctl; u_int16_t _getargs; u_int16_t _setargs; + class Private; + Private *d; }; /*====================================================================================== * Miscellaneous *======================================================================================*/ +namespace Private { void dumpBytes( const unsigned char* data, int num ); QString modeToString( int ); int stringToMode( const QString& ); +} +} +} #define IW_PRIV_TYPE_MASK 0x7000 #define IW_PRIV_TYPE_NONE 0x0000 #define IW_PRIV_TYPE_BYTE 0x1000 #define IW_PRIV_TYPE_CHAR 0x2000 #define IW_PRIV_TYPE_INT 0x4000 #define IW_PRIV_TYPE_FLOAT 0x5000 #define IW_PRIV_TYPE_ADDR 0x6000 #define IW_PRIV_SIZE_FIXED 0x0800 #define IW_PRIV_SIZE_MASK 0x07FF #ifndef ARPHRD_IEEE80211 #define ARPHRD_IEEE80211 801 #endif #ifndef ARPHRD_IEEE80211_PRISM #define ARPHRD_IEEE80211_PRISM 802 #endif /* Network to host order macros */ #ifdef LBL_ALIGN #define EXTRACT_16BITS(p) \ ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ (u_int16_t)*((const u_int8_t *)(p) + 1))) #define EXTRACT_32BITS(p) \ ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ (u_int32_t)*((const u_int8_t *)(p) + 3))) #else #define EXTRACT_16BITS(p) \ ((u_int16_t)ntohs(*(const u_int16_t *)(p))) #define EXTRACT_32BITS(p) \ ((u_int32_t)ntohl(*(const u_int32_t *)(p))) #endif #define EXTRACT_24BITS(p) \ ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ (u_int32_t)*((const u_int8_t *)(p) + 2))) /* Little endian protocol host order macros */ #define EXTRACT_LE_8BITS(p) (*(p)) #define EXTRACT_LE_16BITS(p) \ ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ (u_int16_t)*((const u_int8_t *)(p) + 0))) #define EXTRACT_LE_32BITS(p) \ ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ (u_int32_t)*((const u_int8_t *)(p) + 0))) #endif // ONETUTILS_H diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index e5b091f..ab3e77f 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp @@ -1,162 +1,168 @@ /*
This file is part of the Opie Project
Copyright (C) 2003-2004 by Michael 'Mickey' Lauer
=. <mickey@Vanille.de>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. 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
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* OPIE */
#include <opie2/onetwork.h>
#include <opie2/ostation.h>
#include <opie2/odebug.h>
/* QT */
#include <qfile.h>
#include <qtextstream.h>
/* UNIX */
#include <assert.h>
#include <arpa/inet.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/sockios.h>
#include <net/if_arp.h>
#include <stdarg.h>
#ifndef NODEBUG
#include <opie2/odebugmapper.h>
+ + +using namespace Opie::Core; +using namespace Opie::Net::Private; DebugMapper* debugmapper = new DebugMapper();
#endif
/*======================================================================================
* ONetwork
*======================================================================================*/
+namespace Opie { +namespace Net { ONetwork* ONetwork::_instance = 0;
ONetwork::ONetwork()
{
odebug << "ONetwork::ONetwork()" << oendl;
odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl;
synchronize();
}
void ONetwork::synchronize()
{
// gather available interfaces by inspecting /proc/net/dev
//FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
//FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
//FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
_interfaces.clear();
QString str;
QFile f( "/proc/net/dev" );
bool hasFile = f.open( IO_ReadOnly );
if ( !hasFile )
{
odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl;
return;
}
QTextStream s( &f );
s.readLine();
s.readLine();
while ( !s.atEnd() )
{
s >> str;
str.truncate( str.find( ':' ) );
odebug << "ONetwork: found interface '" << str << "'" << oendl;
ONetworkInterface* iface;
if ( isWirelessInterface( str ) )
{
iface = new OWirelessNetworkInterface( this, (const char*) str );
odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl;
}
else
{
iface = new ONetworkInterface( this, (const char*) str );
}
_interfaces.insert( str, iface );
s.readLine();
}
}
short ONetwork::wirelessExtensionVersion()
{
return WIRELESS_EXT;
}
int ONetwork::count() const
{
return _interfaces.count();
}
ONetworkInterface* ONetwork::interface( const QString& iface ) const
{
return _interfaces[iface];
}
ONetwork* ONetwork::instance()
{
if ( !_instance ) _instance = new ONetwork();
return _instance;
}
ONetwork::InterfaceIterator ONetwork::iterator() const
{
return ONetwork::InterfaceIterator( _interfaces );
}
bool ONetwork::isPresent( const char* name ) const
{
int sfd = socket( AF_INET, SOCK_STREAM, 0 );
struct ifreq ifr;
memset( &ifr, 0, sizeof( struct ifreq ) );
strcpy( (char*) &ifr.ifr_name, name );
int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr );
return result != -1;
}
bool ONetwork::isWirelessInterface( const char* name ) const
{
int sfd = socket( AF_INET, SOCK_STREAM, 0 );
struct iwreq iwr;
memset( &iwr, 0, sizeof( struct iwreq ) );
@@ -1144,96 +1150,99 @@ QString OWlanNGMonitoringInterface::name() const void OWlanNGMonitoringInterface::setChannel( int c )
{
//NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't.
QString enable = "true"; //_if->monitorMode() ? "true" : "false";
QString prism = _prismHeader ? "true" : "false";
QString cmd;
cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
(const char*) _if->name(), c, (const char*) enable, (const char*) prism );
system( cmd );
}
/*======================================================================================
* OHostAPMonitoringInterface
*======================================================================================*/
OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
:OMonitoringInterface( iface, prismHeader )
{
iface->setMonitoring( this );
}
OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
{
}
void OHostAPMonitoringInterface::setEnabled( bool b )
{
int monitorCode = _prismHeader ? 1 : 2;
if ( b )
{
_if->setPrivate( "monitor", 1, monitorCode );
}
else
{
_if->setPrivate( "monitor", 1, 0 );
}
}
QString OHostAPMonitoringInterface::name() const
{
return "hostap";
}
/*======================================================================================
* OOrinocoNetworkInterface
*======================================================================================*/
OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
:OMonitoringInterface( iface, prismHeader )
{
iface->setMonitoring( this );
}
OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
{
}
void OOrinocoMonitoringInterface::setChannel( int c )
{
if ( !_if->hasPrivate( "monitor" ) )
{
this->OMonitoringInterface::setChannel( c );
}
else
{
int monitorCode = _prismHeader ? 1 : 2;
_if->setPrivate( "monitor", 2, monitorCode, c );
}
}
void OOrinocoMonitoringInterface::setEnabled( bool b )
{
if ( b )
{
setChannel( 1 );
}
else
{
_if->setPrivate( "monitor", 2, 0, 0 );
}
}
QString OOrinocoMonitoringInterface::name() const
{
return "orinoco";
}
+ +} +} diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 93b129f..a953296 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h @@ -1,559 +1,590 @@ /* This file is part of the Opie Project Copyright (C) 2003-2004 by Michael 'Mickey' Lauer =. <mickey@Vanille.de> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef ONETWORK_H #define ONETWORK_H #if !defined( OPIE_WE_VERSION ) #error Need to define a wireless extension version to build against! #endif #if OPIE_WE_VERSION == 15 #include "wireless.15.h" #endif #if OPIE_WE_VERSION == 16 #include "wireless.16.h" #endif /* OPIE */ #include <opie2/onetutils.h> #include <opie2/ostation.h> /* QT */ #include <qvaluelist.h> #include <qdict.h> #include <qmap.h> #include <qobject.h> #include <qhostaddress.h> +namespace Opie { +namespace Net { + class ONetworkInterface; class OWirelessNetworkInterface; class OChannelHopper; class OMonitoringInterface; /*====================================================================================== * ONetwork *======================================================================================*/ /** * @brief A container class for all network interfaces * * This class provides access to all available network interfaces of your computer. * * @author Michael 'Mickey' Lauer <mickey@vanille.de> */ class ONetwork : public QObject { Q_OBJECT public: typedef QDict<ONetworkInterface> InterfaceMap; typedef QDictIterator<ONetworkInterface> InterfaceIterator; public: /** * @returns the number of available interfaces */ int count() const; /** * @returns a pointer to the (one and only) @ref ONetwork instance. */ static ONetwork* instance(); /** * @returns an iterator usable for iterating through all network interfaces. */ InterfaceIterator iterator() const; /** * @returns true, if the @a interface is present. */ bool isPresent( const char* interface ) const; /** * @returns true, if the @a interface supports the wireless extension protocol. */ bool isWirelessInterface( const char* interface ) const; /** * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. * @see ONetworkInterface */ ONetworkInterface* interface( const QString& interface ) const; /** * @internal Rebuild the internal interface database * @note Sometimes it might be useful to call this from client code, * e.g. after issuing a cardctl insert */ void synchronize(); /** * @returns the wireless extension version used at compile time. **/ static short wirelessExtensionVersion(); protected: ONetwork(); private: static ONetwork* _instance; InterfaceMap _interfaces; + class Private; + Private *d; }; /*====================================================================================== * ONetworkInterface *======================================================================================*/ /** * @brief A network interface wrapper. * * This class provides a wrapper for a network interface. All the cumbersume details of * Linux ioctls are hidden under a convenient high-level interface. * @warning Most of the setting methods contained in this class require the appropriate * process permissions to work. * * @author Michael 'Mickey' Lauer <mickey@vanille.de> */ class ONetworkInterface : public QObject { friend class OMonitoringInterface; friend class OCiscoMonitoringInterface; friend class OWlanNGMonitoringInterface; friend class OHostAPMonitoringInterface; friend class OOrinocoMonitoringInterface; public: /** * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, * but access them via @ref ONetwork::interface(). */ ONetworkInterface( QObject* parent, const char* name ); /** * Destructor. */ virtual ~ONetworkInterface(); /** * Associates a @a monitoring interface with this network interface. * @note This is currently only useful with @ref OWirelessNetworkInterface objects. */ void setMonitoring( OMonitoringInterface* monitoring ); /** * @returns the currently associated monitoring interface or 0, if no monitoring is associated. */ OMonitoringInterface* monitoring() const; /** * Setting an interface to promiscuous mode enables the device to receive * all packets on the shared medium - as opposed to packets which are addressed to this interface. */ bool setPromiscuousMode( bool ); /** * @returns true if the interface is set to promiscuous mode. */ bool promiscuousMode() const; /** * Setting an interface to up enables it to receive packets. */ bool setUp( bool ); /** * @returns true if the interface is up. */ bool isUp() const; /** * @returns true if the interface is a loopback interface. */ bool isLoopback() const; /** * @returns true if the interface is featuring supports the wireless extension protocol. */ bool isWireless() const; /** * Associate the IP address @ addr with the interface. */ void setIPV4Address( const QHostAddress& addr ); /** * @returns the IPv4 address associated with the interface. */ QString ipV4Address() const; //TODO: make this return an OHostAddress /** * Associate the MAC address @a addr with the interface. * @note It can be necessary to shut down the interface prior to calling this method. * @warning This is not supported by all drivers. */ void setMacAddress( const OMacAddress& addr ); /** * @returns the MAC address associated with the interface. */ OMacAddress macAddress() const; /** * Associate the IPv4 @a netmask with the interface. */ void setIPV4Netmask( const QHostAddress& netmask ); /** * @returns the IPv4 netmask associated with the interface. */ QString ipV4Netmask() const; //TODO: make this return an OHostAddress /** * @returns the data link type currently associated with the interface. * @see #include <net/if_arp.h> for possible values. */ int dataLinkType() const; protected: const int _sfd; mutable ifreq _ifr; OMonitoringInterface* _mon; protected: struct ifreq& ifr() const; virtual void init(); bool ioctl( int call ) const; bool ioctl( int call, struct ifreq& ) const; + private: + class Private; + Private *d; }; /*====================================================================================== * OChannelHopper *======================================================================================*/ /** * @brief A radio frequency channel hopper. * * This class provides a channel hopper for radio frequencies. A channel hopper frequently * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. * This is necessary when in monitoring mode and scanning for other devices, because * the radio frequency hardware can only detect packets sent on the same frequency. * * @author Michael 'Mickey' Lauer <mickey@vanille.de> */ class OChannelHopper : public QObject { Q_OBJECT public: /** * Constructor. */ OChannelHopper( OWirelessNetworkInterface* ); /** * Destructor. */ virtual ~OChannelHopper(); /** * @returns true, if the channel hopper is hopping channels */ bool isActive() const; /** * @returns the last hopped channel */ int channel() const; /** * Set the channel hopping @a interval. * An interval of 0 deactivates the channel hopper. */ void setInterval( int interval ); /** * @returns the channel hopping interval */ int interval() const; signals: /** * This signal is emitted right after the channel hopper performed a hop */ void hopped( int ); protected: virtual void timerEvent( QTimerEvent* ); private: OWirelessNetworkInterface* _iface; int _interval; int _tid; QValueList<int> _channels; QValueList<int>::Iterator _channel; + class Private; + Private *d; }; /*====================================================================================== * OWirelessNetworkInterface *======================================================================================*/ /** * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. * * This class provides a high-level encapsulation of the Linux wireless extension API. * * @author Michael 'Mickey' Lauer <mickey@vanille.de> */ class OWirelessNetworkInterface : public ONetworkInterface { friend class OMonitoringInterface; friend class OCiscoMonitoringInterface; friend class OWlanNGMonitoringInterface; friend class OHostAPMonitoringInterface; friend class OOrinocoMonitoringInterface; friend class OPrivateIOCTL; public: /** * Constructor. */ OWirelessNetworkInterface( QObject* parent, const char* name ); /** * Destructor. */ virtual ~OWirelessNetworkInterface(); /** * Setting the @a channel of the interface changes the radio frequency (RF) * of the corresponding wireless network device. * @note Common channel range is within [1-14]. A value of 0 is not allowed. * @see channels() */ virtual void setChannel( int channel ) const; /** * @returns the channel index of the current radio frequency. */ virtual int channel() const; /** * @returns the current radio frequency (in MHz). */ virtual double frequency() const; /** * @returns the number of radio frequency channels for the * corresponding wireless network device. * @note European devices usually have 14 channels, while American typically feature 11 channels. */ virtual int channels() const; /** * Set the IEEE 802.11 operation @a mode. * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master * @warning Not all drivers support the all modes. * @note You might have to change the SSID to get the operation mode change into effect. */ virtual void setMode( const QString& mode ); /** * @returns the current IEEE 802.11 operation mode. * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown * * @note: Important note concerning the 'monitor' mode: * Setting the monitor mode on a wireless network interface enables * listening to IEEE 802.11 data and management frames which normally * are handled by the device firmware. This can be used to detect * other wireless network devices, e.g. Access Points or Ad-hoc stations. * @warning Standard wireless network drives don't support the monitor mode. * @warning You need a patched driver for this to work. * @note Enabling the monitor mode is highly driver dependent and requires * the proper @ref OMonitoringInterface to be associated with the interface. * @see OMonitoringInterface */ virtual QString mode() const; /** * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. * @see OChannelHopper */ virtual void setChannelHopping( int interval = 0 ); /** * @returns the channel hopping interval or 0, if channel hopping is disabled. */ virtual int channelHopping() const; /** * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before */ virtual OChannelHopper* channelHopper() const; /** * Set the station @a nickname. */ virtual void setNickName( const QString& nickname ); /** * @returns the current station nickname. */ virtual QString nickName() const; /** * Invoke the private IOCTL @a command with a @number of parameters on the network interface. * @see OPrivateIOCTL */ virtual void setPrivate( const QString& command, int number, ... ); /** * @returns true if the interface is featuring the private IOCTL @command. */ virtual bool hasPrivate( const QString& command ); virtual void getPrivate( const QString& command ); //FIXME: Implement and document this /** * @returns true if the interface is associated to an access point * @note: This information is only valid if the interface is in managed mode. */ virtual bool isAssociated() const; /** * @returns the MAC address of the Access Point if the device is in infrastructure mode. * @returns a (more or less random) cell ID address if the device is in adhoc mode. */ virtual OMacAddress associatedAP() const; /** * Set the @a ssid (Service Set ID) string. This is used to decide * which network to associate with (use "any" to let the driver decide). */ virtual void setSSID( const QString& ssid ); /** * @returns the current SSID (Service Set ID). */ virtual QString SSID() const; /** * Perform scanning the wireless network neighbourhood. * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! */ virtual OStationList* scanNetwork(); /** * @return signal strength to associated neighbour (in percent). * In infrastructure mode, this is the signal strength of the Access Point. * In other modes the result is driver dependent. */ virtual int signalStrength() const; /** @internal commit pending changes to the driver * */ void commit() const; protected: void buildInformation(); void buildPrivateList(); void dumpInformation() const; virtual void init(); struct iwreq& iwr() const; bool wioctl( int call ) const; bool wioctl( int call, struct iwreq& ) const; protected: mutable struct iwreq _iwr; QMap<int,int> _channels; struct iw_range _range; private: OChannelHopper* _hopper; + class Private; + Private *d; }; /*====================================================================================== * OMonitoringInterface *======================================================================================*/ class OMonitoringInterface { public: OMonitoringInterface(); OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); virtual ~OMonitoringInterface(); public: virtual void setEnabled( bool ); virtual void setChannel( int ); virtual QString name() const = 0; protected: OWirelessNetworkInterface* _if; bool _prismHeader; + private: + class Private; + Private *d; }; /*====================================================================================== * OCiscoMonitoring *======================================================================================*/ class OCiscoMonitoringInterface : public OMonitoringInterface { public: OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); virtual ~OCiscoMonitoringInterface(); virtual void setEnabled( bool ); virtual QString name() const; virtual void setChannel( int ); + private: + class Private; + Private *d; }; /*====================================================================================== * OWlanNGMonitoringInterface *======================================================================================*/ class OWlanNGMonitoringInterface : public OMonitoringInterface { public: OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); virtual ~OWlanNGMonitoringInterface(); public: virtual void setEnabled( bool ); virtual QString name() const; virtual void setChannel( int ); + private: + class Private; + Private *d; }; /*====================================================================================== * OHostAPMonitoringInterface *======================================================================================*/ class OHostAPMonitoringInterface : public OMonitoringInterface { public: OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); virtual ~OHostAPMonitoringInterface(); public: virtual void setEnabled( bool ); virtual QString name() const; + + private: + class Private; + Private *d; }; /*====================================================================================== * OOrinocoMonitoringInterface *======================================================================================*/ class OOrinocoMonitoringInterface : public OMonitoringInterface { public: OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); virtual ~OOrinocoMonitoringInterface(); public: virtual void setChannel( int ); virtual void setEnabled( bool ); virtual QString name() const; + private: + class Private; + Private *d; }; +} +} + #endif // ONETWORK_H diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index fdd519c..4081d4f 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp @@ -1,143 +1,148 @@ /* This file is part of the Opie Project Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* OPIE */ #include <opie2/opcap.h> #include <opie2/odebug.h> /* QT */ #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) #include <qsocketnotifier.h> #include <qobjectlist.h> /* SYSTEM */ #include <sys/time.h> #include <sys/types.h> #include <unistd.h> /* LOCAL */ #include "udp_ports.h" +using namespace Opie::Core; + +namespace Opie { +namespace Net { + /*====================================================================================== * OPacket *======================================================================================*/ OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) :QObject( parent, "Generic" ), _hdr( header ), _data( data ) { //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); _end = (unsigned char*) data + header.len; //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); switch ( datalink ) { case DLT_EN10MB: odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; new OEthernetPacket( _end, (const struct ether_header*) data, this ); break; case DLT_IEEE802_11: odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); break; case DLT_PRISM_HEADER: odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); break; default: owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; } } OPacket::~OPacket() { } timevalstruct OPacket::timeval() const { return _hdr.ts; } int OPacket::caplen() const { return _hdr.caplen; } void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) { if (!l) return; QObject* o = l->first(); while ( o ) { stats[o->name()]++; updateStats( stats, const_cast<QObjectList*>( o->children() ) ); o = l->next(); } } QString OPacket::dumpStructure() const { return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; } QString OPacket::_dumpStructure( QObjectList* l ) const { if (!l) return QString::null; QObject* o = l->first(); QString str(" "); while ( o ) { str.append( o->name() ); str.append( " |" ); str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); o = l->next(); } return str; } QString OPacket::dump( int bpl ) const { static int index = 0; index++; int len = _hdr.caplen; QString str; str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); str.append( "0000: " ); QString tmp; @@ -1251,97 +1256,98 @@ bool OPacketCapturer::openDumpFile( const QString& filename ) if ( !dump ) { owarn << "OPacketCapturer::open(): can't open dump with '" << filename << "': " << _errbuf << oendl; return false; } odebug << "OPacketCapturer::open(): dump [" << filename << "] opened successfully." << oendl; _pcd = dump; return true; } bool OPacketCapturer::open( const QFile& file ) { QString name = file.name(); if ( _open ) { close(); if ( name == _name ) // ignore opening an already openend device { return true; } else // close the last opened device { close(); } } _name = name; pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); if ( handle ) { odebug << "OPacketCapturer::open(): libpcap opened successfully." << oendl; _pch = handle; _open = true; // in case we have an application object, create a socket notifier if ( qApp ) { _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); } return true; } else { odebug << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; return false; } } bool OPacketCapturer::isOpen() const { return _open; } void OPacketCapturer::readyToReceive() { odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl; OPacket* p = next(); emit receivedPacket( p ); // emit is synchronous - packet has been dealt with, now it's safe to delete delete p; } const QMap<QString,int>& OPacketCapturer::statistics() const { return _stats; } int OPacketCapturer::snapShot() const { return pcap_snapshot( _pch ); } bool OPacketCapturer::swapped() const { return pcap_is_swapped( _pch ); } QString OPacketCapturer::version() const { return QString().sprintf( "%d.%d", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); } - +} +} diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index b873b49..dc609a3 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h @@ -1,671 +1,721 @@ /* This file is part of the Opie Project Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OPCAP_H #define OPCAP_H /* OPIE */ #include <opie2/onetutils.h> /* QT */ #include <qevent.h> #include <qfile.h> #include <qhostaddress.h> #include <qobject.h> #include <qstring.h> #include <qtextstream.h> #include <qmap.h> /* STD */ extern "C" // work around a bpf/pcap conflict in recent headers { #include <pcap.h> } #include <netinet/ether.h> #include <netinet/ip.h> #include <netinet/udp.h> #include <netinet/tcp.h> #include <time.h> /* Custom Network Includes (must go here, don't reorder!) */ #include "802_11_user.h" #include "dhcp.h" /* TYPEDEFS */ typedef struct timeval timevalstruct; typedef struct pcap_pkthdr packetheaderstruct; /* FORWARDS */ -class OPacketCapturer; class QSocketNotifier; +namespace Opie { +namespace Net { +class OPacketCapturer; /*====================================================================================== * OPacket - A frame on the wire *======================================================================================*/ /** @brief A class representing a data frame on the wire. * * The whole family of the packet classes are used when capturing frames from a network. * Most standard network protocols in use share a common architecture, which mostly is * a packet header and then the packet payload. In layered architectures, each lower layer * encapsulates data from its upper layer - that is it * treats the data from its upper layer as payload and prepends an own header to the packet, * which - again - is treated as the payload for the layer below. The figure below is an * example for how such a data frame is composed out of packets, e.g. when sending a mail. * * <pre> * | User Data | == Mail Data * | SMTP Header | User Data | == SMTP * | TCP Header | SMTP Header | User Data | == TCP * | IP Header | TCP Header | SMTP Header | User Data | == IP * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC * * </pre> * * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer * also contains a few more levels of encapsulation. * Since the type of the payload is more or less independent from the encapsulating protocol, * the header must be inspected before attempting to decode the payload. Hence, the * encapsulation level varies and can't be deduced without actually looking into the packets. * * For actually working with captured frames, it's useful to identify the packets via names and * insert them into a parent/child - relationship based on the encapsulation. This is why * all packet classes derive from QObject. The amount of overhead caused by the QObject is * not a problem in this case, because we're talking about a theoratical maximum of about * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the * QObject also cares about destroying the sub-, (child-) packets. * * This enables us to perform a simple look for packets of a certain type: * @code * OPacketCapturer* pcap = new OPacketCapturer(); * pcap->open( "eth0" ); * OPacket* p = pcap->next(); * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; * */ class OPacket : public QObject { Q_OBJECT friend class OPacketCapturer; friend QTextStream& operator<<( QTextStream& s, const OPacket& p ); public: OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); virtual ~OPacket(); timevalstruct timeval() const; int caplen() const; int len() const; QString dump( int = 32 ) const; void updateStats( QMap<QString,int>&, QObjectList* ); private: QString dumpStructure() const; QString _dumpStructure( QObjectList* ) const; private: const packetheaderstruct _hdr; // pcap packet header const unsigned char* _data; // pcap packet data const unsigned char* _end; // end of pcap packet data + private: + class Private; + Private *d; }; QTextStream& operator<<( QTextStream& s, const OPacket& p ); /*====================================================================================== * OEthernetPacket - DLT_EN10MB frame *======================================================================================*/ class OEthernetPacket : public QObject { Q_OBJECT public: OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); virtual ~OEthernetPacket(); OMacAddress sourceAddress() const; OMacAddress destinationAddress() const; int type() const; private: const struct ether_header* _ether; + private: + class Private; + Private *d; }; /*====================================================================================== * OPrismHeaderPacket - DLT_PRISM_HEADER frame *======================================================================================*/ class OPrismHeaderPacket : public QObject { Q_OBJECT public: OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); virtual ~OPrismHeaderPacket(); unsigned int signalStrength() const; private: const struct prism_hdr* _header; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanPacket - DLT_IEEE802_11 frame *======================================================================================*/ class OWaveLanPacket : public QObject { Q_OBJECT public: OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); virtual ~OWaveLanPacket(); int duration() const; bool fromDS() const; bool toDS() const; virtual OMacAddress macAddress1() const; virtual OMacAddress macAddress2() const; virtual OMacAddress macAddress3() const; virtual OMacAddress macAddress4() const; bool usesPowerManagement() const; int type() const; int subType() const; int version() const; bool usesWep() const; private: const struct ieee_802_11_header* _wlanhdr; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanManagementPacket - type: management (T_MGMT) *======================================================================================*/ class OWaveLanManagementPacket : public QObject { Q_OBJECT public: OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); virtual ~OWaveLanManagementPacket(); QString managementType() const; int beaconInterval() const; int capabilities() const; // generic bool canESS() const; bool canIBSS() const; bool canCFP() const; bool canCFP_REQ() const; bool canPrivacy() const; private: const struct ieee_802_11_mgmt_header* _header; const struct ieee_802_11_mgmt_body* _body; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanManagementSSID *======================================================================================*/ class OWaveLanManagementSSID : public QObject { Q_OBJECT public: OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); virtual ~OWaveLanManagementSSID(); QString ID( bool decloak = false ) const; private: const struct ssid_t* _data; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanManagementRates *======================================================================================*/ class OWaveLanManagementRates : public QObject { Q_OBJECT public: OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); virtual ~OWaveLanManagementRates(); private: const struct rates_t* _data; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanManagementCF *======================================================================================*/ class OWaveLanManagementCF : public QObject { Q_OBJECT public: OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); virtual ~OWaveLanManagementCF(); private: const struct cf_t* _data; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanManagementFH *======================================================================================*/ class OWaveLanManagementFH : public QObject { Q_OBJECT public: OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); virtual ~OWaveLanManagementFH(); private: const struct fh_t* _data; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanManagementDS *======================================================================================*/ class OWaveLanManagementDS : public QObject { Q_OBJECT public: OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); virtual ~OWaveLanManagementDS(); int channel() const; private: const struct ds_t* _data; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanManagementTim *======================================================================================*/ class OWaveLanManagementTim : public QObject { Q_OBJECT public: OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); virtual ~OWaveLanManagementTim(); private: const struct tim_t* _data; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanManagementIBSS *======================================================================================*/ class OWaveLanManagementIBSS : public QObject { Q_OBJECT public: OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); virtual ~OWaveLanManagementIBSS(); private: const struct ibss_t* _data; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanManagementChallenge *======================================================================================*/ class OWaveLanManagementChallenge : public QObject { Q_OBJECT public: OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); virtual ~OWaveLanManagementChallenge(); private: const struct challenge_t* _data; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanDataPacket - type: data (T_DATA) *======================================================================================*/ class OWaveLanDataPacket : public QObject { Q_OBJECT public: OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); virtual ~OWaveLanDataPacket(); private: const struct ieee_802_11_data_header* _header; + class Private; + Private *d; }; /*====================================================================================== * OWaveLanControlPacket - type: control (T_CTRL) *======================================================================================*/ class OWaveLanControlPacket : public QObject { Q_OBJECT public: OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); virtual ~OWaveLanControlPacket(); QString controlType() const; private: const struct ieee_802_11_control_header* _header; + class Private; + Private *d; }; /*====================================================================================== * OLLCPacket - IEEE 802.2 Link Level Control *======================================================================================*/ class OLLCPacket : public QObject { Q_OBJECT public: OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); virtual ~OLLCPacket(); private: const struct ieee_802_11_802_2_header* _header; + class Private; + Private *d; }; /*====================================================================================== * OIPPacket *======================================================================================*/ class OIPPacket : public QObject { Q_OBJECT public: OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); virtual ~OIPPacket(); QHostAddress fromIPAddress() const; QHostAddress toIPAddress() const; int tos() const; int len() const; int id() const; int offset() const; int ttl() const; int protocol() const; int checksum() const; private: const struct iphdr* _iphdr; + class Private; + Private *d; }; /*====================================================================================== * OARPPacket *======================================================================================*/ class OARPPacket : public QObject { Q_OBJECT public: OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); virtual ~OARPPacket(); QHostAddress senderIPV4Address() const; OMacAddress senderMacAddress() const; QHostAddress targetIPV4Address() const; OMacAddress targetMacAddress() const; //int type() const; QString type() const; private: const struct myarphdr* _arphdr; + class Private; + Private *d; }; /*====================================================================================== * OUDPPacket *======================================================================================*/ class OUDPPacket : public QObject { Q_OBJECT public: OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); virtual ~OUDPPacket(); int fromPort() const; int toPort() const; int length() const; int checksum() const; private: const struct udphdr* _udphdr; + class Private; + Private *d; }; /*====================================================================================== * ODHCPPacket *======================================================================================*/ class ODHCPPacket : public QObject { Q_OBJECT public: ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); virtual ~ODHCPPacket(); QHostAddress clientAddress() const; QHostAddress yourAddress() const; QHostAddress serverAddress() const; QHostAddress relayAddress() const; OMacAddress clientMacAddress() const; bool isRequest() const; bool isReply() const; QString type() const; private: const struct dhcp_packet* _dhcphdr; unsigned char _type; + class Private; + Private *d; }; /*====================================================================================== * OTCPPacket *======================================================================================*/ class OTCPPacket : public QObject { Q_OBJECT public: OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); virtual ~OTCPPacket(); int fromPort() const; int toPort() const; int seq() const; int ack() const; int window() const; int checksum() const; private: const struct tcphdr* _tcphdr; + class Private; + Private *d; }; /*====================================================================================== * OPacketCapturer *======================================================================================*/ /** * @brief A class based wrapper for network packet capturing. * * This class is the base of a high-level interface to the well known packet capturing * library libpcap. * @see http://tcpdump.org */ class OPacketCapturer : public QObject { Q_OBJECT public: /** * Constructor. */ OPacketCapturer( QObject* parent = 0, const char* name = 0 ); /** * Destructor. */ ~OPacketCapturer(); /** * Set the packet capturer to use blocking or non-blocking IO. This can be useful when * not using the socket notifier, e.g. without an application object. */ void setBlocking( bool ); /** * @returns true if the packet capturer uses blocking IO calls. */ bool blocking() const; /** * Close the packet capturer. This is automatically done in the destructor. */ void close(); /** * Close the output capture file. */ void closeDumpFile(); /** * @returns the data link type. * @see <pcap.h> for possible values. */ int dataLink() const; /** * Dump a packet to the output capture file. */ void dump( OPacket* ); /** * @returns the file descriptor of the packet capturer. This is only useful, if * not using the socket notifier, e.g. without an application object. */ int fileno() const; /** * @returns the next @ref OPacket from the packet capturer. * @note If blocking mode is true then this call might block. */ OPacket* next(); /** * @returns the next @ref OPacket from the packet capturer, if * one arrives within @a time milliseconds. */ OPacket* next( int time ); /** * Open the packet capturer to capture packets in live-mode from @a interface. */ bool open( const QString& interface ); /** * Open the packet capturer to capture packets in offline-mode from @a file. */ bool open( const QFile& file ); /** * Open a prerecorded tcpdump compatible capture file for use with @ref dump() */ bool openDumpFile( const QString& filename ); /** * @returns true if the packet capturer is open */ bool isOpen() const; /** * @returns the snapshot length of this packet capturer */ int snapShot() const; /** * @returns true if the input capture file has a different byte-order * than the byte-order of the running system. */ bool swapped() const; /** * @returns the libpcap version string used to write the input capture file. */ QString version() const; /** * @returns the packet statistic database. * @see QMap */ const QMap<QString,int>& statistics() const; signals: /** * This signal is emitted, when a packet has been received. */ void receivedPacket( OPacket* ); protected slots: void readyToReceive(); protected: QString _name; // devicename bool _open; // check this before doing pcap calls pcap_t* _pch; // pcap library handle pcap_dumper_t* _pcd; // pcap dumper handle QSocketNotifier* _sn; // socket notifier for main loop mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap QMap<QString, int> _stats; // statistics; + class Private; // Private Forward declaration + Private *d; // if we need to add data }; +} +} #endif // OPCAP_H diff --git a/libopie2/opienet/ostation.cpp b/libopie2/opienet/ostation.cpp index 8c989d8..140b924 100644 --- a/libopie2/opienet/ostation.cpp +++ b/libopie2/opienet/ostation.cpp @@ -1,64 +1,72 @@ /* This file is part of the Opie Project Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <opie2/ostation.h> #include <opie2/odebug.h> + +using namespace Opie::Core; + +namespace Opie { +namespace Net { /*====================================================================================== * OStation *======================================================================================*/ OStation::OStation() { odebug << "OStation::OStation()" << oendl; type = "<unknown>"; macAddress = OMacAddress::unknown; ssid = "<unknown>"; channel = 0; apAddress = OMacAddress::unknown; } OStation::~OStation() { odebug << "OStation::~OStation()" << oendl; } void OStation::dump() { odebug << "------- OStation::dump() ------------" << oendl; qDebug( "type: %s", (const char*) type ); qDebug( "mac: %s", (const char*) macAddress.toString() ); qDebug( "ap: %s", (const char*) apAddress.toString() ); qDebug( "ip: %s", (const char*) ipAddress.toString() ); } + +} +}
\ No newline at end of file diff --git a/libopie2/opienet/ostation.h b/libopie2/opienet/ostation.h index 1e7366d..68f1114 100644 --- a/libopie2/opienet/ostation.h +++ b/libopie2/opienet/ostation.h @@ -1,73 +1,82 @@ /* This file is part of the Opie Project Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OSTATION_H #define OSTATION_H #include <opie2/onetutils.h> #include <qlist.h> #include <qstring.h> #include <qhostaddress.h> #include <qobject.h> #include <sys/types.h> +namespace Opie { +namespace Net { + class OStation; + typedef QList<OStation> OStationList; /*====================================================================================== * OStation *======================================================================================*/ class OStation { public: OStation(); ~OStation(); void dump(); /* Ethernet */ QString type; OMacAddress macAddress; QHostAddress ipAddress; /* WaveLan */ QString ssid; OMacAddress apAddress; int channel; bool encrypted; + private: + class Private; + Private *d; }; +} +} #endif // OSTATION_H |