Logo Studenta

UC3M _Universidad Carlos III de Madrid_ _ Máster en Ingeniería de Telecomunicaciones _ Programación C y Java Telecomunicaciones _ code conf_

Esta es una vista previa del archivo. Inicie sesión para ver el archivo original

conf.h
/*******************************************************/
/* conf.h */
/*******************************************************/
#ifndef SIMPLECONF_H
#define SIMPLECONF_H
#include <sys/time.h>
#include <unistd.h>
/* -------------------------------------------------------------------------------- */
/* DEFINITIONS */
enum operat {FIRST, SECOND};
enum payload {PCMU=100, L16_1=11};
#define MaxNameLength 100
#ifndef CALL
#define CALL(v,m) {if ( (v)==-1) {perror (m); printf ("Error number: %d, %s\n", errno, strerror (errno)); exit (1); }};
#endif
/* to be used by first before knowing the length of the audio data */
#define MaxLongBuffer 65536
/* read 'rtp.h', which defines structures that complement the following one */ 
#endif /* SIMPLE_H */
confArgs.c
/*******************************************************/
/* confArgs.c */
/*******************************************************/
/* Captures arguments for 'conf' application */
/* Al alternative to this code is to base it on the Linux standard function 'getopt_long' */
#include "conf.h"
#include "confArgs.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <string.h> 
void captureFirst (int argc, char *argv[], char * firstMulticastIP, int * port, int *vol, int * verbose, int * bufferingTime);
void captureSecond (int argc, char *argv[], char * firstIP, int * port, int *vol, int * packetDuration, int *payload, int * verbose, int * bufferingTime);
/*=====================================================================*/
void printValues (int operation, const char * firstIP, const char * firstMulticastIP, int port, int vol, int packetDuration, int verbose, int payload, int bufferingTime)
{
	if (operation == FIRST) { 
		printf ("FIRST mode.\n");
		if (firstMulticastIP[0] == '\0') {
 	 	 printf ("Unicast IP address requested for first.\n");
 	 	}
 	 	else printf ("Multicast IP address requested for first: %s\n", firstMulticastIP);
 	 	
 	 	printf ("Packet duration %d ms.\n", packetDuration);
 	}		
 	else if (operation == SECOND) {
 		printf ("SECOND mode");
 		if (payload == PCMU)
 		{
 			printf (" with 8 bits, single channel, mu law.\n");
 		}
 		else if (payload == L16_1)
 		{
 			printf (" with PCM 16 bits, singleChannel.\n");
 		}
 		printf ("Address of first node: %s.\n", firstIP);
 
 	}
 printf ("Port used %d.\n", port);
 printf ("Volume %d.\n", vol);
 printf ("Requested buffering time: %d ms.\n", bufferingTime);
 if (verbose)
 {
 printf ("Verbose mode ON.\n");
 }
 else printf ("Verbose mode OFF.\n");
 
};
/*=====================================================================*/
void printHelp (void)
{
 printf ("\nconf first [-pLOCAL_RTP_PORT] [-c] [-vVOL] [-mMULTICAST_ADDR] [-kACCUMULATED_TIME]"
"\nconf second addressOfFirst [-pLOCAL_RTP_PORT] [-c] [-vVOL] [-lPACKET_DURATION] [-kACCUMULATED_TIME] [-yPAYLOAD]\n\n(NOTE: firstName can be either a name or an IP address\n\n");
}
/* Insert default values */
/*=====================================================================*/
void defaultValues (int *operation, char * firstIP, char * firstMulticastIP, int *port, int *vol, int *packetDuration, int *verbose, int *payload, int * bufferingTime)
{
 (*operation) = FIRST; /* not very useful, but removes gcc warning about unused operation variable */
	
 firstMulticastIP[0] = '\0';
 firstIP[0] = '\0';
 *port = 5004;
 (*vol) = 90;
 (*packetDuration) = 20; /* 20 ms */
 (* payload) = PCMU;
 (* verbose) = 0; 
 (* bufferingTime) = 100; /* 100 ms */
};
/*=====================================================================*/
void captureArguments (int argc, char *argv[], int *operation, char * firstIP, char * firstMulticastIP, int *port, int *vol, int *packetDuration, int *verbose, int *payload, int *bufferingTime)
{
 if (argc==1)
 { 
 printf ("I need to know if mode is 'first' or 'second'\n\n");	 
 printHelp ();
 exit (1); /* error */
 }
 defaultValues (operation, firstIP, firstMulticastIP, port, vol, packetDuration, verbose, payload, bufferingTime);
 /* the first argument is always the role played by the host */
 if (strcmp ("first", argv[1]) == 0)
 {
 (*operation) = FIRST;
 (*payload)=0; /* set to 0 in 'first' */
 
 if (argc > 2) /* need to obtain more arguments than './conf first' */
	{
	 captureFirst (argc-1, argv, firstMulticastIP, port, vol, verbose, bufferingTime);
	}
 }
 else if (strcmp ("second", argv[1]) == 0)
 {
 (*operation) = SECOND;
 captureSecond (argc-1, argv, firstIP, port, vol, packetDuration, payload, verbose, bufferingTime);
 }
 else 
 {
 printf ("Operation could not be identified: expecting 'first' or 'second'.\n\n");
 printHelp();
 exit (1); /* error */
 }
}
/*=====================================================================*/
void captureFirst (int argc, char *argv[], char * firstMulticastIP, int * port, int *vol, int * verbose, int * bufferingTime)
{
 int index, mostSignificantAddressComponent;
 char character;
 for ( index=2; argc>1; ++index, --argc)
 {
 if ( *argv[index] == '-')
	{ 
	 character= *(++argv[index]);
	 switch (character)
	 { 
	 case 'p': /* RTP PORT for FIRST*/ 
		if ( sscanf (++argv[index],"%d", port) != 1)
		 { 
		 printf ("\n-p must be followed by a number\n");
		 exit (1); /* error */
		 }
 
	
		if ( ! (( (*port) >= 1024) && ( (*port) <= 65535) ))
		 {	 
		 printf ("\nPort number (-p) is out of the requested range, [1024..65535]\n");
		 exit (1); /* error */
		 }
		break;
	 case 'c': /* VERBOSE */
		(*verbose) = 1;
		break;
	 
	 case 'v': /* VOLume */ 
		if ( sscanf (++argv[index],"%d", vol) != 1)
		 { 
		 printf ("\n-v must be followed by a number\n");
		 exit (1); /* error */
		 }
 
	
		if ( ! (( (*vol) >= 0) && ( (*vol) <= 100) ))
		 {	 
		 printf ("\nVolume (-v) is out of the requested range, [0..100]\n");
		 exit (1); /* error */
		 }
		break;
	 case 'm': /* address of the second - can be mcast */
		if ( sscanf (++argv[index],"%s", firstMulticastIP) != 1)
		 {
		 printf ("\nSomething should follow -m\n");
		 exit (1); /* error */
		 }
				
		/* checks that this address is multicast. Multicast addresses are in the range 224.0.0.0 through 239.255.255.255 */ 
		if ( sscanf ( firstMulticastIP, "%d.", &mostSignificantAddressComponent) != 1)
		 { 
			printf ("\nThe argument following -m does not seem to be an internet address\n");
			exit (1); /* error */
		 }
		if ( (mostSignificantAddressComponent < 224) | (mostSignificantAddressComponent > 239) )
		 {
		 printf ("\nThe argument following -m is out of the multicast address range\n");
		 exit (1); /* error */
		 }	
		break;
	 case 'k': /* Time accumulated in buffers */
		if ( sscanf (++argv[index],"%d", bufferingTime) != 1)
		 { 
		 printf ("\n-k must be followed by a number\n");
		 exit (1); /* error */
		 }
		
		if ( ! ( ((*bufferingTime) >= 0) ))
		 {	 
		 printf ("\nThe buffering time (-k) must be equal or greater than 0\n");
		 exit (1); /* error */
		 }
		break;
	 default:
	 	printf ("\nI do not understand -%c\n", character); 
		printHelp ();
		exit (1); /* error */
	 }
					
	 }
	 else 
	 { /* argument not starting with '-', reject */
	 	 printf ("Every argument of second must start with '-' \n\n");
	 	 printHelp ();
	 	 exit (1); /* error */
	 }
	
	 	 
	
 
 }
 
};
/*=====================================================================*/
void captureSecond (int argc, char *argv[], char * firstAddress, int * port,
int *vol, int * packetDuration, int *payload, int * verbose, int * bufferingTime)
{
 int maxNameNumber = 1;
 
 int index;
 int nameNumber = 0;
 char character;
 for ( index=2; argc>1; ++index, --argc)
 {
 
 if ( *argv[index] == '-')
	{
	 character= *(++argv[index]);
	 switch (character)
	 { 
	 case 'p': /* PORT */ 
	 if ( sscanf (++argv[index],"%d", port) != 1)
		{ 
		 printf ("\n-p must be followed by a number\n");
		 exit (1); /* error */
		}
	 
	 
	 if ( ! (( (*port) >= 1024) && ( (*port) <= 65535 )))
		{	 
		 printf ("\nPort number is out of the requested range, [1024..65535]\n");
		 exit (1); /* error */
		}
	 break;
	 case 'c': /* VERBOSE */
	 (*verbose) = 1;
	 break;
	 
	 
	 case 'v': /* VOLume */ 
		if ( sscanf (++argv[index],"%d", vol) != 1)
		 { 
		 printf ("\n-v must be followed by a number\n");
		 exit (1); /* error */
		 }
 
	
		if ( ! (( (*vol) >= 0) && ( (*vol) <= 100) ))
		 {	 
		 printf ("\nVolume (-v) is out of the requested range, [0..100]\n");
		 exit (1); /* error */
		 }
		break;
	 
	 case 'l': /* Packet duration */
	 if ( sscanf (++argv[index],"%d", packetDuration) != 1)
		{ 
		 printf ("\n-l must be followed by a number\n");
		 exit (1); /* error */
		}
	 
	 if ( ! ( ((*packetDuration) >= 0) ))
		{	 
		 printf ("\nPacket duration (-l) must be greater than 0\n");
		 exit (1); /* error */
		}
	 break;
	 
	 
	 case 'k': /* Accumulated time in buffers */
		if ( sscanf (++argv[index],"%d", bufferingTime) != 1)
		 { 
		 printf ("\n-k must be followed by a number\n");
		 exit (1); /* error */
		 }
		
		if ( ! ( ((*bufferingTime) >= 0) ))
		 {	 
		 printf ("\nThe buffering time (-k) must be equal or greater than 0\n");
		 exit (1); /* error */
		 }
		break;
 case 'y': /* Initial PAYLOAD */
	 if ( sscanf (++argv[index],"%d", payload) != 1)
		{ 
		 printf ("\n-y must be followed by a number\n");
		 exit (1); /* error */
		}
	 
	 if ( ! ( ((*payload) == PCMU) || ( (*payload) == L16_1) ))
		{	 
		 printf ("\nUnrecognized payload number. Must be either 11 or 100.\n");
		 exit (1); /* error */
		}
	 break;
	 
	 
	 
	 default:
	 printf ("\nI do not understand -%c\n", character); 
	 printHelp ();
	 exit (1); /* error */
	 
	 
	 
	 }
	}
 
 else /* THERE IS A NAME */
 {
 strcpy (firstAddress, argv[index]);
 
	 nameNumber += 1;
	 
	 if (nameNumber > maxNameNumber)
	 {
	 printf ("I expected a single non '-' argument, the IP address, and found more\n\n");
	 printHelp ();
	 exit (1); /* error */
	 }
	
 } 
 }
 
 if (nameNumber != 1)
 {
 printf ("Could not obtain an IP address\n\n");
 printHelp();
 exit (1); /* error */
 }
 
};
	
confArgs.h
/*******************************************************/
/* confArgs.h */
/*******************************************************/
/* Captures arguments for conf application */
/* captures arguments from command line. Initial values of the variables provided are not relevant for its operation */
void captureArguments (	int argc, char *argv[], 
	int *operation, /* Returns equested mode of operation, first or second, using the values defined in conf.h: enum operat {FIRST, SECOND}; */
	char *firstIp, /* For 'second' mode only: returns the requested address of node 'first' (for 'first' mode, it returns an empty string; 'first' should no use this value). Note that this function does not check if the string provided by the user has a valid IP address format (xxx.yyy.zzz.kkk) */ 
	char *firstMulticastIP, /* For 'first' mode only: returns the requested MULTICAST address of node 'first' if -m option is used. It returns an empty string if -m is not used in 'first' mode, or if the code is started in 'second' mode. */
	int *port, /* Both modes: returns the port requested to be used in the communication */ 
	int *vol, /* Both modes: returns the volume requested (for both playing and recording). Value in range [0..100] */
	int *packetDuration, /* Both modes: returns the requested duration of the playout of an UDP packet. Measured in ms */
	int *verbose, /* Both modes: returns if the user wants to show detailed traces (value 1) or not (value 0) */
	int *payload, /* For 'second' mode only: returns the requested payload for the communication. This is the payload to include in RTP packets. Values defined in conf.h: enum payload {PCMU=100, L16_1=11}. Therefore, in command line either number 100 or number 11 are expected. (set to 0 in 'first' mode, must not be used) */
	int *bufferingTime /* Both modes: returns the buffering time requested before starting playout. Time measured in ms. */
	);
/* prints current values - can be used for debugging */
void printValues (int operation, const char * firstIp, const char * firstMulticastIP, int port, int vol, int packetDuration, int verbose, int payload, int bufferingTime );
diffTime.c
/* 'diffTime.c'
To compile, 
gcc -Wall -o diffTime diffTime.c 
Examples of execution
strace -tt -o trace [...] 
cat trace | grep 'write(5' | ./ diffTime
	shows in the screen the time interval between sucessive writing operations to device descriptor #5
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
int main () {
	struct timeval first, second, diff;
	long int hours, minutes;
	char s_first[1000], s_second[1000];
	int result;
	
	// Read the first two lines
	// the format of the data from strace is	 	15:24:26.607645
	// pass hours:minutes... to a 'struct timeval' variable in which seconds, which may be very large (more than 60) 
	result = scanf ("%ld:%ld:%ld.%ld %[^\n]", &hours, &minutes, &(first.tv_sec), &(first.tv_usec), s_first); /* ld to scan long int values written as decimal values */
		
	if (result!= 5) {
		printf ("I expected lines starting with something like '15:24:26.607645 ...'\n"); 
		exit (1); } // it could not read the 5 expected variables 
	first.tv_sec = first.tv_sec + minutes * 60 + hours * 60*60; 
	
	result = scanf ("%ld:%ld:%ld.%ld %[^\n]", &hours, &minutes, &(second.tv_sec), &(second.tv_usec), s_second);
	
	if (result!= 5) {
		printf ("I expected lines starting with something like '15:24:26.607645 ...'\n");
		exit (1); }
	second.tv_sec = second.tv_sec + minutes * 60 + hours * 60*60;
	
	
	while (1) { // the loop stops when an EOF 
		timersub (&second, &first, &diff);
		printf ("%ld.%6ld: %s\n", diff.tv_sec, diff.tv_usec, s_first); /* ld: long integer printed as 'decimal' */
		
		// move data from second to first
		first.tv_sec = second.tv_sec; first.tv_usec = second.tv_usec;
		strcpy (s_first, s_second);
		
		// read new data for second
		 
		result = scanf ("%ld:%ld:%ld.%ld %[^\n]", &hours, &minutes, &(second.tv_sec), &(second.tv_usec), s_second);
		if (result!=5) {
			
			if (result == EOF) {
			exit (0); } // this is assumed normal termination of the code
			else {
				printf ("Unexpected format\n");
				exit (1);
				}
		}
				
		
		second.tv_sec = second.tv_sec + minutes * 60 + hours * 60*60;
	}
	
	return 1; /* everything ended fine */
}	
		
rtp.h
/*
 * rtp.h -- RTP header file 
 */
/* Modified for use in UC3M lab */
#include "types.h" /* changed from <sys/types.h> by Akira 12/27/01 */
#include "sysdep.h"
#if 0 /* types.h has a better definition for this. by Akira 12/27/01 */
/*
 * The type definitions below are valid for 32-bit architectures and
 * may have to be adjusted for 16- or 64-bit architectures.
 */
typedef unsigned char u_int8;
typedef unsigned short u_int16;
typedef unsigned int u_int32;
typedef short
int16;
#endif
/*
 * System endianness -- determined by autoconf.
 */
#ifdef WORDS_BIGENDIAN
#define RTP_BIG_ENDIAN 1
#else
#define RTP_LITTLE_ENDIAN 1
#endif
/*
 * Current protocol version.
 */
#define RTP_VERSION 2
#define RTP_SEQ_MOD (1<<16)
#define RTP_MAX_SDES 255 /* maximum text length for SDES */
typedef enum {
 RTCP_SR = 200,
 RTCP_RR = 201,
 RTCP_SDES = 202,
 RTCP_BYE = 203,
 RTCP_APP = 204
} rtcp_type_t;
typedef enum {
 RTCP_SDES_END = 0,
 RTCP_SDES_CNAME = 1,
 RTCP_SDES_NAME = 2,
 RTCP_SDES_EMAIL = 3,
 RTCP_SDES_PHONE = 4,
 RTCP_SDES_LOC = 5,
 RTCP_SDES_TOOL = 6,
 RTCP_SDES_NOTE = 7,
 RTCP_SDES_PRIV = 8
} rtcp_sdes_type_t;
/* ----------------------------------------------------------------------------------------------------- */
/*
 * RTP data header
 */
typedef struct {
#if RTP_BIG_ENDIAN
 unsigned int version:2; /* protocol version */
 unsigned int p:1; /* padding flag */
 unsigned int x:1; /* header extension flag */
 unsigned int cc:4; /* CSRC count */
 unsigned int m:1; /* marker bit */
 unsigned int pt:7; /* payload type */
#elif RTP_LITTLE_ENDIAN
 unsigned int cc:4; /* CSRC count */
 unsigned int x:1; /* header extension flag */
 unsigned int p:1; /* padding flag */
 unsigned int version:2; /* protocol version */
 unsigned int pt:7; /* payload type */
 unsigned int m:1; /* marker bit */
#else
#error Define one of RTP_LITTLE_ENDIAN or RTP_BIG_ENDIAN
#endif
 unsigned int seq:16; /* sequence number */
 u_int32 ts; /* timestamp */
 u_int32 ssrc; /* synchronization source */
 /* UC3M: in the example of the RFC, here appears a csrc field. Our application setting does not require CSRCs so the best option is to remove them */
} rtp_hdr_t;
/* UC3M : next part is RTCP-specific */
/* ----------------------------------------------------------------------------------------------------- */
/*
 * RTCP common header word
 */
typedef struct {
#if RTP_BIG_ENDIAN
 unsigned int version:2; /* protocol version */
 unsigned int p:1; /* padding flag */
 unsigned int count:5; /* varies by packet type */
#elif RTP_LITTLE_ENDIAN
 unsigned int count:5; /* varies by packet type */
 unsigned int p:1; /* padding flag */
 unsigned int version:2; /* protocol version */
#else
#error Define one of RTP_LITTLE_ENDIAN or RTP_BIG_ENDIAN
#endif
 unsigned int pt:8; /* RTCP packet type */
 unsigned int length:16; /* pkt len in words, w/o this word */
} rtcp_common_t;
/*
 * Big-endian mask for version, padding bit and packet type pair
 * XXX?
 */
#define RTCP_VALID_MASK (0xc000 | 0x2000 | 0xfe)
#define RTCP_VALID_VALUE ((RTP_VERSION << 14) | RTCP_SR)
/*
 * Reception report block
 */
typedef struct {
 u_int32 ssrc; /* data source being reported */
 unsigned int fraction:8; /* fraction lost since last SR/RR */
 int lost:24; /* cumul. no. pkts lost (signed!) */
 u_int32 last_seq; /* extended last seq. no. received */
 u_int32 jitter; /* interarrival jitter */
 u_int32 lsr; /* last SR packet from this source */
 u_int32 dlsr; /* delay since last SR packet */
} rtcp_rr_t;
/*
 * SDES item
 */
typedef struct {
 u_int8 type; /* type of item (rtcp_sdes_type_t) */
 u_int8 length; /* length of item (in octets) */
 char data[1]; /* text, not null-terminated */
} rtcp_sdes_item_t;
/*
 * One RTCP packet
 */
typedef struct {
 rtcp_common_t common; /* common header */
 union {
 /* sender report (SR) */
 struct {
 u_int32 ssrc; /* sender generating this report */
 u_int32 ntp_sec; /* NTP timestamp */
 u_int32 ntp_frac;
 u_int32 rtp_ts; /* RTP timestamp */
 u_int32 psent; /* packets sent */
 u_int32 osent; /* octets sent */ 
 rtcp_rr_t rr[1]; /* variable-length list */
 			/* UC3M: this is a generic definition. Note that in a typical application this is not known in compilation time, but depends on the number of peers you have. Real applications may not be able to use static declarations -such as this- to fill this part of the information.
 			Fortunately, in our specific case we know from the very specification of the application the number of peers we are having: 1.
 			So this definition is fine for you */
 } sr;
 /* reception report (RR) */
 struct {
 u_int32 ssrc; /* receiver generating this report */
 rtcp_rr_t rr[1]; /* variable-length list */
 } rr;
 /* source description (SDES) */
 struct rtcp_sdes {
 u_int32 src; /* first SSRC/CSRC */
 rtcp_sdes_item_t item[1]; /* list of SDES items */
 			/* UC3M: this is a generic definition. This is similar to case stated for the Sender Report. 
 			You should put here the exact number of SDES items you plan to use,... IN THIS CASE YOU WANT TO USE A DIFFERENT NUMBER, SO PLEASE CHANGE THIS VALUE */
 } sdes;
 /* BYE */
 struct {
 u_int32 src[1]; /* list of sources */
 		/* UC3M: similar consideration to the previous SR and SDES case */
 		/* UC3M: we can't express trailing text in this way. If you are using the same message all the time, count the characters, and define a char text[CHAR_NUM+1] field - remember always to finish a string with '\0' */
 } bye;
 } r;
} rtcp_t;
typedef struct rtcp_sdes rtcp_sdes_t;
/*
 * Per-source state information
 */
/* UC3M: this is the structure in which you introduce the information regarding the peer sending RTCP info to you */
#define MAX_LEN_SDES_ITEM 128
typedef struct {
 u_int16 max_seq; /* highest seq. number seen */
 u_int32 cycles; /* shifted count of seq. number cycles */
 u_int32 base_seq; /* base seq number */
 u_int32 bad_seq; /* last 'bad' seq number + 1 */
 u_int32 probation; /* sequ. packets till source is valid */
 u_int32 received; /* packets received */
 u_int32 expected_prior; /* packet expected at last interval */
 u_int32 received_prior; /* packet received at last interval */
 u_int32 transit; /* relative trans time for prev pkt */
 u_int32 jitter; /* estimated jitter */
 /* ... */
 /* UC3M specific definitions */
 char CNAME[MAX_LEN_SDES_ITEM]; /* stores the last CNAME value advertised by the peer. Must be a '\0' terminated string. */
 char TOOL[MAX_LEN_SDES_ITEM]; /* stores the last TOOL value advertised by the peer. Must be a '\0' terminated string. */
} source;
sysdep.h
#ifndef SYSDEP_H
#define SYSDEP_H
#if defined(unix) || defined(__unix) || defined (__unix__)
/* Code for Unix. Any Unix compiler should define one of the above three
 * symbols. */
#ifndef startupSocket
#define startupSocket()
#endif
#ifndef closesocket
#define closesocket close
#endif
#ifndef write_socket
#define write_socket(r, s, l) write(r, s, l)
#endif
/* end of 'if unix' */
#elif defined(WIN32) || defined(__WIN32__)
#include <winsock2.h> /* For NT socket */
#include <ws2tcpip.h> /* IP_ADD_MEMBERSHIP */
#include <windows.h>
#include <time.h> /* time_t */
#include <utilNT.h> /* For function and struct in UNIX but not in NT */
#ifndef EADDRNOTAVAIL
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
#endif
#define NOLONGLONG
#define RTP_LITTLE_ENDIAN 1
#define nextstep
/* Determine if the C(++) compiler requires complete function prototype */
#ifndef __P
#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
#define __P(x) x
#else
#define __P(x) ()
#endif
#endif
#ifdef __BORLANDC__
#include <io.h>
#define strcasecmp stricmp
#define strncasecmp strnicmp
#endif /* __BORLANDC__ */
#ifdef _MSC_VER
#define strcasecmp
_stricmp
#define strncasecmp _strnicmp
#define open _open
#define write _write
#define close _close
#define ftime _ftime
#define timeb _timeb
#endif /* _MSC_VER */
#ifndef SIGBUS
#define SIGBUS SIGINT
#endif
#ifndef SIGHUP
#define SIGHUP SIGINT
#endif
#ifndef SIGPIPE
#define SIGPIPE SIGINT
#endif
typedef int ssize_t;
#if 0
typedef long pid_t;
typedef long gid_t;
typedef long uid_t;
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef unsigned char u_char;
#endif
typedef char * caddr_t; /* core address */
typedef long fd_mask;
#define NBBY 8 /* number of bits in a byte */
#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
#ifndef howmany
#define howmany(x, y) (((x) + ((y) - 1)) / (y))
#endif
struct msghdr {
 caddr_t msg_name; /* optional address */
 int msg_namelen; /* size of address */
 struct iovec *msg_iov; /* scatter/gather array */
 int msg_iovlen; /* # elements in msg_iov */
 caddr_t msg_accrights; /* access rights sent/received */
 int msg_accrightslen;
};
struct passwd {
 char *pw_name;
 char *pw_passwd;
 uid_t pw_uid;
 gid_t pw_gid;
 char *pw_age;
 char *pw_comment;
 char *pw_gecos;
 char *pw_dir;
 char *pw_shell;
};
#if 0
struct ip_mreq {
 struct in_addr imr_multiaddr; /* IP multicast address of group */
 struct in_addr imr_interface; /* local IP address of interface */
};
#endif
#define ITIMER_REAL 0 /* Decrements in real time */
#ifndef _TIMESPEC_T
#define _TIMESPEC_T
typedef struct timespec { /* definition per POSIX.4 */
 time_t tv_sec; /* seconds */
 long tv_nsec; /* and nanoseconds */
} timespec_t;
#endif /* _TIMESPEC_T */
struct itimerval {
 struct timeval it_interval; /* timer interval */
 struct timeval it_value; /* current value */
};
#ifndef ETIME
#define ETIME 1
#endif
#ifndef SIGKILL
#define SIGKILL SIGTERM
#endif
#define fork() 0
#define setsid() {}
#ifndef FILE_SOCKET
#define FILE_SOCKET int
#endif
#ifndef fdopen_socket
#define fdopen_socket(f, g) &f
#endif
#ifndef fclose_socket
#define fclose_socket(f) closesocket(*f)
#endif
extern int winfd_dummy; /* for WinNT see unitNT.c by Akira 12/27/01 */
extern char getc_socket(FILE_SOCKET *f);
extern ssize_t write_socket(int fildes, const void *buf, size_t nbyte);
extern int sendmsg(int s, const struct msghdr *msg, int flags);
/* end of 'ifdef WIN32' */
#else
#error "Not Unix or WIN32 -- what system is this?"
#endif
#if !defined(sun4) && !defined(hp) && !defined(nextstep) && !defined(linux)
#include <sys/select.h> /* select() */
#endif
#endif /* end of ifdef SYSDEP_H */
types.h
#ifndef __types_h
#define __types_h
#include <limits.h>
#include <sys/types.h>
#include "sysdep.h"
#ifndef TRUE
#define TRUE (1)
#define FALSE (0)
#endif
typedef unsigned char boolean;
#ifdef __STDC__
#define MAX32U 0xFFFFFFFFU
#else
#define MAX32U 0xFFFFFFFF
#endif
#define MAX32 0x8FFFFFFF
/* 32 bit machines */
#ifndef RTP_VERSION
#if ULONG_MAX == MAX32U
typedef short int16;
typedef int int32;
typedef unsigned long u_int32;
typedef unsigned short u_int16;
/* 16 bit machines */
#elif ULONG_MAX == 0xFFFF
typedef int int16;
typedef long int32;
typedef unsigned long u_int32;
typedef unsigned int u_int16; 
/* 64 bit machines */
#else
typedef short int16;
typedef int int32;
typedef unsigned int u_int32;
typedef unsigned short u_int16;
#endif
typedef char int8;
typedef unsigned char u_int8;
#endif /* RTP_VERSION */
/* Kludge if we can't get 64-bit integers. */
#ifndef NOLONGLONG
typedef long long int int64;
typedef unsigned long long u_int64;
#else
typedef long int int64;
#endif /* NOLONGLONG */
#endif

Continuar navegando