misc.c revision 74853b3588bff974298f37b7cb5a1811e8ff9ac1
/*
* Copyright (c) 1995 Danny Gasparovski.
*
* Please read the file COPYRIGHT for the
* terms and conditions of the copyright.
*/
#define WANT_SYS_IOCTL_H
#include <slirp.h>
#if 0
int x_port = -1;
int x_display = 0;
int x_screen = 0;
int
char *buff;
{
if (x_port < 0) {
lprint("X Redir: X not being redirected.\r\n");
} else {
if (x_display)
}
return CFG_OK;
}
/*
* XXX Allow more than one X redirection?
*/
void
int start_port;
int display;
int screen;
{
int i;
if (x_port >= 0) {
lprint("X Redir: X already being redirected.\r\n");
show_x(0, 0);
} else {
/* Success */
x_port = i - 6000;
show_x(0, 0);
return;
}
}
lprint("X Redir: Error: Couldn't redirect a port for X. Weird.\r\n");
}
}
#endif
#ifndef HAVE_INET_ATON
int
const char *cp;
{
if (addr == 0xffffffff)
return 0;
return 1;
}
#endif
/*
* Get our IP address and put it in our_addr
*/
void
{
char buff[256];
if (he)
}
#if SIZEOF_CHAR_P == 8
struct quehead_32 {
};
void
{
}
void
{
}
#endif /* SIZEOF_CHAR_P == 8 */
struct quehead {
};
void
{
}
void
{
/* element->qh_link = NULL; TCP FIN1 crashes if you do this. Why ? */
}
/* #endif */
int
int do_pty;
char *exec;
int addr;
int port;
{
/* First, check if the port is "bound" */
return -1;
}
return 0;
}
#ifndef HAVE_STRERROR
/*
* For systems with no strerror
*/
extern int sys_nerr;
extern char *sys_errlist[];
char *
int error;
{
return sys_errlist[error];
else
return "Unknown error.";
}
#endif
#ifdef _WIN32
int
{
/* not implemented */
return 0;
}
#else
/*
* XXX This is ugly
* We create and bind a socket, then fork off to another
* process, which connects to this socket, after which we
* exec the wanted program. If something (strange) happens,
* the accept() call could block us forever.
*
*/
int
{
int s;
struct sockaddr_in addr;
int opt;
int master;
char *argv[256];
#if 0
char buff[256];
#endif
/* don't want to clobber the original */
char *bptr;
char *curarg;
int c, i, ret;
DEBUG_CALL("fork_exec");
if (do_pty == 2) {
/* shut up gcc */
s = 0;
master = 0;
} else {
listen(s, 1) < 0) {
closesocket(s);
return 0;
}
}
switch(fork()) {
case -1:
close(s);
if (do_pty == 2)
return 0;
case 0:
/* Set the DISPLAY */
if (do_pty == 2) {
#ifdef TIOCSCTTY /* XXXXX */
(void) setsid();
#endif
} else {
close(s);
/*
* Connect to the socket
* XXX If any of these fail, we're in trouble!
*/
do {
}
#if 0
if (x_port >= 0) {
#ifdef HAVE_SETENV
#else
#endif
}
#endif
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
for (s = 3; s <= 255; s++)
close(s);
i = 0;
if (do_pty == 1) {
/* Setup "slirp.telnetd -x" */
argv[i++] = "-x";
} else
do {
/* Change the string into argv[] */
bptr++;
c = *bptr;
*bptr++ = (char)0;
} while (c);
argv[i] = 0;
/* Ooops, failed, let's tell the user why */
{
char buff[256];
}
exit(1);
default:
if (do_pty == 2) {
close(s);
} else {
/*
* XXX this could block us...
* XXX Should set a timer here, and if accept() doesn't
* return after X seconds, declare it a failure
* The only reason this will block forever is if socket()
* of connect() fail in the child process
*/
do {
closesocket(s);
opt = 1;
opt = 1;
}
fd_nonblock(so->s);
/* Append the telnet options now */
}
return 1;
}
}
#endif
#ifndef HAVE_STRDUP
char *
const char *str;
{
char *bptr;
return bptr;
}
#endif
#if 0
void
int num;
{
int s, ret;
#ifndef NO_UNIX_SOCKETS
struct sockaddr_un sock_un;
#endif
struct sockaddr_in sock_in;
char buff[256];
ret = -1;
if (slirp_socket_passwd) {
if (s < 0)
slirp_exit(1);
}
#ifndef NO_UNIX_SOCKETS
else {
if (s < 0)
slirp_exit(1);
slirp_exit(1);
}
#endif
slirp_exit(0);
}
void
snooze()
{
sigset_t s;
int i;
/* Don't need our data anymore */
/* XXX This makes SunOS barf */
/* brk(0); */
/* Close all fd's */
for (i = 255; i >= 0; i--)
close(i);
sigemptyset(&s);
/* Wait for any signal */
sigsuspend(&s);
/* Just in case ... */
exit(255);
}
void
relay(s)
int s;
{
char buf[8192];
int n;
/* Don't need our data anymore */
/* XXX This makes SunOS barf */
/* brk(0); */
/* Fudge to get term_raw and term_restore to work */
slirp_exit (1);
}
while (1) {
if (n <= 0)
slirp_exit(0);
if (n <= 0)
slirp_exit(0);
if (n <= 0)
slirp_exit(0);
}
if (n <= 0)
slirp_exit(0);
if (n <= 0)
slirp_exit(0);
}
}
/* Just in case.... */
exit(1);
}
#endif
#ifdef BAD_SPRINTF
/*
* Some BSD-derived systems have a sprintf which returns char *
*/
int
char *string;
const char *format;
{
}
int
#ifdef __STDC__
#else
#endif
{
#ifdef __STDC__
#else
char *string;
char *format;
#endif
}
#endif
void
int usec;
{
struct timeval t;
t.tv_sec = 0;
}
/*
* Set fd blocking and non-blocking
*/
void
int fd;
{
#ifdef FIONBIO
int opt = 1;
#else
int opt;
opt |= O_NONBLOCK;
#endif
}
void
int fd;
{
#ifdef FIONBIO
int opt = 0;
#else
int opt;
opt &= ~O_NONBLOCK;
#endif
}
#if 0
/*
* invoke RSH
*/
int
char *user;
char *host;
char *args;
{
int fd[2];
int fd0[2];
int s;
char buff[256];
DEBUG_CALL("rsh_exec");
return 0;
}
/* #ifdef HAVE_SOCKETPAIR */
#if 1
return 0;
}
#else
return 0;
}
#endif
switch(fork()) {
case -1:
return 0;
case 0:
/* Set the DISPLAY */
if (x_port >= 0) {
#ifdef HAVE_SETENV
#else
#endif
}
for (s = 3; s <= 255; s++)
close(s);
/* Ooops, failed, let's tell the user why */
exit(1);
default:
return 1;
}
}
#endif