Socket Layer
|
Data Structures |
struct | OOInterface |
Defines |
#define | OOSOCKET_INVALID ((OOSOCKET)-1) |
#define | OOIPADDR_ANY ((OOIPADDR)0) |
#define | OOIPADDR_LOCAL ((OOIPADDR)0x7f000001UL) |
Typedefs |
typedef int | OOSOCKET |
| Socket's handle.
|
typedef unsigned long | OOIPADDR |
| The IP address represented as unsigned long value.
|
Functions |
EXTERN int | ooSocketAccept (OOSOCKET socket, OOSOCKET *pNewSocket, OOIPADDR *destAddr, int *destPort) |
| This function permits an incoming connection attempt on a socket.
|
EXTERN int | ooSocketAddrToStr (OOIPADDR ipAddr, char *pbuf, int bufsize) |
| This function converts an IP address to its string representation.
|
EXTERN int | ooSocketBind (OOSOCKET socket, OOIPADDR addr, int port) |
| This function associates a local address with a socket.
|
EXTERN int | ooSocketClose (OOSOCKET socket) |
| This function closes an existing socket.
|
EXTERN int | ooSocketConnect (OOSOCKET socket, const char *host, int port) |
| This function establishes a connection to a specified socket.
|
EXTERN int | ooSocketCreate (OOSOCKET *psocket) |
| This function creates a socket.
|
EXTERN int | ooSocketCreateUDP (OOSOCKET *psocket) |
| This function creates a UDP datagram socket.
|
EXTERN int | ooSocketsInit (void) |
| This function initiates use of sockets by an application.
|
EXTERN int | ooSocketsCleanup (void) |
| This function terminates use of sockets by an application.
|
EXTERN int | ooSocketListen (OOSOCKET socket, int maxConnection) |
| This function places a socket a state where it is listening for an incoming connection.
|
EXTERN int | ooSocketRecvPeek (OOSOCKET socket, ASN1OCTET *pbuf, ASN1UINT bufsize) |
| This function is used to peek at the received data without actually removing it from the receive socket buffer.
|
EXTERN int | ooSocketRecv (OOSOCKET socket, ASN1OCTET *pbuf, ASN1UINT bufsize) |
| This function receives data from a connected socket.
|
EXTERN int | ooSocketRecvFrom (OOSOCKET socket, ASN1OCTET *pbuf, ASN1UINT bufsize, char *remotehost, ASN1UINT hostBufLen, int *remoteport) |
| This function receives data from a connected/unconnected socket.
|
EXTERN int | ooSocketSend (OOSOCKET socket, const ASN1OCTET *pdata, ASN1UINT size) |
| This function sends data on a connected socket.
|
EXTERN int | ooSocketSendTo (OOSOCKET socket, const ASN1OCTET *pdata, ASN1UINT size, const char *remotehost, int remoteport) |
| This function sends data on a connected or unconnected socket.
|
EXTERN int | ooSocketSelect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) |
| This function is used for synchronous monitoring of multiple sockets.
|
EXTERN int | ooSocketStrToAddr (const char *pIPAddrStr, OOIPADDR *pIPAddr) |
| This function converts the string with IP address to a double word representation.
|
EXTERN int | ooSocketConvertIpToNwAddr (const char *inetIp, ASN1OCTET *netIp, size_t bufsiz) |
| This function converts an internet dotted ip address to network address.
|
EXTERN int | ooGetLocalIPAddress (char *pIPAddrs) |
| This function retrives the IP address of the local host.
|
EXTERN int | ooSocketGetSockName (OOSOCKET socket, struct sockaddr_in *name, socklen_t *size) |
EXTERN long | ooSocketHTONL (long val) |
EXTERN short | ooSocketHTONS (short val) |
EXTERN int | ooSocketGetIpAndPort (OOSOCKET socket, char *ip, int len, int *port) |
| This function is used to retrieve the ip and port number used by the socket passed as parameter.
|
EXTERN int | ooSocketGetInterfaceList (OOCTXT *pctxt, OOInterface **ifList) |
Typedef Documentation
The IP address represented as unsigned long value.
The most significant 8 bits in this unsigned long value represent the first number of the IP address. The least significant 8 bits represent the last number of the IP address.
Definition at line 82 of file ooSocket.h.
Function Documentation
This function permits an incoming connection attempt on a socket.
It extracts the first connection on the queue of pending connections on socket. It then creates a new socket and returns a handle to the new socket. The newly created socket is the socket that will handle the actual connection and has the same properties as original socket. See description of 'accept' socket function for further details.
- Parameters:
-
| socket | The socket's handle created by call to rtSocketCreate function. |
| pNewSocket | The pointer to variable to receive the new socket's handle. |
| destAddr | Optional pointer to a buffer that receives the IP address of the connecting entity. It may be NULL. |
| destPort | Optional pointer to a buffer that receives the port of the connecting entity. It may be NULL. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketAddrToStr |
( |
OOIPADDR |
ipAddr, |
|
|
char * |
pbuf, |
|
|
int |
bufsize | |
|
) |
| | |
This function converts an IP address to its string representation.
- Parameters:
-
| ipAddr | The IP address to be converted. |
| pbuf | Pointer to the buffer to receive a string with the IP address. |
| bufsize | Size of the buffer. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
This function associates a local address with a socket.
It is used on an unconnected socket before subsequent calls to the rtSocketConnect or rtSocketListen functions. See description of 'bind' socket function for further details.
- Parameters:
-
| socket | The socket's handle created by call to rtSocketCreate function. |
| addr | The local IP address to assign to the socket. |
| port | The local port number to assign to the socket. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketClose |
( |
OOSOCKET |
socket |
) |
|
This function closes an existing socket.
- Parameters:
-
| socket | The socket's handle created by call to rtSocketCreate or rtSocketAccept function. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketConnect |
( |
OOSOCKET |
socket, |
|
|
const char * |
host, |
|
|
int |
port | |
|
) |
| | |
This function establishes a connection to a specified socket.
It is used to create a connection to the specified destination. When the socket call completes successfully, the socket is ready to send and receive data. See description of 'connect' socket function for further details.
- Parameters:
-
| socket | The socket's handle created by call to rtSocketCreate function. |
| host | The null-terminated string with the IP address in the following format: "NNN.NNN.NNN.NNN", where NNN is a number in the range (0..255). |
| port | The destination port to connect. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketCreate |
( |
OOSOCKET * |
psocket |
) |
|
This function creates a socket.
The only streaming TCP/IP sockets are supported at the moment.
- Parameters:
-
| psocket | The pointer to the socket's handle variable to receive the handle of new socket. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketCreateUDP |
( |
OOSOCKET * |
psocket |
) |
|
This function creates a UDP datagram socket.
- Parameters:
-
| psocket | The pointer to the socket's handle variable to receive the handle of new socket. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketsInit |
( |
void |
|
) |
|
This function initiates use of sockets by an application.
This function must be called first before use sockets.
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketsCleanup |
( |
void |
|
) |
|
This function terminates use of sockets by an application.
This function must be called after done with sockets.
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketListen |
( |
OOSOCKET |
socket, |
|
|
int |
maxConnection | |
|
) |
| | |
This function places a socket a state where it is listening for an incoming connection.
To accept connections, a socket is first created with the rtSocketCreate function and bound to a local address with the rtSocketBind function, a maxConnection for incoming connections is specified with rtSocketListen, and then the connections are accepted with the rtSocketAccept function. See description of 'listen' socket function for further details.
- Parameters:
-
| socket | The socket's handle created by call to rtSocketCreate function. |
| maxConnection | Maximum length of the queue of pending connections. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
This function is used to peek at the received data without actually removing it from the receive socket buffer.
A receive call after this will get the same data from the socket. - Parameters:
-
| socket | The socket's handle created by call to rtSocketCreate or rtSocketAccept function. |
| pbuf | Pointer to the buffer for the incoming data. |
| bufsize | Length of the buffer. |
- Returns:
- If no error occurs, returns the number of bytes received. Otherwise, the negative value is error code.
This function receives data from a connected socket.
It is used to read incoming data on sockets. The socket must be connected before calling this function. See description of 'recv' socket function for further details.
- Parameters:
-
| socket | The socket's handle created by call to rtSocketCreate or rtSocketAccept function. |
| pbuf | Pointer to the buffer for the incoming data. |
| bufsize | Length of the buffer. |
- Returns:
- If no error occurs, returns the number of bytes received. Otherwise, the negative value is error code.
This function receives data from a connected/unconnected socket.
It is used to read incoming data on sockets. It populates the remotehost and remoteport parameters with information of remote host. See description of 'recvfrom' socket function for further details.
- Parameters:
-
| socket | The socket's handle created by call to ooSocketCreate |
| pbuf | Pointer to the buffer for the incoming data. |
| bufsize | Length of the buffer. |
| remotehost | Pointer to a buffer in which remote ip address will be returned. |
| hostBufLen | Length of the buffer passed for remote ip address. |
| remoteport | Pointer to an int in which remote port number will be returned. |
- Returns:
- If no error occurs, returns the number of bytes received. Otherwise, negative value.
This function sends data on a connected socket.
It is used to write outgoing data on a connected socket. See description of 'send' socket function for further details.
- Parameters:
-
| socket | The socket's handle created by call to rtSocketCreate or rtSocketAccept function. |
| pdata | Buffer containing the data to be transmitted. |
| size | Length of the data in pdata. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketSendTo |
( |
OOSOCKET |
socket, |
|
|
const ASN1OCTET * |
pdata, |
|
|
ASN1UINT |
size, |
|
|
const char * |
remotehost, |
|
|
int |
remoteport | |
|
) |
| | |
This function sends data on a connected or unconnected socket.
See description of 'sendto' socket function for further details.
- Parameters:
-
| socket | The socket's handle created by call to rtSocketCreate or rtSocketAccept function. |
| pdata | Buffer containing the data to be transmitted. |
| size | Length of the data in pdata. |
| remotehost | Remote host ip address to which data has to be sent. |
| remoteport | Remote port ip address to which data has to be sent. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketSelect |
( |
int |
nfds, |
|
|
fd_set * |
readfds, |
|
|
fd_set * |
writefds, |
|
|
fd_set * |
exceptfds, |
|
|
struct timeval * |
timeout | |
|
) |
| | |
This function is used for synchronous monitoring of multiple sockets.
For more information refer to documnetation of "select" system call.
- Parameters:
-
| nfds | The highest numbered descriptor to be monitored plus one. |
| readfds | The descriptors listed in readfds will be watched for whether read would block on them. |
| writefds | The descriptors listed in writefds will be watched for whether write would block on them. |
| exceptfds | The descriptors listed in exceptfds will be watched for exceptions. |
| timeout | Upper bound on amout of time elapsed before select returns. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketStrToAddr |
( |
const char * |
pIPAddrStr, |
|
|
OOIPADDR * |
pIPAddr | |
|
) |
| | |
This function converts the string with IP address to a double word representation.
The converted address may be used with the rtSocketBind function.
- Parameters:
-
| pIPAddrStr | The null-terminated string with the IP address in the following format: "NNN.NNN.NNN.NNN", where NNN is a number in the range (0..255). |
| pIPAddr | Pointer to the converted IP address. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketConvertIpToNwAddr |
( |
const char * |
inetIp, |
|
|
ASN1OCTET * |
netIp, |
|
|
size_t |
bufsiz | |
|
) |
| | |
This function converts an internet dotted ip address to network address.
- Parameters:
-
| inetIp | The null-terminated string with the IP address in the following format: "NNN.NNN.NNN.NNN", where NNN is a number in the range (0..255). |
| netIp | Buffer in which the converted address will be returned. |
| bufsiz | Size of buffer to receive converted address. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooGetLocalIPAddress |
( |
char * |
pIPAddrs |
) |
|
This function retrives the IP address of the local host.
- Parameters:
-
| pIPAddrs | Pointer to a char buffer in which local IP address will be returned. |
- Returns:
- Completion status of operation: 0 (ASN_OK) = success, negative return value is error.
EXTERN int ooSocketGetIpAndPort |
( |
OOSOCKET |
socket, |
|
|
char * |
ip, |
|
|
int |
len, |
|
|
int * |
port | |
|
) |
| | |
This function is used to retrieve the ip and port number used by the socket passed as parameter.
It internally uses getsockname system call for this purpose. - Parameters:
-
| socket | Socket for which ip and port has to be determined. |
| ip | Buffer in which ip address will be returned. |
| len | Length of the ip address buffer. |
| port | Pointer to integer in which port number will be returned. |
- Returns:
- ASN_OK, on success; -ve on failed.
|