Main Page | Compound List | File List | Compound Members | File Members | Related Pages

sockets.c File Reference

Implements the socket object. More...

#include "config.h"
#include "liblogging.h"
#include "sockets.h"
#include "assert.h"
#include "socketsUnix.c"

Functions

srRetVal sbSockConstruct (sbSockObj **pThis)
 Construct a socket object (just in-memory representation, no socket calls).

int sbSockGetLastSockError (sbSockObj *pThis)
 get last error code

int sbSockPeekRcvChar (sbSockObj *pThis)
 Peek at the next character from the stream.

int sbSockGetRcvChar (sbSockObj *pThis)
 Read the next character from the stream.

srRetVal sbSockExit (struct sbSockObject *pThis)
int sbSockHasReceiveData (struct sbSockObject *pThis)
srRetVal sbSockWaitReceiveData (struct sbSockObject *pThis)
 Wait until the socket has some receive data.

sbSockObjsbSockInitListenSock (srRetVal *iRet, int iType, char *szBindToAddress, unsigned uBindToPort)
 Initialize a listen socket.

srRetVal sbSockAcceptConnection (sbSockObj *pThis, sbSockObj **pNew)
 This method accepts an incoming connection and creates a new socket object out of it.

srRetVal sbSockGetRemoteHostIP (sbSockObj *pThis, char **ppszHost)
 Return the IP Address of the remote host as a string.

srRetVal sbSockGetIPusedForSending (sbSockObj *pThis, char **ppsz)
 Provide the (local) IP address this session is sending to the remote peer on as a string.

srRetVal sbSockRecvFrom (sbSockObj *pThis, char *pRecvBuf, int *piBufLen, char **ppFrom)
 Enhanced recvfrom() clone.


Detailed Description

Implements the socket object.

This file implements the socket layer. It contains all those methods that are upper layer. It also includes lower layer files which do the actual OS-dependant socket API handling. Thanks to Devin Kowatch, there is now a UNIX as well as a Win32 lower layer available.

Note:
If you intend to add a new lower layer, please
Author:
Rainer Gerhards <rgerhards@adiscon.com>
Date:
2003-08-05 Created this file as upper-layer and general entry point to the socket object. It includes the necessry lower layer according to the config.h OS defines.
Copyright 2002-2003 Rainer Gerhards and Adiscon GmbH. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of Adiscon GmbH or Rainer Gerhards nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Function Documentation

srRetVal sbSockGetIPusedForSending sbSockObj pThis,
char **  ppsz
 

Provide the (local) IP address this session is sending to the remote peer on as a string.

OK, the short description is probably not very well ;) What it does is, it looks up the local IP address that is used to talk to the remote Peer. This is especially important on multihomed machines, as different interfaces can be used to forward data (depending on which one is closest to the recipient). Then, it formats this as an IP Address string that then is handed back to the caller.

Please note: the socket MUST be connected before you can use this method! It should NOT be used on UDP sockets.

Parameters:
ppsz Pointer to a char* that will receive the IP string. The caller must free the returned pointer when he is done. The provided pointer must not be NULL.

int sbSockGetLastSockError sbSockObj  ) 
 

get last error code

Return values:
last error code (OS specific)

int sbSockGetRcvChar sbSockObj pThis  ) 
 

Read the next character from the stream.

The character is removed from the stream. If no data is ready on the stream, a blocking read is carried out. So this function can block!

Return values:
character read

srRetVal sbSockGetRemoteHostIP sbSockObj pThis,
char **  ppszHost
 

Return the IP Address of the remote host as a string.

The caller must free the returned string.

sbSockObj* sbSockInitListenSock srRetVal iRet,
int  iType,
char *  szBindToAddress,
unsigned  uBindToPort
 

Initialize a listen socket.

This includes everything so that the next call can be listen().

Parameters:
iRet [out] Pointer to a variable holding the return code of this operation. Has the error code if initialisation failed.
iType sockets type to be used. Must be either SOCK_STREAM or SOCK_DGRAM.
szBindToAdresse string with IP address to which the socket should be bound. If NULL, do not bind to any specific address.
iBindToPort Port the socket should be bound to. For listening sockets, this is the port that the remote peer will to connect to.
Return values:
Pointer to newly created socket or NULL, if an error occured. In case of NULL, the caller can examine the socket error code to learn the error cause.

int sbSockPeekRcvChar sbSockObj pThis  ) 
 

Peek at the next character from the stream.

The character is NOT removed from the stream. If no data is ready on the stream, a blocking read is carried out. So this function can block!

Return values:
character read

srRetVal sbSockRecvFrom sbSockObj pThis,
char *  pRecvBuf,
int *  piBufLen,
char **  ppFrom
 

Enhanced recvfrom() clone.

Will receive an C sz String. That is, any received as part of the string will be replaced by ABNF SP (' ').

Parameters:
pRecvBuf Pointer to buffer that will receive the incoming data.
piBufLen On entry, the size of the buffer pointed to by pRecvBuf. On exit, the number of bytes received
ppFrom Pointer to a char pointer that will receive a string with the senders' IP address. This buffer MUST be free()ed by the caller!
Todo:
handle the connection closed case (*piBuflen == 0)

srRetVal sbSockWaitReceiveData struct sbSockObject pThis  ) 
 

Wait until the socket has some receive data.

This is a blocking call.


Generated on Mon Oct 3 12:29:56 2005 for liblogging by doxygen 1.3.2