liblogging: socketsWin32.c File Reference

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

# socketsWin32.c File Reference

Socket layer/driver for Win32. More...

## Functions
srRetVal | sbSockLayerInit (int bInitOSStack)
| Global Layer initialization.
srRetVal | sbSockLayerExit (int bExitOSStack)
| Global Layer destructor.
sbSockObj * | sbSockInit (void)
| Constructor for STREAM sockets, only.
sbSockObj * | sbSockInitEx (int iAF, int iSockType)
| Alternate Constructur.
srRetVal | sbSockSetNonblocking (sbSockObj *pThis)
| Set the socket to nonblocking state.
srRetVal | sbSockAccept (sbSockObj *pThis, sbSockObj *pNew, struct sockaddr *sa, int *iSizeSA)
| Wrapper for the socket accept() call.
srRetVal | sbSockListen (sbSockObj *pThis)
| Wrapper for the socket listen() call.
srRetVal | sbSockClosesocket (sbSockObj *pThis)
| Close a socket.
int | sbSockSelectMulti (srSock_fd_set *fdsetRD, srSock_fd_set *fdsetWR, int iTimOutSecs, int iTimOutMSecs)
| Wrapper for the socket select call on a fd_set structure.
int | sbSockSelect (struct sbSockObject *pThis, int iTimOutSecs, int iTimOutMSecs)
| Wrapper for the socket select call on a single socket.
int | sbSockReceive (struct sbSockObject *pThis, char *pszBuf, int iLen)
int | sbSockSend (struct sbSockObject *pThis, const char *pszBuf, int iLen)
srRetVal | sbSockConnectoToHost (sbSockObj *pThis, char *pszHost, int iPort)
| Connect a socket to a remote host.
srRetVal | sbSockBind (sbSockObj *pThis, char *pszHost, int iPort)
| Bind a socket to the provided address.
srRetVal | sbSock_gethostname (char **psz)
| Wrapper for gethostname().

## Detailed Description

Socket layer/driver for Win32.

This is the socket layer for Win32.

Author:
  Rainer Gerhards <rgerhards@adiscon.com>

Date:
  2003-08-04

  2003-08-05 Modified to be a plain lower layer. Moved some of the code to sockets::c.

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 sbSock_gethostname | ( | char ** | psz | ) |

  | Wrapper for gethostname(). Note: The Windows sockets API seems to be broken. We often have seen that only the computer name part (not the domain name) is returned by gethostname, even if the full identity is configured. A way to work around this may be to call gethostbyname() on the returned name and then call gethostbyaddr() on what is returned there. WE HAVE NOW IMPLEMENTED THIS WORKAROUND, but leave the text above in just in case... Parameters:
  psz | Pointer to Pointer to hostname. Must not be NULL. On return, this pointer will refer to a newly allocated buffer containing the hostname. This buffer must be free()ed by the caller!

srRetVal sbSockBind | ( | sbSockObj * | pThis,
|  | char * | pszHost,
|  | int | iPort
| ) |

  | Bind a socket to the provided address. Parameters:
  pszAddr | Address to bind to. This is a string. If NULL, no specific address is used. Please keep in mind that a specific bind to an address may steal the port and thus NULL could be causing a security vulnerability.
  iPort | Port to bind to.
sorry, other modes currently not supported Todo: implement!

srRetVal sbSockConnectoToHost | ( | sbSockObj * | pThis,
|  | char * | pszHost,
|  | int | iPort
| ) |

  | Connect a socket to a remote host. Parameters:
  pszHost | Name or IP address of host to connect to
  iPort | Port to connect to

sbSockObj* sbSockInit | ( | void |  | ) |

  | Constructor for STREAM sockets, only. Return values:
  Returns | a pointer to the new instance or NULL, if it could not be created.

sbSockObj* sbSockInitEx | ( | int | af,
|  | int | iSockType
| ) |

| Alternate Constructur. Socket TYPE (STREAM/DGRAM) can be specified

srRetVal sbSockLayerExit | ( | int | bExitOSStack | ) |

  | Global Layer destructor. Call this only once at the end of the application. All sockets must be destroyed before calling this method. Parameters:
  bExitOSStack | Specifies if the library should shut down the operating system socket stack. If 1, it shuts it down, if 0, it does not. Set this to 0 if you integrate this lib into an app that otherwise shuts down the OS socket lib itself.

srRetVal sbSockLayerInit | ( | int | bInitOSStack | ) |

  | Global Layer initialization. Should be called only once per application. This will do all housekeeping necessary to use the layer. DO NOT CALL ANY OTHER METHODS BEFORE THIS ONE HAS BEEN CALLED! They will probably fail! Parameters:
  bInitOSStack | Specifies if the library should initialize the operating system socket stack. If 1, it initializes it, if 0, it does not. Set this to 0 if you integrate this lib into an app that otherwise initializes the socket lib itself.

int sbSockSelect | ( | struct sbSockObject * | pThis,
|  | int | iTimOutSecs,
|  | int | iTimOutMSecs
| ) |

  | Wrapper for the socket select call on a single socket. Parameters:
  iTimOutSecs | Seconds until timeout. -1 means indefinite blocking.
  iTimOutMSecs | Milliseconds until timeout.
  Return values:
  Value | returned by select.

int sbSockSelectMulti | ( | srSock_fd_set * | fdsetRD,
|  | srSock_fd_set * | fdsetWR,
|  | int | iTimOutSecs,
|  | int | iTimOutMSecs
| ) |

  | Wrapper for the socket select call on a fd_set structure. Parameters:
  fdsetRD | fdset structure for read-awaiting sockets. May be NULL.
  fdsetWR | fdset structure for write-awaiting sockets. May be NULL.
  iTimOutSecs | Seconds until timeout. -1 means indefinite blocking.
  iTimOutMSecs | Milliseconds until timeout.
  Return values:
  Value | returned by select.