/*
 *  Copyright (c) 1996-2007 Digi International Inc., All Rights Reserved
 *
 *  This software contains proprietary and confidential information of Digi
 *  International Inc.  By accepting transfer of this copy, Recipient agrees
 *  to retain this software in confidence, to prevent disclosure to others,
 *  and to make no use of this software other than that for which it was
 *  delivered.  This is an unpublished copyrighted work of Digi International
 *  Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
 *  prohibited.
 *
 *  Restricted Rights Legend
 *
 *  Use, duplication, or disclosure by the Government is subject to
 *  restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
 *  Technical Data and Computer Software clause at DFARS 252.227-7031 or
 *  subparagraphs (c)(1) and (2) of the Commercial Computer Software -
 *  Restricted Rights at 48 CFR 52.227-19, as applicable.
 *
 *  Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 *
 * =======================================================================
 * This file contains the application programming interface routine
 * declarations for narmcore.lib.
 *                                                                        
 *                                                                        
 * Edit Date/Ver    Edit Description
 * ==============   ===================================================
 *  PMJ 06/13/00    Changed prototype NAinet_addr to NAInet_addr
 *  JFU 8/2/00	    Updated text from NETOS
 *  PMJ 01/02/01    Removed unused functions NAENIProcCreate, NAENIProcStart
 *                  and NAENITransmit.
 *  PMJ 01/02/01    Removed private functions NASetDefaultGateway, NAInit_socket and 
 *                  NAENIProcStart
 *
 *
 */
 
#ifndef __NARMAPI_H
#define __NARMAPI_H

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdio.h>

#if NETWORK_STACK == TRECK
#include "nastatus.h"
#include "sockapi.h"
#endif
    
/* 
 * NAinet_addr
 * 
 * This routine converts a string containing an Internet Protocol dotted address
 * a.b.c.d, a.b.c, a.b, a, into a proper address. 
 *
 * INPUTS
 *
 *    addrp     Points to a null terminated charactersting representing
 *              an IP address. 
 * RETURNS
 *
 *    4 byte Internet Address
 * 
 */
unsigned long NAInet_addr(char *addrp);

/*
 * NAInet_toa
 *
 * This routine takes an IP address in the form of an unsigned long
 * and converts it to the dot notation (a.b.c.d).
 *
 * INPUTS
 *
 *    ulipaddr    Unsigned long format of ip address to convert.
 *    destp       Destination of character representation. WARNING destp
 *                must be no less than 16 characters long [15 characters
 *                plusa the NULL terminator].
 */

void NAInet_toa (unsigned long ulipaddr, char *destp);

char * NAStrccpy(char * const dest, char const * const src, size_t const count);

#if NETWORK_STACK == TRECK
int na_pton(const char *ipstring, struct sockaddr_storage * ipaddress);
NaStatus na_ntop(int af, struct sockaddr_storage * src, char * dst, int dst_size);
#endif /* NETWORK_STACK == TRECK */

/*
 *
 * Checks the combinations of IP address and subnet mask and gateway and subnet mask for
 * validity.  
 *
 * @param     ipAddress     IP address in unsigned long format
 * @param     subnetMask    Subnet Mask in unsigned long format
 * @param     gateWay       Gateway address in unsigned long format
 *
 * @return     VALIDIP             	IP Address is valid
 * @return     NOSUBNETTING	    	IP Address can not be subnetted.
 * @return     ZEROIPNOTALLOWED    	IP Address 0.0.0.0 is not allowed.
 * @return     IPANDGWMATCH        	IP Address and Gateway Address are the same.
 * @return     IPORGWISMULTICAST   	IP Address or Gatweay Address is > 223.
 * @return     IPORGWISLOCALLOOP   	IP Address or Gatweay Address is 127.
 * @return     ZEROOCTETNOTALLOWED 	Zero is not allowed in leftmost octet of IP Address.
 * @return     ZEROMASKNOTALLOWED  	Subnet mask 0.0.0.0 not allowed.
 * @return     MAXSUBNETEXCEEDED   	Subnet mask can not exceed 255.255.255.252
 * @return     IPISNETWORKID       	IP Address is network ID.
 * @return     IPISBROADCAST       	IP Address is network broadcast address.
 * @return     GWISNETWORKID       	Gateway Address is network ID.
 * @return     GWISBROADCAST       	Gateway Address is network broadcast address.
 * @return     GWNOTONSUBNET       	Gateway Address is not on subnet.
 *
 * 
 * @since 7.0
 *
*/ 
int naValidateNetworkInformation(unsigned long ipAddress, unsigned long subnetMask, unsigned long gateWay);
int naValidateIpv6Information(struct sockaddr_storage * ipAddrPtr, int prefixLen);
int naValidateIpAddress(unsigned long ipAddress);


/*
 * NET+ARM API error codes
 *
 */
#define NA_EVENT_ERR     (0x1001)
#define NA_TIMER_ERR     (0x1002)
#define NA_SOCKET_ERR    (0x1003)
#define NA_IOCTL_ERR     (0x1004)
#define NA_SOCKOPT_ERR   (0x1005)
#define NA_BIND_ERR      (0x1006)
#define NA_NOTFOUND_ERR  (0x1007)
#define NA_BADSTATE_ERR  (0x1008)
#define NA_NOSUPPORT_ERR (0x1009)
#define NA_BADARGS_ERR   (0x100A)
#define NA_SOCKSEND_ERR  (0x100B)
#define NA_SOCKRECV_ERR  (0x100C)
#define NA_SOCKINIT_ERR  (0x100D)
#define NA_SOCKCONN_ERR  (0x100E)
#define NA_PROTO_ERR     (0x100F)

#ifdef __cplusplus
}
#endif

#endif
