/* Name:  Chuck Winters
 * Corp:  Lockheed Martin ATL
 * Date:  26 April, 2002
 * File:  basic_common.h
 * Desc:  Common defines and functions
*/

#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>

#ifndef __BASIC_COMMON_H__
#define __BASIC_COMMON_H__
#define TCP 1
#define SCTP 2

#define PROTO_TYPE SCTP

#if ( PROTO_TYPE == TCP )
#include <netinet/tcp.h>
#undef PROTO_TYPE
#define PROTO_TYPE IPPROTO_TCP
#elif ( PROTO_TYPE == SCTP )
#include <netinet/sctp.h>
#undef PROTO_TYPE
#define PROTO_TYPE IPPROTO_SCTP
#else
#undef PROTO_TYPE
#error "Only TCP and SCTP are supported protocols"
#endif


#if (PROTO_TYPE == IPPROTO_TCP)
#define SOCKET_TYPE SOCK_STREAM
#define PROTO_LEVEL SOL_TCP
#define PROTO_DELAY TCP_NODELAY
#elif (PROTO_TYPE == IPPROTO_SCTP)
#define SOCKET_TYPE SOCK_SEQPACKET
#define PROTO_LEVEL SOL_SCTP
#define PROTO_DELAY SCTP_NODELAY
#endif

/** Change these to your liking **/
#define MAX_ARGLEN 20
#define ACK_MSG_LEN 1
#define ACK_MSG "\0"
#define MSG_LEN 13
#define MSG_NUM 2
#define MSG { "Hello World", "Cruel  World" }
#define DEFAULT_REMOTE_PORT 1029
#define DEFAULT_LOCAL_PORT 42365
#define DEFAULT_NUM_MSGS 100
#define MAX_REMOTE_ADDRS 12
#define SLEEP_TIME 2

/** Options for basic_s and basic_c **/
#define HELP_CHAR 'h'
#define ACK_CHAR 'a'
#define NUM_CHAR 'n'
#define LINGER_CHAR 'l'
#define DELAY_CHAR 'd'
#define REMOTE_PORT_CHAR 'r'
#define LOCAL_PORT_CHAR 'p'
#define SEND_RECV_CHAR 's'
#define SEND_RECV_MSG_CHAR 'm'
#define LOCAL_ADDR_CHAR 'b'
#define SLEEP_CHAR 'e'
#define OPT_STRING "+healdmsn:p:b:r:"

#define bad_arg_opt(opt_char) do{ \
	                                fprintf(stderr, "Bad arg %s to option -%c\n", optarg, opt_char);\
                                }while(0)

#define OPT_ACK 0x001
#define OPT_LINGER 0x002
#define OPT_DELAY 0x004
#define OPT_SEND_RECV 0x008
#define OPT_SEND_RECV_MSG 0x010
#define OPT_PORT 0x020
#define OPT_SLEEP 0x040

#define print_sockaddr_in(f, s) do{ \
	                                fprintf(f, "   Port    %u\n", ntohs((s)->sin_port)); \
																	fprintf(f, "   Address %s\n", inet_ntoa((s)->sin_addr)); \
																  }while(0)

static int on = 1;
static int off = 0;

#endif /* #ifndef __BASIC_COMMON_H__ */
