Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Portable.h

Go to the documentation of this file.
00001 /*
00002  * Dibbler - a portable DHCPv6
00003  *
00004  * authors: Tomasz Mrugalski <thomson@klub.com.pl>
00005  *          Marek Senderski <msend@o2.pl>
00006  *
00007  * Released under GNU GPL v2 licence
00008  *
00009  * $Id: Portable.h,v 1.32 2004/12/27 20:45:00 thomson Exp $
00010  *
00011  * $Log: Portable.h,v $
00012  * Revision 1.32  2004/12/27 20:45:00  thomson
00013  * 0.3.1 version.
00014  *
00015  * Revision 1.31  2004/12/15 22:54:45  thomson
00016  * no message
00017  *
00018  * Revision 1.30  2004/12/07 00:45:41  thomson
00019  * Clnt managers creation unified and cleaned up.
00020  *
00021  * Revision 1.29  2004/12/04 23:45:40  thomson
00022  * Problem with client and server on the same Linux host fixed (bug #56)
00023  *
00024  * Revision 1.28  2004/11/15 20:59:12  thomson
00025  * 0.3.0-RC2
00026  *
00027  * Revision 1.27  2004/11/01 23:31:25  thomson
00028  * New options,option handling mechanism and option renewal implemented.
00029  *
00030  * Revision 1.26  2004/10/25 20:45:54  thomson
00031  * Option support, parsers rewritten. ClntIfaceMgr now handles options.
00032  *
00033  * Revision 1.25  2004/10/03 21:53:15  thomson
00034  * strncasecmp macro added (win32)
00035  *
00036  * Revision 1.24  2004/10/03 21:28:45  thomson
00037  * 0.2.1-RC1 version.
00038  *
00039  * Revision 1.23  2004/09/05 15:27:49  thomson
00040  * Data receive switched from recvfrom to recvmsg, unicast partially supported.
00041  *
00042  * Revision 1.21  2004/07/11 14:09:11  thomson
00043  * 0.2.0-RC2
00044  *
00045  * Revision 1.18  2004/06/04 19:03:47  thomson
00046  * Resolved warnings with signed/unisigned
00047  *
00048  * Revision 1.17  2004/05/23 23:45:45  thomson
00049  * logLevel works (finally...)
00050  *
00051  * Revision 1.15  2004/03/29 22:06:49  thomson
00052  * 0.1.1 version
00053  */
00054 
00055 #ifndef PORTABLE_H
00056 #define PORTABLE_H
00057 
00058 //#define DIBBLER_VERSION "0.3.1-CVS (" __DATE__ " " __TIME__ ")"
00059 #define DIBBLER_VERSION "0.3.1"
00060 
00061 #define DIBBLER_COPYRIGHT1 "| Dibbler - a portable DHCPv6, version " DIBBLER_VERSION
00062 #define DIBBLER_COPYRIGHT2 "| Authors : Tomasz Mrugalski<thomson@klub.com.pl>,Marek Senderski<msend@o2.pl>"
00063 #define DIBBLER_COPYRIGHT3 "| Licence : GNU GPL v2 or later. Developed at Gdansk University of Technology."
00064 #define DIBBLER_COPYRIGHT4 "| Homepage: http://klub.com.pl/dhcpv6/"
00065 
00066 #ifdef LINUX
00067 #include <netinet/in.h>
00068 #include <stdio.h>
00069 #include <stdlib.h>
00070 #include <unistd.h>
00071 #include <resolv.h>
00072 #include <sys/socket.h>
00073 #include <sys/select.h>
00074 #include <sys/time.h>
00075 #include <arpa/inet.h>
00076 #include <ctype.h>
00077 #include <stdarg.h>
00078 #include <string.h>
00079 #endif 
00080 
00081 // **********************************************************************
00082 // *** file setup/default paths *****************************************
00083 // **********************************************************************
00084 
00085 #define CLNTCFGMGR_FILE   "client-CfgMgr.xml"
00086 #define CLNTIFACEMGR_FILE "client-IfaceMgr.xml"
00087 #define CLNTDUID_FILE     "client-duid"
00088 #define CLNTLOG_FILE      "client.log"
00089 #define CLNTADDRMGR_FILE  "client-AddrMgr.xml"
00090 #define CLNTTRANSMGR_FILE "client-TransMgr.xml"
00091 
00092 #define SRVCFGMGR_FILE    "server-CfgMgr.xml"
00093 #define SRVIFACEMGR_FILE  "server-IfaceMgr.xml"
00094 #define SRVDUID_FILE      "server-duid"
00095 #define SRVLOG_FILE       "server.log"
00096 #define SRVADDRMGR_FILE   "server-AddrMgr.xml"
00097 #define SRVTRANSMGR_FILE  "server-TransMgr.xml"
00098 
00099 // false - normal operation
00100 // true - Linux: client and server can be run on the same host, but
00101 //        there is also a drawback: multiple clients can be run at once.
00102 #define CLIENT_BIND_REUSE false
00103 
00104 #ifdef WIN32
00105 #define WORKDIR           ".\\"
00106 #define CLNTCONF_FILE     "client.conf"
00107 #define SRVCONF_FILE      "server.conf"
00108 #define NULLFILE          "nul"
00109 #endif
00110 
00111 #ifdef LINUX
00112 #define WORKDIR           "/var/lib/dibbler"
00113 #define CLNTCONF_FILE     "/var/lib/dibbler/client.conf"
00114 #define SRVCONF_FILE      "/var/lib/dibbler/server.conf"
00115 #define RESOLVCONF_FILE   "/etc/resolv.conf"
00116 #define CLNTPID_FILE      "client.pid"
00117 #define SRVPID_FILE       "server.pid"
00118 #define NULLFILE          "/dev/null"
00119 #endif
00120 
00121 // --- options ---
00122 #define OPTION_DNS_SERVERS_FILENAME  "option-dns-servers"
00123 #define OPTION_DOMAINS_FILENAME      "option-domains"
00124 #define OPTION_NTP_SERVERS_FILENAME  "option-ntp-servers"
00125 #define OPTION_TIMEZONE_FILENAME     "option-timezone"
00126 #define OPTION_SIP_SERVERS_FILENAME  "option-sip-servers"
00127 #define OPTION_SIP_DOMAINS_FILENAME  "option-sip-domains"
00128 #define OPTION_NIS_SERVERS_FILENAME  "option-nis-servers"
00129 #define OPTION_NIS_DOMAIN_FILENAME   "option-nis-domain"
00130 #define OPTION_NISP_SERVERS_FILENAME "option-nisplus-servers"
00131 #define OPTION_NISP_DOMAIN_FILENAME  "option-nisplus-domain"
00132 
00133 // **********************************************************************
00134 // *** interface flags **************************************************
00135 // **********************************************************************
00136 
00137 #ifdef WIN32
00138 #define MAX_IFNAME_LENGTH 255
00139 #define LOGLEVEL        0
00140 #define IF_RUNNING      0x1
00141 #define IF_UP           0x1
00142 #define IF_MULTICAST    0x4
00143 #define IF_LOOPBACK     0x8
00144 #endif
00145 
00146 #ifdef LINUX
00147 #define MAX_IFNAME_LENGTH 64
00148 #define LOGLEVEL        0
00149 #define IF_UP           0x1
00150 #define IF_LOOPBACK     0x8  
00151 #define IF_RUNNING      0x40
00152 #define IF_MULTICAST    0x1000
00153 #endif
00154 
00155 // **********************************************************************
00156 // *** time related functions *******************************************
00157 // **********************************************************************
00158 
00159 #ifdef WIN32
00160 #define strncasecmp _strnicmp
00161 #include <windows.h>
00162 #include <time.h>
00163 #endif
00164 
00165 #define now() (unsigned) time(NULL)
00166 
00167 // **********************************************************************
00168 // *** interface/socket low level functions *****************************
00169 // **********************************************************************
00170 
00171 #ifdef __cplusplus 
00172 extern "C" {
00173 #endif
00174 
00175 extern struct iface * if_list_get();
00176 extern void if_list_release(struct iface * list);
00177     
00178 /* add address to interface */
00179 extern int ipaddr_add(const char* ifacename, int ifindex, const char* addr, 
00180                       unsigned long pref, unsigned long valid);
00181 extern int ipaddr_del(const char* ifacename, int ifindex, const char* addr);
00182 
00183 /* add socket to interface */
00184 extern int sock_add(char* ifacename,int ifaceid, char* addr, int port, int thisifaceonly, int reuse);
00185 extern int sock_del(int fd);
00186 extern int sock_send(int fd, char* addr, char* buf, int buflen, int port, int iface);
00187 extern int sock_recv(int fd, char* myPlainAddr, char* peerPlainAddr, char* buf, int buflen);
00188 
00189 /* pack/unpack address */
00190 extern void print_packed(char addr[]);
00191 extern int inet_pton4(const char* src, char* dst);
00192 extern int inet_pton6(const char* src, char* dst);
00193 extern char * inet_ntop4(const char* src, char* dst);
00194 extern char * inet_ntop6(const char* src, char* dst);
00195 extern void print_packed(char * addr);
00196 extern int is_addr_tentative(char* ifacename, int iface, char* plainAddr);
00197 /* microsleep(int microsecs) */
00198 extern void microsleep(int microsecs);
00199 
00200 /* DNS */
00201 extern int dns_add(const char* ifname, int ifindex, const char* addrPlain);
00202 extern int dns_del(const char* ifname, int ifindex, const char* addrPlain);
00203 extern int domain_add(const char* ifname, int ifindex, const char* domain);
00204 extern int domain_del(const char* ifname, int ifindex, const char* domain);
00205 extern int ntp_add(const char* ifname, int ifindex, const char* addrPlain);
00206 extern int ntp_del(const char* ifname, int ifindex, const char* addrPlain);
00207 extern int timezone_set(const char* ifname, int ifindex, const char* timezone);
00208 extern int timezone_del(const char* ifname, int ifindex, const char* timezone);
00209 extern int sipserver_add(const char* ifname, int ifindex, const char* addrPlain);
00210 extern int sipserver_del(const char* ifname, int ifindex, const char* addrPlain);
00211 extern int sipdomain_add(const char* ifname, int ifindex, const char* domain);
00212 extern int sipdomain_del(const char* ifname, int ifindex, const char* domain);
00213 extern int nisserver_add(const char* ifname, int ifindex, const char* addrPlain);
00214 extern int nisserver_del(const char* ifname, int ifindex, const char* addrPlain);
00215 extern int nisdomain_set(const char* ifname, int ifindex, const char* domain);
00216 extern int nisdomain_del(const char* ifname, int ifindex, const char* domain);
00217 
00218 extern int nisplusserver_add(const char* ifname, int ifindex, const char* addrPlain);
00219 extern int nisplusserver_del(const char* ifname, int ifindex, const char* addrPlain);
00220 extern int nisplusdomain_set(const char* ifname, int ifindex, const char* domain);
00221 extern int nisplusdomain_del(const char* ifname, int ifindex, const char* domain);
00222 
00223 #ifdef __cplusplus
00224 }
00225 #endif
00226 
00227 #ifndef MAX_IFNAME_LENGTH 
00228 #define MAX_IFNAME_LENGTH 255
00229 #endif
00230 
00231 struct iface {
00232     char name[MAX_IFNAME_LENGTH];  // interface name
00233     int  id;                       // interface ID (often called ifindex)
00234     int  hardwareType;             // type of hardware (see RFC 826)
00235     char mac[255];                 // link layer address
00236     int  maclen;                   // length of link layer address
00237     char *linkaddr;                // assigned IPv6 link local addresses 
00238     int  linkaddrcount;            // number of assigned IPv6 link local addresses
00239     unsigned int flags;            // look IF_xxx in portable.h
00240     struct iface* next;            // structure describing next iface in system
00241 };
00242 
00243 #endif
00244 

Generated on Mon Dec 27 21:55:22 2004 for Dibbler - a portable DHCPv6 by  doxygen 1.3.9.1