/* Packet.h Copyright (C) 2003 Mike Saywell Southampton Open Wireless Network, http://www.sown.org.uk This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "AddressManager.h" using namespace std; /* Aladin protocol layout (bits) 0.......8......16......24......32 --------------------------------- | Type | Reserved | +-------------------------------+ _ | Network | \ | Netmask | > Used by ALADIN_REPLY --------------------------------- _/ Every aladin message is one of the following basic types, this in itself is sufficient except for the REPLY case where an IP and netmask need to be communicated. *** Types *** */ static u_char ALADIN_INVALID = 0; static u_char ALADIN_HELLO = 1; static u_char ALADIN_REQUEST = 2; static u_char ALADIN_REPLY = 3; static u_char ALADIN_ACK = 4; // Ethertype reserved to DEC but unassigned, hopefully they wont mind :) // Tried using one from the experimental range but got mixed results, bug?? static uint16_t ALADIN_PROTOCOL = 0x8039; static size_t ALADIN_LEN=50; class Packet { private: u_char type; struct sockaddr dst; u_int32_t network; u_int32_t netmask; public: Packet(u_char t); u_char getType(); void setType(u_char t); int genPkt(u_char* msg); void prnType(char* type); void reset(); void setNetwork(struct in_addr* net); void setNetmask(struct in_addr* mask); u_int32_t getNetwork(); u_int32_t getNetmask(); static int send(Packet* p, int if_id); static int receive(Packet* p, int if_id, int timeout); static int parse(u_char* raw, Packet* p); };