Functions | |||
![]() | ![]() | void | initErrorCodes () |
![]() | ![]() | int | openSocket (int type) |
![]() | ![]() | This function creates a socket of type TCP or UDP. More... | |
![]() | ![]() | bool | closeSocket (int sockDescr) |
![]() | ![]() | This functions closes the socket given by the socket descriptor. More... | |
![]() | ![]() | bool | bind (int sockDescr, unsigned int localPort) |
![]() | ![]() | Bind a name to a socket. More... | |
![]() | ![]() | bool | connect (int sockDescr, char* IPAddress, unsigned int remotePort) |
![]() | ![]() | Establish a connection to a given IP address on a given port over the socket given by the socket descriptor. More... | |
![]() | ![]() | int | TCPSend (int sockDescr, byte* dataBuffer, int length, int flags) |
![]() | ![]() | Sends a TCP message to anothertransport end-point. More... | |
![]() | ![]() | int | TCPReceive (int sockDescr, byte* dataBuffer, int length, int flags, unsigned long timeout) |
![]() | ![]() | Receive message from another socket. More... | |
![]() | ![]() | bool | TCPAbortConnection (int sockDescr) |
![]() | ![]() | Abort a connection on a socket. More... | |
![]() | ![]() | bool | TCPCloseLinger (int sockDescr, unsigned int seconds) |
![]() | ![]() | Sets linger time on close in seconds. More... | |
![]() | ![]() | bool | TCPSocketReuse (int sockDescr) |
![]() | ![]() | Sets reuse option on a listening socket. More... | |
![]() | ![]() | int | UDPSend (int sockDescr, char* IPAddress, unsigned int remotePort, byte* dataBuffer, int length, int flags, bool convertPort) |
![]() | ![]() | Sends UDP datagrams. More... | |
![]() | ![]() | int | UDPReceive (int sockDescr, byte* dataBuffer, int length, int flags, unsigned long timeout) |
![]() | ![]() | Receives UDP datagrams. More... | |
![]() | ![]() | bool | listen (int sockDescr, int connections) |
![]() | ![]() | Place the socket in passive mode and set the number of incomimg TCP connections the system will enque. More... | |
![]() | ![]() | int | accept (int sockDescr) |
![]() | ![]() | Accept the next incoming connection from the queue of pending connections from the listen function and creates a new socket. More... | |
![]() | ![]() | int | waitingBytes (int sockDescr) |
![]() | ![]() | Get the number of bytes on a socket, waiting for read. More... | |
![]() | ![]() | clientInfoPtr | getClientInfo () |
![]() | ![]() | You'll get a pointer to clientInfo struct which contains information about the connection to the client the server is connected. More... | |
![]() | ![]() | errorInfoPtr | getErrorInfo () |
![]() | ![]() | This function returns a pointer to the struct errorInfo. More... | |
![]() | ![]() | int | getErrorCode () |
![]() | ![]() | This function returns the error code of the last API call. More... | |
![]() | ![]() | void | inet2ascii (unsigned long far* IP, char far* IPAddress) |
![]() | ![]() | Converts an unsigned long IP address to a dotted decimal IP string The buffer must have the length of 17 Bytes. More... | |
![]() | ![]() | bool | ascii2inet (char far* IPAddress, unsigned long far* IP) |
![]() | ![]() | Converts an dotted decimal IP-String to an unsigned long. More... | |
![]() | ![]() | void | sleep (unsigned int mseconds) |
![]() | ![]() | Sleeps for mseconds milliseconds. More... | |
![]() | ![]() | bool | evalError (union REGS* outregs) |
![]() | ![]() | Evaluate errors. More... | |
Variables | |||
![]() | ![]() | struct errorInfo | errInf |
![]() | ![]() | errorInfoPtr | errInfp |
![]() | ![]() | struct clientInfo | cInf |
![]() | ![]() | clientInfoPtr | cInfp |
![]() | ![]() | char | IPAddr [17] |
![]() | ![]() | char* | errorCodes [266] |
![]() | ![]() | char* | specialCode |
![]() | ![]() | int | errorCodesInit |
@author: Christian Decker (cdecker@teco.edu)
Development System: Turbo C++ 3.0
Licence: GPL
This API was developed for easy handling the TCPIP/UDP functions of the SC12 from Beck GmbH. The code was inspired from snippets which I found in the examples delivered with the original API descriptions from Beck.
This API contains functions for opening, closing sockets, binding them, connection, sending and receiving data through them, listen on particular ports and some converting routines for IP-Adressen to network byte order. These functions not only for TCP sockets, they are for UDP sockets, too.
Definition in file netapi.c.
void initErrorCodes () [static]
|
| int openSocket (int type) |
This function creates a socket of type TCP or UDP.
It returns the socket descriptor.
| type | is one of TCP or UDP |
| bool closeSocket (int sockDescr) |
This functions closes the socket given by the socket descriptor.
| sockDescr | the socket descriptor |
| bool bind (int sockDescr, unsigned int localPort) |
Bind a name to a socket.
This functions uses the local address. You can specify the local port the socket is bind to.
| sockDescr | a socket descriptor |
| localPort | the local port the socket is bind to |
| bool connect (int sockDescr, char * IPAddress, unsigned int remotePort) |
Establish a connection to a given IP address on a given port over the socket given by the socket descriptor.
@sockDescr a socket descriptor @IPAddress a char pointer to a IP address to connect to @remotePort the port on the remote computer to connect to
| int TCPSend (int sockDescr, byte * dataBuffer, int length, int flags) |
Sends a TCP message to anothertransport end-point.
Can only be used if the socket is in a connected state.
| sockDescr | a socket descriptor |
| dataBuffer | a pointer to an array of bytes which should be sent |
| length | number of bytes to send |
| flags | is one of MSG_BLOCKING, MSG_DONTWAIT |
| int TCPReceive (int sockDescr, byte * dataBuffer, int length, int flags, unsigned long timeout) |
Receive message from another socket.
Can only be used if the socket is in a connected state.
| sockDescr | a socket descriptor |
| dataBuffer | a pointer to an array of bytes where received bytes are saved |
| length | number of bytes to receive |
| flags | is one of MSG_BLOCKING, MSG_TIMEOUT, MSG_DONTWAIT |
| timeout | timeout in milliseconds - only usedif flags = MSG_TIMEOUT |
| bool TCPAbortConnection (int sockDescr) |
Abort a connection on a socket.
Works only with TCP sockets.
| sockDescr | a socket descriptor |
| bool TCPCloseLinger (int sockDescr, unsigned int seconds) |
Sets linger time on close in seconds.
Works only with TCP sockets.
| sockDescr | a socket descriptor |
| seconds | linger time in seconds (0 means linger off) |
| bool TCPSocketReuse (int sockDescr) |
Sets reuse option on a listening socket.
This is necessary, if a listening socket was closed and will be open and bind on the same port as it was bind before. Works only with TCP sockets.
| sockDescr | a socket descriptor |
| int UDPSend (int sockDescr, char * IPAddress, unsigned int remotePort, byte * dataBuffer, int length, int flags, bool convertPort) |
Sends UDP datagrams.
It only works with an UDP socket.
| sockDescr | a socket descriptor |
| IPAddress | a char pointer to the dotted IP address |
| remotePort | the port the UPD msg will be sent to |
| dataBuffer | a pointer to an array of bytes where the sending bytes are |
| length | number of bytes to send |
| flags | is one of MSG_BLOCKING, MSG_DONTWAIT |
| convertPort | greater 0 if UDPSend should convert remotePort into network byte order, 0 means it doesn't convert |
| int UDPReceive (int sockDescr, byte * dataBuffer, int length, int flags, unsigned long timeout) |
Receives UDP datagrams.
It only works with an UDP socket. It sets up the information about the client (ip and port in network byte order)
| sockDescr | a socket descriptor |
| dataBuffer | a pointer to an array of bytes where received bytes are written |
| length | number of bytes to receive |
| flags | is one of MSG_BLOCKING, MSG_TIMEOUT, MSG_DONTWAIT |
| timeout | timeout in milliseconds - only used if flags = MSG_TIMEOUT |
| bool listen (int sockDescr, int connections) |
Place the socket in passive mode and set the number of incomimg TCP connections the system will enque.
This call is used by a TCP server.
| sockDescr | a socket descriptor @connections the max. number (limited to 5) of allowed outstanding connections |
| int accept (int sockDescr) |
Accept the next incoming connection from the queue of pending connections from the listen function and creates a new socket.
It sets up the information about the client (ip and port in network byte order)
| sockDescr | a socket descriptor from listen function |
| int waitingBytes (int sockDescr) |
Get the number of bytes on a socket, waiting for read.
| sockDescr | a socket descriptor |
| clientInfoPtr getClientInfo () |
You'll get a pointer to clientInfo struct which contains information about the connection to the client the server is connected.
The port in this structure is in network byte order.
| errorInfoPtr getErrorInfo () |
This function returns a pointer to the struct errorInfo.
You can use this pointer to ask for the error code of the last API call and for the appropriate description to this code.
| int getErrorCode () |
This function returns the error code of the last API call.
It uses getErrorInfo and is for simplifying the error handling.
| void inet2ascii (unsigned long far * IP, char far * IPAddress) |
Converts an unsigned long IP address to a dotted decimal IP string The buffer must have the length of 17 Bytes.
| IP | a far pointer to the unsigned long IP |
| IPAddress | a far char pointer to the buffer where the IP string is saved (must be 17 chars) |
| bool ascii2inet (char far * IPAddress, unsigned long far * IP) |
Converts an dotted decimal IP-String to an unsigned long.
| IPAddress | a far pointer to a dotted decimal IP-String |
| IP | a far pointer to the IP in network byte order |
| void sleep (unsigned int mseconds) |
Sleeps for mseconds milliseconds.
| mseconds | time to sleep in milliseconds |
| bool evalError (union REGS * outregs) |
Evaluate errors.
This is used by all API calls for evaluation of the errors. It writes into struct errorInfo the error code and an error description.
| a | pointer to the register after the API call |
struct errorInfo errInf [static]
|
| errorInfoPtr errInfp |
struct clientInfo cInf [static]
|
| clientInfoPtr cInfp |
char IPAddr[17] [static]
|
char* errorCodes[266] [static]
|
char* specialCode [static]
|
int errorCodesInit [static]
|
1.0.0 written by Dimitri van Heesch,
© 1997-1999