2004-04-22 02:10:48 +02:00
|
|
|
#ifndef __COMMON_H__
|
|
|
|
#define __COMMON_H__
|
|
|
|
|
2007-11-07 20:27:18 +01:00
|
|
|
#include "config-host.h"
|
2004-04-22 02:10:48 +02:00
|
|
|
#include "slirp_config.h"
|
|
|
|
|
2004-07-13 00:33:07 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
# include <inttypes.h>
|
|
|
|
|
|
|
|
typedef uint8_t u_int8_t;
|
|
|
|
typedef uint16_t u_int16_t;
|
|
|
|
typedef uint32_t u_int32_t;
|
|
|
|
typedef uint64_t u_int64_t;
|
|
|
|
typedef char *caddr_t;
|
|
|
|
|
2005-01-11 00:19:34 +01:00
|
|
|
# include <windows.h>
|
2004-07-13 00:33:07 +02:00
|
|
|
# include <winsock2.h>
|
2008-05-17 20:07:00 +02:00
|
|
|
# include <ws2tcpip.h>
|
2004-07-13 00:33:07 +02:00
|
|
|
# include <sys/timeb.h>
|
|
|
|
# include <iphlpapi.h>
|
|
|
|
|
|
|
|
# define EWOULDBLOCK WSAEWOULDBLOCK
|
|
|
|
# define EINPROGRESS WSAEINPROGRESS
|
|
|
|
# define ENOTCONN WSAENOTCONN
|
|
|
|
# define EHOSTUNREACH WSAEHOSTUNREACH
|
|
|
|
# define ENETUNREACH WSAENETUNREACH
|
|
|
|
# define ECONNREFUSED WSAECONNREFUSED
|
|
|
|
#else
|
|
|
|
# define ioctlsocket ioctl
|
|
|
|
# define closesocket(s) close(s)
|
2004-10-10 00:57:43 +02:00
|
|
|
# define O_BINARY 0
|
2004-07-13 00:33:07 +02:00
|
|
|
#endif
|
|
|
|
|
2004-04-22 02:10:48 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_SYS_BITYPES_H
|
|
|
|
# include <sys/bitypes.h>
|
|
|
|
#endif
|
|
|
|
|
2004-06-03 14:53:17 +02:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2004-04-22 02:10:48 +02:00
|
|
|
#ifdef NEED_TYPEDEFS
|
|
|
|
typedef char int8_t;
|
|
|
|
typedef unsigned char u_int8_t;
|
|
|
|
|
|
|
|
# if SIZEOF_SHORT == 2
|
|
|
|
typedef short int16_t;
|
|
|
|
typedef unsigned short u_int16_t;
|
|
|
|
# else
|
|
|
|
# if SIZEOF_INT == 2
|
|
|
|
typedef int int16_t;
|
|
|
|
typedef unsigned int u_int16_t;
|
|
|
|
# else
|
|
|
|
#error Cannot find a type with sizeof() == 2
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# if SIZEOF_SHORT == 4
|
|
|
|
typedef short int32_t;
|
|
|
|
typedef unsigned short u_int32_t;
|
|
|
|
# else
|
|
|
|
# if SIZEOF_INT == 4
|
|
|
|
typedef int int32_t;
|
|
|
|
typedef unsigned int u_int32_t;
|
|
|
|
# else
|
|
|
|
#error Cannot find a type with sizeof() == 4
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
#endif /* NEED_TYPEDEFS */
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
# include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#ifndef HAVE_MEMMOVE
|
|
|
|
#define memmove(x, y, z) bcopy(y, x, z)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if TIME_WITH_SYS_TIME
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <time.h>
|
|
|
|
#else
|
2008-09-06 19:47:39 +02:00
|
|
|
# ifdef HAVE_SYS_TIME_H
|
2004-04-22 02:10:48 +02:00
|
|
|
# include <sys/time.h>
|
|
|
|
# else
|
|
|
|
# include <time.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#else
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2004-07-13 00:33:07 +02:00
|
|
|
#ifndef _WIN32
|
2004-04-22 02:10:48 +02:00
|
|
|
#include <sys/uio.h>
|
2004-07-13 00:33:07 +02:00
|
|
|
#endif
|
2004-04-22 02:10:48 +02:00
|
|
|
|
2004-07-13 00:33:07 +02:00
|
|
|
#ifndef _WIN32
|
2004-04-22 02:10:48 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2004-07-13 00:33:07 +02:00
|
|
|
#endif
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
/* Systems lacking strdup() definition in <string.h>. */
|
|
|
|
#if defined(ultrix)
|
2009-07-01 21:11:17 +02:00
|
|
|
char *strdup(const char *);
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Systems lacking malloc() definition in <stdlib.h>. */
|
|
|
|
#if defined(ultrix) || defined(hcx)
|
2009-07-01 21:11:17 +02:00
|
|
|
void *malloc(size_t arg);
|
|
|
|
void free(void *ptr);
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_INET_ATON
|
2009-07-01 21:11:17 +02:00
|
|
|
int inet_aton(const char *cp, struct in_addr *ia);
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#ifndef NO_UNIX_SOCKETS
|
|
|
|
#include <sys/un.h>
|
|
|
|
#endif
|
|
|
|
#include <signal.h>
|
|
|
|
#ifdef HAVE_SYS_SIGNAL_H
|
|
|
|
# include <sys/signal.h>
|
|
|
|
#endif
|
2004-07-13 00:33:07 +02:00
|
|
|
#ifndef _WIN32
|
2004-04-22 02:10:48 +02:00
|
|
|
#include <sys/socket.h>
|
2004-07-13 00:33:07 +02:00
|
|
|
#endif
|
2004-04-22 02:10:48 +02:00
|
|
|
|
2004-07-12 23:11:45 +02:00
|
|
|
#if defined(HAVE_SYS_IOCTL_H)
|
2004-04-22 02:10:48 +02:00
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
# include <sys/select.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
# include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_FILIO_H
|
|
|
|
# include <sys/filio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_PPP
|
|
|
|
#include <ppp/slirppp.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __STDC__
|
|
|
|
#include <stdarg.h>
|
|
|
|
#else
|
|
|
|
#include <varargs.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
/* Avoid conflicting with the libc insque() and remque(), which
|
|
|
|
have different prototypes. */
|
|
|
|
#define insque slirp_insque
|
|
|
|
#define remque slirp_remque
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_STROPTS_H
|
|
|
|
#include <sys/stropts.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2009-09-12 09:36:22 +02:00
|
|
|
#include "qemu-queue.h"
|
2009-06-24 14:42:31 +02:00
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
#include "libslirp.h"
|
2004-04-22 02:10:48 +02:00
|
|
|
#include "ip.h"
|
|
|
|
#include "tcp.h"
|
|
|
|
#include "tcp_timer.h"
|
|
|
|
#include "tcp_var.h"
|
|
|
|
#include "tcpip.h"
|
|
|
|
#include "udp.h"
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "sbuf.h"
|
|
|
|
#include "socket.h"
|
|
|
|
#include "if.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#ifdef USE_PPP
|
|
|
|
#include "ppp/pppd.h"
|
|
|
|
#include "ppp/ppp.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "bootp.h"
|
2004-08-24 23:57:12 +02:00
|
|
|
#include "tftp.h"
|
2009-06-24 14:42:31 +02:00
|
|
|
|
2009-12-02 12:24:42 +01:00
|
|
|
/* osdep.c */
|
|
|
|
int qemu_socket(int domain, int type, int protocol);
|
|
|
|
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
struct Slirp {
|
2009-09-12 09:36:22 +02:00
|
|
|
QTAILQ_ENTRY(Slirp) entry;
|
2009-06-24 14:42:31 +02:00
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
/* virtual network configuration */
|
|
|
|
struct in_addr vnetwork_addr;
|
|
|
|
struct in_addr vnetwork_mask;
|
|
|
|
struct in_addr vhost_addr;
|
|
|
|
struct in_addr vdhcp_startaddr;
|
|
|
|
struct in_addr vnameserver_addr;
|
|
|
|
|
|
|
|
/* ARP cache for the guest IP addresses (XXX: allow many entries) */
|
|
|
|
uint8_t client_ethaddr[6];
|
|
|
|
|
|
|
|
struct in_addr client_ipaddr;
|
|
|
|
char client_hostname[33];
|
|
|
|
|
|
|
|
int restricted;
|
|
|
|
struct timeval tt;
|
|
|
|
struct ex_list *exec_list;
|
|
|
|
|
|
|
|
/* mbuf states */
|
|
|
|
struct mbuf m_freelist, m_usedlist;
|
|
|
|
int mbuf_alloced;
|
|
|
|
|
|
|
|
/* if states */
|
|
|
|
int if_queued; /* number of packets queued so far */
|
|
|
|
struct mbuf if_fastq; /* fast queue (for interactive data) */
|
|
|
|
struct mbuf if_batchq; /* queue for non-interactive data */
|
|
|
|
struct mbuf *next_m; /* pointer to next mbuf to output */
|
|
|
|
|
|
|
|
/* ip states */
|
|
|
|
struct ipq ipq; /* ip reass. queue */
|
|
|
|
u_int16_t ip_id; /* ip packet ctr, for ids */
|
|
|
|
|
|
|
|
/* bootp/dhcp states */
|
|
|
|
BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
|
|
|
|
char *bootp_filename;
|
|
|
|
|
|
|
|
/* tcp states */
|
|
|
|
struct socket tcb;
|
|
|
|
struct socket *tcp_last_so;
|
|
|
|
tcp_seq tcp_iss; /* tcp initial send seq # */
|
|
|
|
u_int32_t tcp_now; /* for RFC 1323 timestamps */
|
|
|
|
|
|
|
|
/* udp states */
|
|
|
|
struct socket udb;
|
|
|
|
struct socket *udp_last_so;
|
|
|
|
|
|
|
|
/* tftp states */
|
|
|
|
char *tftp_prefix;
|
|
|
|
struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
void *opaque;
|
2009-06-24 14:42:31 +02:00
|
|
|
};
|
|
|
|
|
2009-06-24 14:42:31 +02:00
|
|
|
extern Slirp *slirp_instance;
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL (void *)0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef FULL_BOLT
|
2009-07-01 21:11:17 +02:00
|
|
|
void if_start(Slirp *);
|
2004-04-22 02:10:48 +02:00
|
|
|
#else
|
2009-07-01 21:11:17 +02:00
|
|
|
void if_start(struct ttys *);
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BAD_SPRINTF
|
|
|
|
# define vsprintf vsprintf_len
|
|
|
|
# define sprintf sprintf_len
|
2009-07-01 21:11:17 +02:00
|
|
|
extern int vsprintf_len(char *, const char *, va_list);
|
|
|
|
extern int sprintf_len(char *, const char *, ...);
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DECLARE_SPRINTF
|
|
|
|
# ifndef BAD_SPRINTF
|
2009-07-01 21:11:17 +02:00
|
|
|
extern int vsprintf(char *, const char *, va_list);
|
2004-04-22 02:10:48 +02:00
|
|
|
# endif
|
2009-07-01 21:11:17 +02:00
|
|
|
extern int vfprintf(FILE *, const char *, va_list);
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRERROR
|
2009-07-01 21:11:17 +02:00
|
|
|
extern char *strerror(int error);
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_INDEX
|
2009-07-01 21:11:17 +02:00
|
|
|
char *index(const char *, int);
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_GETHOSTID
|
2009-07-01 21:11:17 +02:00
|
|
|
long gethostid(void);
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|
|
|
|
|
2009-07-01 21:11:17 +02:00
|
|
|
void lprint(const char *, ...);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
2004-07-13 00:33:07 +02:00
|
|
|
#ifndef _WIN32
|
2004-04-22 02:10:48 +02:00
|
|
|
#include <netdb.h>
|
2004-07-13 00:33:07 +02:00
|
|
|
#endif
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
#define DEFAULT_BAUD 115200
|
|
|
|
|
2007-10-26 21:01:16 +02:00
|
|
|
#define SO_OPTIONS DO_KEEPALIVE
|
|
|
|
#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
|
|
|
|
|
2004-04-22 02:10:48 +02:00
|
|
|
/* cksum.c */
|
|
|
|
int cksum(struct mbuf *m, int len);
|
|
|
|
|
|
|
|
/* if.c */
|
2009-07-01 21:11:17 +02:00
|
|
|
void if_init(Slirp *);
|
|
|
|
void if_output(struct socket *, struct mbuf *);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
/* ip_input.c */
|
2009-07-01 21:11:17 +02:00
|
|
|
void ip_init(Slirp *);
|
|
|
|
void ip_input(struct mbuf *);
|
|
|
|
void ip_slowtimo(Slirp *);
|
|
|
|
void ip_stripoptions(register struct mbuf *, struct mbuf *);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
/* ip_output.c */
|
2009-07-01 21:11:17 +02:00
|
|
|
int ip_output(struct socket *, struct mbuf *);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
/* tcp_input.c */
|
2009-07-01 21:11:17 +02:00
|
|
|
void tcp_input(register struct mbuf *, int, struct socket *);
|
|
|
|
int tcp_mss(register struct tcpcb *, u_int);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
/* tcp_output.c */
|
2009-07-01 21:11:17 +02:00
|
|
|
int tcp_output(register struct tcpcb *);
|
|
|
|
void tcp_setpersist(register struct tcpcb *);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
/* tcp_subr.c */
|
2009-07-01 21:11:17 +02:00
|
|
|
void tcp_init(Slirp *);
|
|
|
|
void tcp_template(struct tcpcb *);
|
|
|
|
void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
|
|
|
|
struct tcpcb * tcp_newtcpcb(struct socket *);
|
|
|
|
struct tcpcb * tcp_close(register struct tcpcb *);
|
|
|
|
void tcp_sockclosed(struct tcpcb *);
|
|
|
|
int tcp_fconnect(struct socket *);
|
|
|
|
void tcp_connect(struct socket *);
|
|
|
|
int tcp_attach(struct socket *);
|
|
|
|
u_int8_t tcp_tos(struct socket *);
|
|
|
|
int tcp_emu(struct socket *, struct mbuf *);
|
|
|
|
int tcp_ctl(struct socket *);
|
2004-04-26 21:50:09 +02:00
|
|
|
struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
|
2004-04-22 02:10:48 +02:00
|
|
|
|
|
|
|
#ifdef USE_PPP
|
|
|
|
#define MIN_MRU MINMRU
|
|
|
|
#define MAX_MRU MAXMRU
|
|
|
|
#else
|
|
|
|
#define MIN_MRU 128
|
|
|
|
#define MAX_MRU 16384
|
|
|
|
#endif
|
|
|
|
|
2004-07-13 00:33:07 +02:00
|
|
|
#ifndef _WIN32
|
|
|
|
#define min(x,y) ((x) < (y) ? (x) : (y))
|
|
|
|
#define max(x,y) ((x) > (y) ? (x) : (y))
|
|
|
|
#endif
|
|
|
|
|
2004-10-08 01:27:35 +02:00
|
|
|
#ifdef _WIN32
|
2004-11-14 19:58:04 +01:00
|
|
|
#undef errno
|
2004-10-08 01:27:35 +02:00
|
|
|
#define errno (WSAGetLastError())
|
|
|
|
#endif
|
|
|
|
|
2004-04-22 02:10:48 +02:00
|
|
|
#endif
|