2004-05-29 00:16:39 +00:00
|
|
|
#ifndef OSKITTCP_H
|
|
|
|
#define OSKITTCP_H
|
|
|
|
|
2004-11-07 20:37:21 +00:00
|
|
|
#ifdef linux
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
2004-05-29 00:16:39 +00:00
|
|
|
#ifdef KERNEL
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
#include <netinet/ip_var.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/tcp_fsm.h>
|
|
|
|
#include <netinet/tcp_seq.h>
|
|
|
|
#include <netinet/tcp_timer.h>
|
|
|
|
#include <netinet/tcp_var.h>
|
|
|
|
#include <netinet/tcpip.h>
|
|
|
|
|
|
|
|
struct connect_args {
|
|
|
|
int s;
|
|
|
|
caddr_t name;
|
|
|
|
int namelen;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <oskittypes.h>
|
|
|
|
|
|
|
|
#define IPHDR_SIZE 20
|
2004-06-09 18:11:39 +00:00
|
|
|
#define SEL_CONNECT 1
|
|
|
|
#define SEL_FIN 2
|
|
|
|
#define SEL_RST 4
|
|
|
|
#define SEL_ABRT 8
|
|
|
|
#define SEL_READ 16
|
|
|
|
#define SEL_WRITE 32
|
|
|
|
#define SEL_ACCEPT 64
|
|
|
|
#define SEL_OOB 128
|
|
|
|
#define SEL_ERROR 256
|
|
|
|
#define SEL_FINOUT 512
|
2004-05-29 00:16:39 +00:00
|
|
|
|
2004-07-08 06:39:30 +00:00
|
|
|
typedef int (*OSKITTCP_SOCKET_STATE)
|
2004-05-29 00:16:39 +00:00
|
|
|
( void *ClientData,
|
|
|
|
void *WhichSocket,
|
|
|
|
void *WhichConnection,
|
2004-07-08 06:39:30 +00:00
|
|
|
OSK_UINT NewState );
|
|
|
|
|
2004-05-29 00:16:39 +00:00
|
|
|
typedef int (*OSKITTCP_SEND_PACKET)
|
|
|
|
( void *ClientData,
|
|
|
|
OSK_PCHAR Data,
|
|
|
|
OSK_UINT Len );
|
|
|
|
|
2004-08-19 21:39:00 +00:00
|
|
|
typedef struct ifaddr *(*OSKITTCP_FIND_INTERFACE)
|
|
|
|
( void *ClientData,
|
|
|
|
OSK_UINT AddrType,
|
|
|
|
OSK_UINT FindType,
|
|
|
|
struct sockaddr *ReqAddr );
|
|
|
|
|
2004-08-29 20:04:42 +00:00
|
|
|
typedef void *(*OSKITTCP_MALLOC)
|
|
|
|
( void *ClientData,
|
|
|
|
OSK_UINT Bytes,
|
|
|
|
OSK_PCHAR File,
|
|
|
|
OSK_UINT Line );
|
|
|
|
|
|
|
|
typedef void (*OSKITTCP_FREE)
|
|
|
|
( void *ClientData,
|
|
|
|
void *data,
|
|
|
|
OSK_PCHAR File,
|
|
|
|
OSK_UINT Line );
|
|
|
|
|
|
|
|
typedef int (*OSKITTCP_SLEEP)
|
|
|
|
( void *ClientData, void *token, int priority, char *msg, int tmio );
|
|
|
|
|
|
|
|
typedef void (*OSKITTCP_WAKEUP)( void *ClientData, void *token );
|
|
|
|
|
2004-05-29 00:16:39 +00:00
|
|
|
typedef struct _OSKITTCP_EVENT_HANDLERS {
|
|
|
|
void *ClientData;
|
2004-06-09 18:11:39 +00:00
|
|
|
OSKITTCP_SOCKET_STATE SocketState;
|
2004-05-29 00:16:39 +00:00
|
|
|
OSKITTCP_SEND_PACKET PacketSend;
|
2004-08-19 21:39:00 +00:00
|
|
|
OSKITTCP_FIND_INTERFACE FindInterface;
|
2004-08-29 20:04:42 +00:00
|
|
|
OSKITTCP_MALLOC TCPMalloc;
|
|
|
|
OSKITTCP_FREE TCPFree;
|
|
|
|
OSKITTCP_SLEEP Sleep;
|
|
|
|
OSKITTCP_WAKEUP Wakeup;
|
2004-05-29 00:16:39 +00:00
|
|
|
} OSKITTCP_EVENT_HANDLERS, *POSKITTCP_EVENT_HANDLERS;
|
|
|
|
|
|
|
|
extern OSKITTCP_EVENT_HANDLERS OtcpEvent;
|
|
|
|
|
|
|
|
extern void InitOskitTCP();
|
|
|
|
extern void DeinitOskitTCP();
|
2005-12-23 20:46:48 +00:00
|
|
|
extern void TimerOskitTCP( int FastTimer, int SlowTimer );
|
2004-08-19 21:39:00 +00:00
|
|
|
extern void OskitDumpBuffer( OSK_PCHAR Data, OSK_UINT Len );
|
2004-12-04 23:29:56 +00:00
|
|
|
extern int OskitTCPShutdown( void *socket, int disconn_type );
|
2004-05-29 00:16:39 +00:00
|
|
|
extern int OskitTCPSocket( void *Connection, void **ConnectionContext,
|
|
|
|
int Af, int Type, int Proto );
|
|
|
|
extern void RegisterOskitTCPEventHandlers
|
|
|
|
( POSKITTCP_EVENT_HANDLERS EventHandlers );
|
|
|
|
extern void OskitTCPReceiveDatagram( OSK_PCHAR Data, OSK_UINT Len,
|
|
|
|
OSK_UINT IpHeaderLen );
|
2005-05-08 02:16:32 +00:00
|
|
|
extern int OskitTCPReceive( void *socket,
|
2004-06-09 18:11:39 +00:00
|
|
|
void *Addr,
|
|
|
|
OSK_PCHAR Data,
|
|
|
|
OSK_UINT Len,
|
|
|
|
OSK_UINT *OutLen,
|
|
|
|
OSK_UINT Flags );
|
2005-05-08 02:16:32 +00:00
|
|
|
extern int OskitTCPSend( void *socket,
|
2004-07-08 06:39:30 +00:00
|
|
|
OSK_PCHAR Data,
|
|
|
|
OSK_UINT Len,
|
|
|
|
OSK_UINT *OutLen,
|
|
|
|
OSK_UINT Flags );
|
2004-08-19 21:39:00 +00:00
|
|
|
|
2009-11-14 18:38:02 +00:00
|
|
|
extern int OskitTCPConnect( void *socket,
|
2004-08-19 21:39:00 +00:00
|
|
|
void *nam, OSK_UINT namelen );
|
|
|
|
extern int OskitTCPClose( void *socket );
|
|
|
|
|
2009-10-31 01:05:31 +00:00
|
|
|
extern int OskitTCPBind( void *socket,
|
2004-08-19 21:39:00 +00:00
|
|
|
void *nam, OSK_UINT namelen );
|
|
|
|
|
2004-12-25 21:30:20 +00:00
|
|
|
extern int OskitTCPAccept( void *socket, void **new_socket,
|
2009-11-14 18:38:02 +00:00
|
|
|
void *context, void *addr_out,
|
2004-12-25 21:30:20 +00:00
|
|
|
OSK_UINT addr_len,
|
|
|
|
OSK_UINT *out_addr_len,
|
|
|
|
OSK_UINT finish_accept );
|
|
|
|
|
2004-08-19 21:39:00 +00:00
|
|
|
extern int OskitTCPListen( void *socket, int backlog );
|
|
|
|
|
|
|
|
extern int OskitTCPRecv( void *connection,
|
|
|
|
OSK_PCHAR Data,
|
|
|
|
OSK_UINT Len,
|
|
|
|
OSK_UINT *OutLen,
|
|
|
|
OSK_UINT Flags );
|
|
|
|
|
2009-10-31 01:05:31 +00:00
|
|
|
int OskitTCPGetAddress( void *socket,
|
2004-08-19 21:39:00 +00:00
|
|
|
OSK_UINT *LocalAddress,
|
|
|
|
OSK_UI16 *LocalPort,
|
|
|
|
OSK_UINT *RemoteAddress,
|
|
|
|
OSK_UI16 *RemotePort );
|
|
|
|
|
2009-10-31 00:24:38 +00:00
|
|
|
int OskitTCPGetSockOpt(void *socket,
|
|
|
|
int level,
|
|
|
|
int optname,
|
|
|
|
char *buffer,
|
|
|
|
int *size);
|
|
|
|
|
|
|
|
int OskitTCPSetSockOpt(void *socket,
|
|
|
|
int level,
|
|
|
|
int optname,
|
|
|
|
char *buffer,
|
|
|
|
int size);
|
|
|
|
|
2009-10-31 18:15:23 +00:00
|
|
|
int OskitTCPDisconnect(void *socket);
|
|
|
|
|
2009-11-16 07:39:52 +00:00
|
|
|
int OskitTCPGetSocketError(void *socket);
|
|
|
|
|
2004-05-29 00:16:39 +00:00
|
|
|
#undef errno
|
|
|
|
|
2006-01-01 11:48:11 +00:00
|
|
|
void *fbsd_malloc( unsigned int bytes, char *file, unsigned line, ... );
|
|
|
|
void fbsd_free( void *data, char *file, unsigned line, ... );
|
2004-09-23 03:02:29 +00:00
|
|
|
#if 0
|
|
|
|
#define malloc(x) fbsd_malloc(x,__FILE__,__LINE__)
|
|
|
|
#define free(x) fbsd_free(x,__FILE__,__LINE__)
|
|
|
|
#endif
|
|
|
|
#define kern_malloc(x,y,z) kern_malloc_needs_definition(x,y,z)
|
|
|
|
#define kern_free(x,y,z) kern_free_needs_definition(x,w,z)
|
2004-05-29 00:16:39 +00:00
|
|
|
|
|
|
|
/* Error codes */
|
|
|
|
#include <oskiterrno.h>
|
|
|
|
|
|
|
|
#define SOCK_MAXADDRLEN 255
|
|
|
|
|
2004-06-09 18:11:39 +00:00
|
|
|
#define OSK_MSG_OOB 0x01
|
|
|
|
#define OSK_MSG_PEEK 0x02
|
|
|
|
#define OSK_MSG_DONTWAIT 0x80
|
|
|
|
|
2009-10-31 18:15:23 +00:00
|
|
|
#define FREAD 0x0001
|
|
|
|
#define FWRITE 0x0002
|
|
|
|
|
2009-11-14 18:38:02 +00:00
|
|
|
/* Don't define this unless your are insane or aicom */
|
|
|
|
//#define LOCK_SPAM
|
|
|
|
|
|
|
|
#ifdef LOCK_SPAM
|
|
|
|
#define OSKLock() if (!KeTryToAcquireSpinLockAtDpcLevel(&OSKLock)) \
|
|
|
|
{ \
|
|
|
|
DbgPrint("OSKLock WAIT (%s)\n", __FUNCTION__); \
|
|
|
|
KeAcquireSpinLockAtDpcLevel(&OSKLock); \
|
|
|
|
} \
|
|
|
|
DbgPrint("OSKLock >>>> (%s)\n", __FUNCTION__)
|
|
|
|
|
|
|
|
#define OSKUnlock() KeReleaseSpinLockFromDpcLevel(&OSKLock); \
|
|
|
|
DbgPrint("OSKLock <<<< (%s)\n", __FUNCTION__)
|
|
|
|
#else
|
|
|
|
#define OSKLock() KeAcquireSpinLockAtDpcLevel(&OSKLock)
|
|
|
|
#define OSKUnlock() KeReleaseSpinLockFromDpcLevel(&OSKLock)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define OSKLockAndRaise(x) KeRaiseIrql(DISPATCH_LEVEL, x); \
|
|
|
|
OSKLock()
|
|
|
|
#define OSKUnlockAndLower(x) OSKUnlock(); \
|
|
|
|
KeLowerIrql(x)
|
|
|
|
|
2004-05-29 00:16:39 +00:00
|
|
|
#endif/*OSKITTCP_H*/
|