socket.h revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
* NAT - socket handling (declarations/defines).
*/
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*
* This code is based on:
*
* Copyright (c) 1995 Danny Gasparovski.
*
* Please read the file COPYRIGHT for the
* terms and conditions of the copyright.
*/
/* MINE */
#ifndef _SLIRP_SOCKET_H_
#define _SLIRP_SOCKET_H_
#define SO_EXPIRE 240000
#define SO_EXPIREFAST 10000
/*
* Our socket structure
*/
struct socket
{
#if !defined(RT_OS_WINDOWS)
int s; /* The actual socket */
#else
union {
int s;
};
#endif
/* XXX union these with not-yet-used sbuf params */
* for non-blocking connect()'s, and
* PING reply's */
* so_mconn, for non-blocking connections */
int so_urgc;
int so_state; /* internal state flags SS_*, below */
int so_queued; /* Number of packets queued from this socket */
int so_nqueued; /* Number of packets queued in a row
* Used to determine when to "downgrade" a session
* from fastq to batchq */
#ifndef RT_OS_WINDOWS
int so_poll_index;
#endif /* !RT_OS_WINDOWS */
/*
*/
int so_close;
void *so_timeout_arg;
#ifdef VBOX_WITH_NAT_SERVICE
/* storage of source ether address */
unsigned char so_ethaddr[6];
#endif
/* required for port-forwarding */
/* libalias might attach the socket and we want to notify libalias we're freeing it */
void *so_pvLnk;
int so_cCloneCounter; /* number of clones */
#endif
/** These flags (''fUnderPolling'' and ''fShouldBeRemoved'') introduced to
* to let polling routine gain control over freeing socket whatever level of
* So polling routine when start processing socket alter it's state to
* ''fUnderPolling'' to 1, and clean (set to 0) when it finish.
* When polling routine calls functions it should be ensure on return,
* whether ''fShouldBeRemoved'' set or not, and depending on state call
* ''sofree'' or continue socket processing.
* On ''fShouldBeRemoved'' equal to 1, polling routine should call ''sofree'',
* clearing ''fUnderPolling'' to do real freeng of the socket and removing from
* the queue.
* @todo: perhaps, to simplefy the things we need some helper function.
* @note: it's used like a bool, I use 'int' to avoid compiler warnings
* appearing if [-Wc++-compat] used.
*/
int fUnderPolling;
/** This flag used by ''sofree'' function in following manner
*
* fUnderPolling = 1, then we don't remove socket from the queue, just
* alter value ''fShouldBeRemoved'' to 1, else we do removal.
*/
int fShouldBeRemoved;
};
/* this function inform libalias about socket close */
void slirpDeleteLinkSocket(void *pvLnk);
# define SOCKET_LOCK(so) do {} while (0)
# define SOCKET_UNLOCK(so) do {} while (0)
# define SOCKET_LOCK_CREATE(so) do {} while (0)
# define SOCKET_LOCK_DESTROY(so) do {} while (0)
/*
* Socket state bits. (peer means the host on the Internet,
* local host means the host on the other end of the modem)
*/
/* #define SS_ISFDISCONNECTED 0x020*/ /* Socket has disconnected from peer, in 2MSL state */
/* #define SS_CTL 0x080 */
#if defined(DECLARE_IOVEC) && !defined(HAVE_READV)
struct iovec
{
char *iov_base;
};
#endif
void so_init (void);
void soisfconnecting (register struct socket *);
void soisfconnected (register struct socket *);
void sofcantrcvmore (struct socket *);
void sofcantsendmore (struct socket *);
void soisfdisconnected (struct socket *);
/**
* Creates copy of UDP socket with specified addr
* fBindSocket - in case we want bind a real socket.
* @return copy of the socket with f_addr equal to u32ForeignAddr
*/
struct socket * soCloneUDPSocketWithForegnAddr(PNATState pData, bool fBindSocket, struct socket *pSo, uint32_t u32ForeignAddr);
struct socket *soLookUpClonedUDPSocket(PNATState pData, const struct socket *pcSo, uint32_t u32ForeignAddress);
#endif
static inline int soIgnorableErrorCode(int iErrorCode)
{
return ( iErrorCode == EINPROGRESS
|| iErrorCode == EAGAIN
|| iErrorCode == EWOULDBLOCK);
}
#endif /* _SOCKET_H_ */