slirp.c revision 62690540b00cb711916728639049c18b31c206b0
#include "slirp.h"
#ifdef __OS2__
# include <paths.h>
#endif
0x52, 0x54, 0x00, 0x12, 0x35, 0x00
};
#ifdef _WIN32
const char **ppszDomain)
{
int rc = 0;
BufLen = sizeof(FIXED_INFO);
if (FixedInfo) {
}
}
if (FixedInfo) {
}
rc = -1;
goto get_dns_prefix;
}
Log(("nat: DNS Servers:\n"));
while ( pIPAddr ) {
}
if (FixedInfo) {
}
*ppszDomain = NULL;
{
char szDnsDomain[256];
GetVersionEx(&ver);
{
/* GetComputerNameEx exists in Windows versions starting with 2000. */
{
if (szDnsDomain[0])
{
/* Just non-empty strings are valid. */
if (pData->fPassDomain)
else
}
}
else
}
}
return rc;
}
#else
const char **ppszDomain)
{
char buff[512];
char buff2[256];
FILE *f;
int found = 0;
#ifdef __OS2__
/* Try various locations. */
f = NULL;
if (etc)
{
}
if (!f) {
}
if (!f) {
}
#else
#endif
if (!f)
return -1;
*ppszDomain = NULL;
Log(("nat: IP address of your DNS(s): \n"));
continue;
/* If it's the first one, set it to dns_addr */
if (!found)
if (++found > 3) {
Log(("nat: (more)\n"));
break;
} else
}
{
if (*ppszDomain == NULL)
{
char *tok;
if (tok)
{
if (pData->fPassDomain)
else
}
}
}
}
fclose(f);
if (!found)
return -1;
return 0;
}
#endif
{
int fNATfailed = 0;
if (!pData)
return VERR_NO_MEMORY;
#if ARCH_BITS == 64
#endif
#ifdef _WIN32
{
}
#endif
link_up = 1;
/* Initialise mbufs *after* setting the MTU */
/* set default addresses */
fNATfailed = 1;
}
/**
* Marks the link as up, making it possible to establish new connections.
*/
{
link_up = 1;
}
/**
* Marks the link as down and cleans up the current connections.
*/
{
{
else
}
link_up = 0;
}
/**
* Terminates the slirp component.
*/
{
#if ARCH_BITS == 64
LogRel(("NAT: cpvHashUsed=%RU32 cpvHashCollisions=%RU32 cpvHashInserts=%RU64 cpvHashDone=%RU64\n",
#endif
#ifdef WIN32
WSACleanup();
#endif
#ifdef LOG_ENABLED
Log(("\n"
"NAT statistics\n"
"--------------\n"
"\n"));
Log(("\n"
"\n"
"\n"));
#endif
}
#define CONN_CANFSEND(so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
/*
* curtime kept to an accuracy of 1ms
*/
#ifdef _WIN32
{
}
#else
{
gettimeofday(&tt, 0);
curtime++;
}
#endif
{
int nfds;
int tmp_time;
/*
* First, TCP sockets
*/
do_slowtimo = 0;
if (link_up) {
/*
* *_slowtimo needs calling if there are IP fragments
* in the fragment queue, or there are TCP connections active
*/
/*
* See if we need a tcp_fasttimo
*/
/*
* NOFDREF can include still connecting to local-host,
* newly socreated() sockets etc. Don't want to select these.
*/
continue;
/*
* Set for reading sockets which are accepting
*/
continue;
}
/*
* Set for writing sockets which are connecting
*/
continue;
}
/*
* Set for writing if we are connected, can send more, and
* we have something to send
*/
}
/*
* Set for reading (and urgent data) if we are connected, can
* receive more, and we have room for it XXX /2 ?
*/
}
}
/*
* UDP sockets
*/
/*
* See if it's timed out
*/
continue;
} else
}
/*
* When UDP packets are received from over the
* link, they're sendto()'d straight away, so
* no need for setting for writing
* Limit the number of packets queued by this session
* to 4. Note that even though we try and limit this
* to 4 packets, the session could have more queued
* if the packets needed to be fragmented
* (XXX <= 4 ?)
*/
}
}
}
/*
* Setup timeout to use minimum CPU usage, especially when idle
*/
/*
* First, see the timeout needed by *timo
*/
/*
* If a slowtimo is needed, set timeout to 500ms from the last
* slow timeout. If a fast timeout is needed, set timeout within
* 200ms of when it was requested.
*/
if (do_slowtimo) {
/* XXX + 10000 because some select()'s aren't that accurate */
/* Can only fasttimo if we also slowtimo */
if (time_fasttimo) {
if (tmp_time < 0)
tmp_time = 0;
/* Choose the smallest of the 2 */
}
}
}
{
int ret;
/* Update time */
/*
* See if anything has timed out
*/
if (link_up) {
time_fasttimo = 0;
}
}
}
/*
* Check sockets
*/
if (link_up) {
/*
* Check TCP sockets
*/
/*
* FD_ISSET is meaningless on these sockets
* (and they can crash the program)
*/
continue;
/*
* Check for URG data
* This will soread as well, so no need to
* test for readfds below if this succeeds
*/
/*
* Check sockets for reading
*/
/*
* Check for incoming connections
*/
continue;
} /* else */
/* Output it if we read something */
if (ret > 0)
}
/*
* Check sockets for writing
*/
/*
* Check for non-blocking, still-connecting sockets
*/
/* Connected */
if (ret < 0) {
/* XXXXX Must fix, zero bytes is a NOP */
continue;
/* else failed */
}
/* else so->so_state &= ~SS_ISFCONNECTING; */
/*
* Continue tcp_input
*/
/* continue; */
} else
/*
* XXXXX If we wrote something (a lot), there
* could be a need for a window update.
* In the worst case, the remote will send
* a window probe to get things going again
*/
}
/*
* Probe a still-connecting, non-blocking socket
* to check if it's still alive
*/
#ifdef PROBE_CONN
if (ret < 0) {
/* XXX */
continue; /* Still connecting, continue */
/* else failed */
/* tcp_input will take care of it */
} else {
if (ret < 0) {
/* XXX */
continue;
/* else failed */
} else
}
} /* SS_ISFCONNECTING */
#endif
}
/*
* Now UDP sockets.
* Incoming packets are sent straight away, they're not buffered.
* Incoming UDP data isn't buffered either.
*/
}
}
}
/*
* See if we can start outputting
*/
}
#define ETH_ALEN 6
#define ETH_HLEN 14
struct ethhdr
{
unsigned short h_proto; /* packet type ID field */
};
struct arphdr
{
unsigned short ar_hrd; /* format of hardware address */
unsigned short ar_pro; /* format of protocol address */
unsigned char ar_hln; /* length of hardware address */
unsigned char ar_pln; /* length of protocol address */
unsigned short ar_op; /* ARP opcode (command) */
/*
* Ethernet looks like this : This bit is variable sized however...
*/
};
static
{
int ar_op;
switch(ar_op) {
case ARPOP_REQUEST:
goto arp_ok;
goto arp_ok;
}
return;
/* XXX: make an ARP request to have the client address */
}
break;
default:
break;
}
}
{
struct mbuf *m;
int proto;
return;
switch(proto) {
case ETH_P_ARP:
break;
case ETH_P_IP:
/* Update time. Important if the network is very quiet, as otherwise
* the first outgoing connection gets an incorrect timestamp. */
if (!m)
return;
/* Note: we add to align the IP header */
}
break;
default:
break;
}
}
/* output the IP packet to the ethernet device */
{
return;
/* XXX: not correct */
}
{
if (is_udp) {
htons(guest_port), 0))
return -1;
} else {
htons(guest_port), 0))
return -1;
}
return 0;
}
int guest_port)
{
}