/*

                                   _JNJ`                        
                               .JNMH`                           
                              JMMF`       `;.                   
                            .NMM)          `MN.                 
                            MMM)            (MML                
                           (MMM`             MMML               
                     M  I  D  N  I  G  H  T    C  o  D  E       
                           (NMMF             MHNH               
                            NMML            .MMM                
                             NMML          .NMH                 
                              4MMNL       .#F                   
                               `4HNNL_   `                      
                                   `"""`                        

                          Copyright (C) 2004-2007
       "Ian (Larry) Latter" <ian dot latter at midnightcode dot org>

    Midnight Code is a registered trademark of Ian Latter.

    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, and mirrored at the Midnight Code web
    site; as at version 2 of the License only.
  
    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
    (version 2) along with this program; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA, or see http://midnightcode.org/gplv2.txt

*/


/* midnightcode-bootp.h :: Midnight Code Bootp/Dhcp library		*/


#ifndef __MIDNIGHTCODE_BOOTP_H
#define __MIDNIGHTCODE_BOOTP_H 1


#define MIDNIGHTCODE_BOOTP_STRUCTURE "bootp"

#define MIDNIGHTCODE_BOOTP_CLIENT_XID 0xbeef 
#define MIDNIGHTCODE_BOOTP_CLIENT_TIMEOUT 3
#define MIDNIGHTCODE_BOOTP_CLIENT_RETRIES_OFFER 3
#define MIDNIGHTCODE_BOOTP_CLIENT_RETRIES_REQUEST 3
#define MIDNIGHTCODE_BOOTP_CLIENT_RETRIES 2
#define MIDNIGHTCODE_BOOTP_CLIENT_PORT 68
#define MIDNIGHTCODE_BOOTP_SERVER_PORT 67

enum midnightcode_action_opcode_t
{
  MIDNIGHTCODE_BOOTP_ACTION_UNKNOWN = 0,
  MIDNIGHTCODE_BOOTP_ACTION_CONFIGURE,
  MIDNIGHTCODE_BOOTP_ACTION_RELEASE
};

enum midnightcode_bootp_opcode_t
{
  MIDNIGHTCODE_BOOTP_OPCODE_UNKNOWN = 0,
  MIDNIGHTCODE_BOOTP_OPCODE_BOOTREQUEST,
  MIDNIGHTCODE_BOOTP_OPCODE_BOOTREPLY
};

enum midnightcode_bootp_option_t
{
  MIDNIGHTCODE_BOOTP_OPTION_PAD = 0,
  MIDNIGHTCODE_BOOTP_OPTION_SUBNETMASK,
  MIDNIGHTCODE_BOOTP_OPTION_TIMEOFFSET,
  MIDNIGHTCODE_BOOTP_OPTION_GATEWAY,
  MIDNIGHTCODE_BOOTP_OPTION_TIMESERVER,
  MIDNIGHTCODE_BOOTP_OPTION_NAMESERVER,
  MIDNIGHTCODE_BOOTP_OPTION_DOMAINNAMESERVER,
  MIDNIGHTCODE_BOOTP_OPTION_LOGSERVER,
  MIDNIGHTCODE_BOOTP_OPTION_QUOTESERVER,
  MIDNIGHTCODE_BOOTP_OPTION_LPRSERVER,
  MIDNIGHTCODE_BOOTP_OPTION_IMPRESSSERVER,
  MIDNIGHTCODE_BOOTP_OPTION_RLPSERVER,
  MIDNIGHTCODE_BOOTP_OPTION_HOSTNAME,
  MIDNIGHTCODE_BOOTP_OPTION_BOOTFILESIZE,
  MIDNIGHTCODE_BOOTP_OPTION_MERITDUMPFILE,
  MIDNIGHTCODE_BOOTP_OPTION_DOMAINNAME,
  MIDNIGHTCODE_BOOTP_OPTION_SWAPSERVER,
  MIDNIGHTCODE_BOOTP_OPTION_ROOTPATH,
  MIDNIGHTCODE_BOOTP_OPTION_EXTENSIONPATH,
  MIDNIGHTCODE_BOOTP_OPTION_IPFORWARDING,
  MIDNIGHTCODE_BOOTP_OPTION_SOURCEROUTING,
  MIDNIGHTCODE_BOOTP_OPTION_POLICYFILTER,
  MIDNIGHTCODE_BOOTP_OPTION_MAXDATAGRAMSIZE,
  MIDNIGHTCODE_BOOTP_OPTION_IPTTL,
  MIDNIGHTCODE_BOOTP_OPTION_PATHMTUAGING,
  MIDNIGHTCODE_BOOTP_OPTION_PATHMTUPLATEAU,
  MIDNIGHTCODE_BOOTP_OPTION_MTU,
  MIDNIGHTCODE_BOOTP_OPTION_ALLSUBNETSLOCAL,
  MIDNIGHTCODE_BOOTP_OPTION_BROADCASTADDRESS,
  MIDNIGHTCODE_BOOTP_OPTION_MASKDISCOVERY,
  MIDNIGHTCODE_BOOTP_OPTION_MASKSUPPLIER,
  MIDNIGHTCODE_BOOTP_OPTION_ROUTERDISCOVERY,
  MIDNIGHTCODE_BOOTP_OPTION_ROUTERSOLICITADDRESS,
  MIDNIGHTCODE_BOOTP_OPTION_STATICROUTE,
  MIDNIGHTCODE_BOOTP_OPTION_ARPTRAILERENCAP,
  MIDNIGHTCODE_BOOTP_OPTION_ARPCACHETIMEOUT,
  MIDNIGHTCODE_BOOTP_OPTION_ETHERNETENCAP,
  MIDNIGHTCODE_BOOTP_OPTION_TCPTTL,
  MIDNIGHTCODE_BOOTP_OPTION_TCPKEEPALIVE,
  MIDNIGHTCODE_BOOTP_OPTION_TCPKEEPALIVEGARBAGE,
  MIDNIGHTCODE_BOOTP_OPTION_NISDOMAIN,
  MIDNIGHTCODE_BOOTP_OPTION_NISSERVER,
  MIDNIGHTCODE_BOOTP_OPTION_NTPSERVER,
  MIDNIGHTCODE_BOOTP_OPTION_VENDORID,
  MIDNIGHTCODE_BOOTP_OPTION_NETBIOSNS,
  MIDNIGHTCODE_BOOTP_OPTION_NETBIOSDD,
  MIDNIGHTCODE_BOOTP_OPTION_NETBIOSNODETYPE,
  MIDNIGHTCODE_BOOTP_OPTION_NETBIOSTCPSCOPE,
  MIDNIGHTCODE_BOOTP_OPTION_XFONTSERVER,
  MIDNIGHTCODE_BOOTP_OPTION_XDISPLAYSERVER,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPREQUESTIP,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPLEASETIME,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPOVERLOAD,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPMESSAGETYPE,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPSERVERID,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPPARAMREQUEST,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPMESSAGE,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPMAXMESSAGESIZE,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPRENEWALTIME,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPREBINDINGTIME,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPCLASSID,
  MIDNIGHTCODE_BOOTP_OPTION_DHCPCLIENTID,
  MIDNIGHTCODE_BOOTP_OPTION_END = 255
};

enum midnightcode_bootp_dhcp_t
{
  MIDNIGHTCODE_BOOTP_DHCP_DISCOVER = 1,
  MIDNIGHTCODE_BOOTP_DHCP_OFFER,
  MIDNIGHTCODE_BOOTP_DHCP_REQUEST,
  MIDNIGHTCODE_BOOTP_DHCP_DECLINE,
  MIDNIGHTCODE_BOOTP_DHCP_ACK,
  MIDNIGHTCODE_BOOTP_DHCP_NAK,
  MIDNIGHTCODE_BOOTP_DHCP_RELEASE
};


struct midnightcode_bootp_message_t
{
  unsigned char op;
  unsigned char htype;
  unsigned char hlen;
  unsigned char hops;
  unsigned int xid;
  unsigned short secs;
  unsigned short flags;
  struct in_addr ciaddr;
  struct in_addr yiaddr;
  struct in_addr siaddr;
  struct in_addr giaddr;
  unsigned char chaddr[16];
  char sname[64];
  char file[128];
  unsigned char options[312];
};

int midnightcode_bootp_write_option(unsigned char ** option_up, int option,
                  int * buffer_max_p, void * value_p, int value_len);
int midnightcode_bootp_read_option(unsigned char ** option_up,
                  struct midnightcode_interface_element_t ** interface_p,
                  char * buffer_max_p);
int midnightcode_bootp_open(
                  struct midnightcode_interface_element_t ** interface_p,
                  struct midnightcode_socket_element_t ** socket_p);
int midnightcode_bootp_write(int dhcp_message,
                  struct midnightcode_interface_element_t ** interface_p,
                  struct midnightcode_socket_element_t * socket);
int midnightcode_bootp_read(int dhcp_message,
                  struct midnightcode_interface_element_t ** interface_p,
                  struct midnightcode_socket_element_t * socket);
int midnightcode_bootp(int action,
                  struct midnightcode_interface_element_t ** interface_p);

#endif
