@@ -46,6 +46,7 @@
|
||||
#endif
|
||||
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define ABS(x) ((x) > 0 ? (x) : -(x))
|
||||
#define BCD8(x) ((((x) / 10) << 4) | ((x) % 10))
|
||||
#define BCD16(x) ((((x) / 1000) << 12) | (((x) / 100) << 8) | BCD8(x))
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/* bootp/dhcp defines */
|
||||
|
||||
#define BOOTP_SERVER 67
|
||||
#define BOOTP_CLIENT 68
|
||||
|
||||
#define BOOTP_REQUEST 1
|
||||
#define BOOTP_REPLY 2
|
||||
|
||||
#define RFC1533_COOKIE 99, 130, 83, 99
|
||||
#define RFC1533_PAD 0
|
||||
#define RFC1533_NETMASK 1
|
||||
#define RFC1533_TIMEOFFSET 2
|
||||
#define RFC1533_GATEWAY 3
|
||||
#define RFC1533_TIMESERVER 4
|
||||
#define RFC1533_IEN116NS 5
|
||||
#define RFC1533_DNS 6
|
||||
#define RFC1533_LOGSERVER 7
|
||||
#define RFC1533_COOKIESERVER 8
|
||||
#define RFC1533_LPRSERVER 9
|
||||
#define RFC1533_IMPRESSSERVER 10
|
||||
#define RFC1533_RESOURCESERVER 11
|
||||
#define RFC1533_HOSTNAME 12
|
||||
#define RFC1533_BOOTFILESIZE 13
|
||||
#define RFC1533_MERITDUMPFILE 14
|
||||
#define RFC1533_DOMAINNAME 15
|
||||
#define RFC1533_SWAPSERVER 16
|
||||
#define RFC1533_ROOTPATH 17
|
||||
#define RFC1533_EXTENSIONPATH 18
|
||||
#define RFC1533_IPFORWARDING 19
|
||||
#define RFC1533_IPSOURCEROUTING 20
|
||||
#define RFC1533_IPPOLICYFILTER 21
|
||||
#define RFC1533_IPMAXREASSEMBLY 22
|
||||
#define RFC1533_IPTTL 23
|
||||
#define RFC1533_IPMTU 24
|
||||
#define RFC1533_IPMTUPLATEAU 25
|
||||
#define RFC1533_INTMTU 26
|
||||
#define RFC1533_INTLOCALSUBNETS 27
|
||||
#define RFC1533_INTBROADCAST 28
|
||||
#define RFC1533_INTICMPDISCOVER 29
|
||||
#define RFC1533_INTICMPRESPOND 30
|
||||
#define RFC1533_INTROUTEDISCOVER 31
|
||||
#define RFC1533_INTROUTESOLICIT 32
|
||||
#define RFC1533_INTSTATICROUTES 33
|
||||
#define RFC1533_LLTRAILERENCAP 34
|
||||
#define RFC1533_LLARPCACHETMO 35
|
||||
#define RFC1533_LLETHERNETENCAP 36
|
||||
#define RFC1533_TCPTTL 37
|
||||
#define RFC1533_TCPKEEPALIVETMO 38
|
||||
#define RFC1533_TCPKEEPALIVEGB 39
|
||||
#define RFC1533_NISDOMAIN 40
|
||||
#define RFC1533_NISSERVER 41
|
||||
#define RFC1533_NTPSERVER 42
|
||||
#define RFC1533_VENDOR 43
|
||||
#define RFC1533_NBNS 44
|
||||
#define RFC1533_NBDD 45
|
||||
#define RFC1533_NBNT 46
|
||||
#define RFC1533_NBSCOPE 47
|
||||
#define RFC1533_XFS 48
|
||||
#define RFC1533_XDM 49
|
||||
|
||||
#define RFC2132_REQ_ADDR 50
|
||||
#define RFC2132_LEASE_TIME 51
|
||||
#define RFC2132_MSG_TYPE 53
|
||||
#define RFC2132_SRV_ID 54
|
||||
#define RFC2132_PARAM_LIST 55
|
||||
#define RFC2132_MAX_SIZE 57
|
||||
#define RFC2132_RENEWAL_TIME 58
|
||||
#define RFC2132_REBIND_TIME 59
|
||||
|
||||
#define DHCPDISCOVER 1
|
||||
#define DHCPOFFER 2
|
||||
#define DHCPREQUEST 3
|
||||
#define DHCPACK 5
|
||||
|
||||
#define RFC1533_VENDOR_MAJOR 0
|
||||
#define RFC1533_VENDOR_MINOR 0
|
||||
|
||||
#define RFC1533_VENDOR_MAGIC 128
|
||||
#define RFC1533_VENDOR_ADDPARM 129
|
||||
#define RFC1533_VENDOR_ETHDEV 130
|
||||
#define RFC1533_VENDOR_HOWTO 132
|
||||
#define RFC1533_VENDOR_MNUOPTS 160
|
||||
#define RFC1533_VENDOR_SELECTION 176
|
||||
#define RFC1533_VENDOR_MOTD 184
|
||||
#define RFC1533_VENDOR_NUMOFMOTD 8
|
||||
#define RFC1533_VENDOR_IMG 192
|
||||
#define RFC1533_VENDOR_NUMOFIMG 16
|
||||
|
||||
#define RFC1533_END 255
|
||||
#define BOOTP_VENDOR_LEN 64
|
||||
#define DHCP_OPT_LEN 312
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct bootp_t {
|
||||
struct ip ip;
|
||||
struct udphdr udp;
|
||||
uint8_t bp_op;
|
||||
uint8_t bp_htype;
|
||||
uint8_t bp_hlen;
|
||||
uint8_t bp_hops;
|
||||
uint32_t bp_xid;
|
||||
uint16_t bp_secs;
|
||||
uint16_t unused;
|
||||
struct in_addr bp_ciaddr;
|
||||
struct in_addr bp_yiaddr;
|
||||
struct in_addr bp_siaddr;
|
||||
struct in_addr bp_giaddr;
|
||||
uint8_t bp_hwaddr[16];
|
||||
uint8_t bp_sname[64];
|
||||
uint8_t bp_file[128];
|
||||
uint8_t bp_vend[DHCP_OPT_LEN];
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(PACK_END)
|
||||
#endif
|
||||
|
||||
void bootp_input(struct SLIRPmbuf *m);
|
||||
@@ -1,9 +0,0 @@
|
||||
/* Automatically generated by configure - do not modify */
|
||||
#define CONFIG_QEMU_SHAREDIR "/c/Program Files/Qemu"
|
||||
#define HOST_I386 1
|
||||
#define HOST_LONG_BITS 32
|
||||
#define CONFIG_WIN32 1
|
||||
#define CONFIG_GDBSTUB 1
|
||||
#define CONFIG_SLIRP 1
|
||||
#define QEMU_VERSION "0.9.0"
|
||||
#define CONFIG_UNAME_RELEASE ""
|
||||
@@ -1,9 +0,0 @@
|
||||
/* Automatically generated by configure - do not modify */
|
||||
#include "config-host.h"
|
||||
#define CONFIG_QEMU_PREFIX "/usr/gnemul/qemu-i386"
|
||||
#define TARGET_ARCH "i386"
|
||||
#define TARGET_I386 1
|
||||
#define USE_KQEMU 1
|
||||
#define CONFIG_SOFTMMU 1
|
||||
#define CONFIG_SDL 1
|
||||
#define HAVE_STRDUP 1
|
||||
@@ -1,7 +0,0 @@
|
||||
#define CTL_CMD 0
|
||||
#define CTL_EXEC 1
|
||||
#define CTL_ALIAS 2
|
||||
#define CTL_DNS 3
|
||||
|
||||
#define CTL_SPECIAL "10.0.2.0"
|
||||
#define CTL_LOCAL "10.0.2.15"
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995 Danny Gasparovski.
|
||||
*
|
||||
* Please read the file COPYRIGHT for the
|
||||
* terms and conditions of the copyright.
|
||||
*/
|
||||
|
||||
#define PRN_STDERR 1
|
||||
#define PRN_SPRINTF 2
|
||||
|
||||
extern FILE *dfd;
|
||||
extern FILE *lfd;
|
||||
extern int dostats;
|
||||
extern int slirp_debug;
|
||||
|
||||
#define DBG_CALL 0x1
|
||||
#define DBG_MISC 0x2
|
||||
#define DBG_ERROR 0x4
|
||||
#define DEBUG_DEFAULT DBG_CALL|DBG_MISC|DBG_ERROR
|
||||
|
||||
#ifdef SLIRP_DEBUG
|
||||
#define DEBUG_CALL(x) if (slirp_debug & DBG_CALL) { fprintf(dfd, "%s...\n", x); fflush(dfd); }
|
||||
#define DEBUG_ARG(x, y) if (slirp_debug & DBG_CALL) { fputc(' ', dfd); fprintf(dfd, x, y); fputc('\n', dfd); fflush(dfd); }
|
||||
#define DEBUG_ARGS(x) if (slirp_debug & DBG_CALL) { fprintf x ; fflush(dfd); }
|
||||
#define DEBUG_MISC(x) if (slirp_debug & DBG_MISC) { fprintf x ; fflush(dfd); }
|
||||
#define DEBUG_ERROR(x) if (slirp_debug & DBG_ERROR) {fprintf x ; fflush(dfd); }
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#define DEBUG_CALL(x)
|
||||
#define DEBUG_ARG(x, y)
|
||||
#define DEBUG_ARGS(x)
|
||||
#define DEBUG_MISC(x)
|
||||
#define DEBUG_ERROR(x)
|
||||
|
||||
#endif
|
||||
|
||||
void debug_init _P((char *, int));
|
||||
void allttystats _P((void));
|
||||
void ipstats _P((void));
|
||||
void vjstats _P((void));
|
||||
void tcpstats _P((void));
|
||||
void udpstats _P((void));
|
||||
void icmpstats _P((void));
|
||||
void mbufstats _P((void));
|
||||
void sockstats _P((void));
|
||||
void slirp_exit _P((int));
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)icmp_var.h 8.1 (Berkeley) 6/10/93
|
||||
* icmp_var.h,v 1.4 1995/02/16 00:27:40 wollman Exp
|
||||
*/
|
||||
|
||||
#ifndef _NETINET_ICMP_VAR_H_
|
||||
#define _NETINET_ICMP_VAR_H_
|
||||
|
||||
/*
|
||||
* Variables related to this implementation
|
||||
* of the internet control message protocol.
|
||||
*/
|
||||
struct icmpstat {
|
||||
/* statistics related to input messages processed */
|
||||
u_long icps_received; /* #ICMP packets received */
|
||||
u_long icps_tooshort; /* packet < ICMP_MINLEN */
|
||||
u_long icps_checksum; /* bad checksum */
|
||||
u_long icps_notsupp; /* #ICMP packets not supported */
|
||||
u_long icps_badtype; /* #with bad type feild */
|
||||
u_long icps_reflect; /* number of responses */
|
||||
};
|
||||
|
||||
/*
|
||||
* Names for ICMP sysctl objects
|
||||
*/
|
||||
#define ICMPCTL_MASKREPL 1 /* allow replies to netmask requests */
|
||||
#define ICMPCTL_STATS 2 /* statistics (read-only) */
|
||||
#define ICMPCTL_MAXID 3
|
||||
|
||||
#define ICMPCTL_NAMES { \
|
||||
{ 0, 0 }, \
|
||||
{ "maskrepl", CTLTYPE_INT }, \
|
||||
{ "stats", CTLTYPE_STRUCT }, \
|
||||
}
|
||||
|
||||
extern struct icmpstat icmpstat;
|
||||
|
||||
#endif
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995 Danny Gasparovski.
|
||||
*
|
||||
* Please read the file COPYRIGHT for the
|
||||
* terms and conditions of the copyright.
|
||||
*/
|
||||
|
||||
#ifndef _IF_H_
|
||||
#define _IF_H_
|
||||
|
||||
#define IF_COMPRESS 0x01 /* We want compression */
|
||||
#define IF_NOCOMPRESS 0x02 /* Do not do compression */
|
||||
#define IF_AUTOCOMP 0x04 /* Autodetect (default) */
|
||||
#define IF_NOCIDCOMP 0x08 /* CID compression */
|
||||
|
||||
/* Needed for FreeBSD */
|
||||
#undef if_mtu
|
||||
extern int if_mtu;
|
||||
extern int if_mru; /* MTU and MRU */
|
||||
extern int if_comp; /* Flags for compression */
|
||||
extern int if_maxlinkhdr;
|
||||
extern int if_queued; /* Number of packets queued so far */
|
||||
extern int if_thresh; /* Number of packets queued before we start sending
|
||||
* (to prevent allocing too many SLIRPmbufs) */
|
||||
|
||||
extern struct SLIRPmbuf if_fastq; /* fast queue (for interactive data) */
|
||||
extern struct SLIRPmbuf if_batchq; /* queue for non-interactive data */
|
||||
extern struct SLIRPmbuf *next_m;
|
||||
|
||||
#define ifs_init(ifm) ((ifm)->ifs_next = (ifm)->ifs_prev = (ifm))
|
||||
|
||||
/* Interface statistics */
|
||||
struct slirp_ifstats {
|
||||
u_int out_pkts; /* Output packets */
|
||||
u_int out_bytes; /* Output bytes */
|
||||
u_int out_errpkts; /* Output Error Packets */
|
||||
u_int out_errbytes; /* Output Error Bytes */
|
||||
u_int in_pkts; /* Input packets */
|
||||
u_int in_bytes; /* Input bytes */
|
||||
u_int in_errpkts; /* Input Error Packets */
|
||||
u_int in_errbytes; /* Input Error Bytes */
|
||||
|
||||
u_int bytes_saved; /* Number of bytes that compression "saved" */
|
||||
/* ie: number of bytes that didn't need to be sent over the link
|
||||
* because of compression */
|
||||
|
||||
u_int in_mbad; /* Bad incoming packets */
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,362 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)ip.h 8.1 (Berkeley) 6/10/93
|
||||
* ip.h,v 1.3 1994/08/21 05:27:30 paul Exp
|
||||
*/
|
||||
|
||||
#ifndef _IP_H_
|
||||
#define _IP_H_
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# ifndef NTOHL
|
||||
# define NTOHL(d)
|
||||
# endif
|
||||
# ifndef NTOHS
|
||||
# define NTOHS(d)
|
||||
# endif
|
||||
# ifndef HTONL
|
||||
# define HTONL(d)
|
||||
# endif
|
||||
# ifndef HTONS
|
||||
# define HTONS(d)
|
||||
# endif
|
||||
#else
|
||||
# ifndef NTOHL
|
||||
# define NTOHL(d) ((d) = ntohl((d)))
|
||||
# endif
|
||||
# ifndef NTOHS
|
||||
# define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
|
||||
# endif
|
||||
# ifndef HTONL
|
||||
# define HTONL(d) ((d) = htonl((d)))
|
||||
# endif
|
||||
# ifndef HTONS
|
||||
# define HTONS(d) ((d) = htons((u_int16_t)(d)))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef u_int32_t n_long; /* long as received from the net */
|
||||
|
||||
/*
|
||||
* Definitions for internet protocol version 4.
|
||||
* Per RFC 791, September 1981.
|
||||
*/
|
||||
#define IPVERSION 4
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(push, 1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Structure of an internet header, naked of options.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct ip {
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
u_char ip_v:4, /* version */
|
||||
ip_hl:4; /* header length */
|
||||
#else
|
||||
u_char ip_hl:4, /* header length */
|
||||
ip_v:4; /* version */
|
||||
#endif
|
||||
u_int8_t ip_tos; /* type of service */
|
||||
u_int16_t ip_len; /* total length */
|
||||
u_int16_t ip_id; /* identification */
|
||||
u_int16_t ip_off; /* fragment offset field */
|
||||
#define IP_DF 0x4000 /* don't fragment flag */
|
||||
#define IP_MF 0x2000 /* more fragments flag */
|
||||
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
||||
u_int8_t ip_ttl; /* time to live */
|
||||
u_int8_t ip_p; /* protocol */
|
||||
u_int16_t ip_sum; /* checksum */
|
||||
struct in_addr ip_src,ip_dst; /* source and dest address */
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(PACK_END) //WAS 0
|
||||
#endif
|
||||
|
||||
#define IP_MAXPACKET 65535 /* maximum packet size */
|
||||
|
||||
/*
|
||||
* Definitions for IP type of service (ip_tos)
|
||||
*/
|
||||
#define IPTOS_LOWDELAY 0x10
|
||||
#define IPTOS_THROUGHPUT 0x08
|
||||
#define IPTOS_RELIABILITY 0x04
|
||||
|
||||
/*
|
||||
* Definitions for options.
|
||||
*/
|
||||
#define IPOPT_COPIED(o) ((o)&0x80)
|
||||
#define IPOPT_CLASS(o) ((o)&0x60)
|
||||
#define IPOPT_NUMBER(o) ((o)&0x1f)
|
||||
|
||||
#define IPOPT_CONTROL 0x00
|
||||
#define IPOPT_RESERVED1 0x20
|
||||
#define IPOPT_DEBMEAS 0x40
|
||||
#define IPOPT_RESERVED2 0x60
|
||||
|
||||
#define IPOPT_EOL 0 /* end of option list */
|
||||
#define IPOPT_NOP 1 /* no operation */
|
||||
|
||||
#define IPOPT_RR 7 /* record packet route */
|
||||
#define IPOPT_TS 68 /* timestamp */
|
||||
#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
|
||||
#define IPOPT_LSRR 131 /* loose source route */
|
||||
#define IPOPT_SATID 136 /* satnet id */
|
||||
#define IPOPT_SSRR 137 /* strict source route */
|
||||
|
||||
/*
|
||||
* Offsets to fields in options other than EOL and NOP.
|
||||
*/
|
||||
#define IPOPT_OPTVAL 0 /* option ID */
|
||||
#define IPOPT_OLEN 1 /* option length */
|
||||
#define IPOPT_OFFSET 2 /* offset within option */
|
||||
#define IPOPT_MINOFF 4 /* min value of above */
|
||||
|
||||
/*
|
||||
* Time stamp option structure.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct ip_timestamp {
|
||||
u_int8_t ipt_code; /* IPOPT_TS */
|
||||
u_int8_t ipt_len; /* size of structure (variable) */
|
||||
u_int8_t ipt_ptr; /* index of current entry */
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
u_char ipt_oflw:4, /* overflow counter */
|
||||
ipt_flg:4; /* flags, see below */
|
||||
#else
|
||||
u_char ipt_flg:4, /* flags, see below */
|
||||
ipt_oflw:4; /* overflow counter */
|
||||
#endif
|
||||
union ipt_timestamp {
|
||||
n_long ipt_time[1];
|
||||
struct ipt_ta {
|
||||
struct in_addr ipt_addr;
|
||||
n_long ipt_time;
|
||||
} ipt_ta[1];
|
||||
} ipt_timestamp;
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(PACK_END)
|
||||
#endif
|
||||
|
||||
/* flag bits for ipt_flg */
|
||||
#define IPOPT_TS_TSONLY 0 /* timestamps only */
|
||||
#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
|
||||
#define IPOPT_TS_PRESPEC 3 /* specified modules only */
|
||||
|
||||
/* bits for security (not byte swapped) */
|
||||
#define IPOPT_SECUR_UNCLASS 0x0000
|
||||
#define IPOPT_SECUR_CONFID 0xf135
|
||||
#define IPOPT_SECUR_EFTO 0x789a
|
||||
#define IPOPT_SECUR_MMMM 0xbc4d
|
||||
#define IPOPT_SECUR_RESTR 0xaf13
|
||||
#define IPOPT_SECUR_SECRET 0xd788
|
||||
#define IPOPT_SECUR_TOPSECRET 0x6bc5
|
||||
|
||||
/*
|
||||
* Internet implementation parameters.
|
||||
*/
|
||||
#define MAXTTL 255 /* maximum time to live (seconds) */
|
||||
#define IPDEFTTL 64 /* default ttl, from RFC 1340 */
|
||||
#define IPFRAGTTL 60 /* time to live for frags, slowhz */
|
||||
#define IPTTLDEC 1 /* subtracted when forwarding */
|
||||
|
||||
#define IP_MSS 576 /* default maximum segment size */
|
||||
|
||||
#ifdef HAVE_SYS_TYPES32_H /* Overcome some Solaris 2.x junk */
|
||||
#include <sys/types32.h>
|
||||
#else
|
||||
#if SIZEOF_CHAR_P == 4
|
||||
typedef SLIRPcaddr_t caddr32_t;
|
||||
#else
|
||||
typedef u_int32_t caddr32_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__amd64__) || defined(__aarch64__)
|
||||
typedef uintptr_t ipqp_32;
|
||||
typedef uintptr_t ipasfragp_32;
|
||||
#else
|
||||
#if SIZEOF_CHAR_P == 4
|
||||
typedef struct ipq *ipqp_32;
|
||||
typedef struct ipasfrag *ipasfragp_32;
|
||||
#else
|
||||
typedef caddr32_t ipqp_32;
|
||||
typedef caddr32_t ipasfragp_32;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Overlay for ip header used by other protocols (tcp, udp).
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct ipovly {
|
||||
#if defined(__amd64__) || defined(__aarch64__)
|
||||
uintptr_t ih_next, ih_prev; /* for protocol sequence q's */
|
||||
#else
|
||||
caddr32_t ih_next, ih_prev; /* for protocol sequence q's */
|
||||
#endif
|
||||
u_int8_t ih_x1; /* (unused) */
|
||||
u_int8_t ih_pr; /* protocol */
|
||||
u_int16_t ih_len; /* protocol length */
|
||||
struct in_addr ih_src; /* source internet address */
|
||||
struct in_addr ih_dst; /* destination internet address */
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(PACK_END)
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Ip reassembly queue structure. Each fragment
|
||||
* being reassembled is attached to one of these structures.
|
||||
* They are timed out after ipq_ttl drops to 0, and may also
|
||||
* be reclaimed if memory becomes tight.
|
||||
* size 28 bytes
|
||||
*/
|
||||
struct ipq {
|
||||
#if defined(__amd64__) || defined(__aarch64__)
|
||||
uintptr_t next,prev; /* to other reass headers */
|
||||
#else
|
||||
ipqp_32 next,prev; /* to other reass headers */
|
||||
#endif
|
||||
u_int8_t ipq_ttl; /* time for reass q to live */
|
||||
u_int8_t ipq_p; /* protocol of this fragment */
|
||||
u_int16_t ipq_id; /* sequence id for reassembly */
|
||||
ipasfragp_32 ipq_next,ipq_prev;
|
||||
/* to ip headers of fragments */
|
||||
struct in_addr ipq_src,ipq_dst;
|
||||
};
|
||||
|
||||
/*
|
||||
* Ip header, when holding a fragment.
|
||||
*
|
||||
* Note: ipf_next must be at same offset as ipq_next above
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct ipasfrag {
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
u_char ip_v:4,
|
||||
ip_hl:4;
|
||||
#else
|
||||
u_char ip_hl:4,
|
||||
ip_v:4;
|
||||
#endif
|
||||
/* BUG : u_int changed to u_int8_t.
|
||||
* sizeof(u_int)==4 on linux 2.0
|
||||
*/
|
||||
u_int8_t ipf_mff; /* XXX overlays ip_tos: use low bit
|
||||
* to avoid destroying tos (PPPDTRuu);
|
||||
* copied from (ip_off&IP_MF) */
|
||||
u_int16_t ip_len;
|
||||
u_int16_t ip_id;
|
||||
u_int16_t ip_off;
|
||||
u_int8_t ip_ttl;
|
||||
u_int8_t ip_p;
|
||||
u_int16_t ip_sum;
|
||||
ipasfragp_32 ipf_next; /* next fragment */
|
||||
ipasfragp_32 ipf_prev; /* previous fragment */
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(PACK_END) //WAS 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Structure stored in mbuf in inpcb.ip_options
|
||||
* and passed to ip_output when ip options are in use.
|
||||
* The actual length of the options (including ipopt_dst)
|
||||
* is in m_len.
|
||||
*/
|
||||
#define MAX_IPOPTLEN 40
|
||||
|
||||
struct ipoption {
|
||||
struct in_addr ipopt_dst; /* first-hop dst if source routed */
|
||||
int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure attached to inpcb.ip_moptions and
|
||||
* passed to ip_output when IP multicast options are in use.
|
||||
*/
|
||||
|
||||
struct ipstat {
|
||||
u_long ips_total; /* total packets received */
|
||||
u_long ips_badsum; /* checksum bad */
|
||||
u_long ips_tooshort; /* packet too short */
|
||||
u_long ips_toosmall; /* not enough data */
|
||||
u_long ips_badhlen; /* ip header length < data size */
|
||||
u_long ips_badlen; /* ip length < ip header length */
|
||||
u_long ips_fragments; /* fragments received */
|
||||
u_long ips_fragdropped; /* frags dropped (dups, out of space) */
|
||||
u_long ips_fragtimeout; /* fragments timed out */
|
||||
u_long ips_forward; /* packets forwarded */
|
||||
u_long ips_cantforward; /* packets rcvd for unreachable dest */
|
||||
u_long ips_redirectsent; /* packets forwarded on same net */
|
||||
u_long ips_noproto; /* unknown or unsupported protocol */
|
||||
u_long ips_delivered; /* datagrams delivered to upper level*/
|
||||
u_long ips_localout; /* total ip packets generated here */
|
||||
u_long ips_odropped; /* lost packets due to nobufs, etc. */
|
||||
u_long ips_reassembled; /* total packets reassembled ok */
|
||||
u_long ips_fragmented; /* datagrams successfully fragmented */
|
||||
u_long ips_ofragments; /* output fragments created */
|
||||
u_long ips_cantfrag; /* don't fragment flag was set, etc. */
|
||||
u_long ips_badoptions; /* error in option processing */
|
||||
u_long ips_noroute; /* packets discarded due to no route */
|
||||
u_long ips_badvers; /* ip version != 4 */
|
||||
u_long ips_rawout; /* total raw ip packets generated */
|
||||
u_long ips_unaligned; /* times the ip packet was not aligned */
|
||||
};
|
||||
|
||||
extern struct ipstat ipstat;
|
||||
extern struct ipq ipq; /* ip reass. queue */
|
||||
extern u_int16_t ip_id; /* ip packet ctr, for ids */
|
||||
extern int ip_defttl; /* default IP ttl */
|
||||
|
||||
#endif
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93
|
||||
* ip_icmp.h,v 1.4 1995/05/30 08:09:43 rgrimes Exp
|
||||
*/
|
||||
|
||||
#ifndef _NETINET_IP_ICMP_H_
|
||||
#define _NETINET_IP_ICMP_H_
|
||||
|
||||
/*
|
||||
* Interface Control Message Protocol Definitions.
|
||||
* Per RFC 792, September 1981.
|
||||
*/
|
||||
|
||||
typedef u_int32_t n_time;
|
||||
|
||||
/*
|
||||
* Structure of an icmp header.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct icmp {
|
||||
u_char icmp_type; /* type of message, see below */
|
||||
u_char icmp_code; /* type sub code */
|
||||
u_short icmp_cksum; /* ones complement cksum of struct */
|
||||
union {
|
||||
u_char ih_pptr; /* ICMP_PARAMPROB */
|
||||
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
|
||||
struct ih_idseq {
|
||||
u_short icd_id;
|
||||
u_short icd_seq;
|
||||
} ih_idseq;
|
||||
int ih_void;
|
||||
|
||||
/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
|
||||
struct ih_pmtu {
|
||||
u_short ipm_void;
|
||||
u_short ipm_nextmtu;
|
||||
} ih_pmtu;
|
||||
} icmp_hun;
|
||||
#define icmp_pptr icmp_hun.ih_pptr
|
||||
#define icmp_gwaddr icmp_hun.ih_gwaddr
|
||||
#define icmp_id icmp_hun.ih_idseq.icd_id
|
||||
#define icmp_seq icmp_hun.ih_idseq.icd_seq
|
||||
#define icmp_void icmp_hun.ih_void
|
||||
#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
|
||||
#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
|
||||
union {
|
||||
struct id_ts {
|
||||
n_time its_otime;
|
||||
n_time its_rtime;
|
||||
n_time its_ttime;
|
||||
} id_ts;
|
||||
struct id_ip {
|
||||
struct ip idi_ip;
|
||||
/* options and then 64 bits of data */
|
||||
} id_ip;
|
||||
uint32_t id_mask;
|
||||
char id_data[1];
|
||||
} icmp_dun;
|
||||
#define icmp_otime icmp_dun.id_ts.its_otime
|
||||
#define icmp_rtime icmp_dun.id_ts.its_rtime
|
||||
#define icmp_ttime icmp_dun.id_ts.its_ttime
|
||||
#define icmp_ip icmp_dun.id_ip.idi_ip
|
||||
#define icmp_mask icmp_dun.id_mask
|
||||
#define icmp_data icmp_dun.id_data
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Lower bounds on packet lengths for various types.
|
||||
* For the error advice packets must first insure that the
|
||||
* packet is large enought to contain the returned ip header.
|
||||
* Only then can we do the check to see if 64 bits of packet
|
||||
* data have been returned, since we need to check the returned
|
||||
* ip header length.
|
||||
*/
|
||||
#define ICMP_MINLEN 8 /* abs minimum */
|
||||
#define ICMP_TSLEN (8 + 3 * sizeof (n_time)) /* timestamp */
|
||||
#define ICMP_MASKLEN 12 /* address mask */
|
||||
#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */
|
||||
#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
|
||||
/* N.B.: must separately check that ip_hl >= 5 */
|
||||
|
||||
/*
|
||||
* Definition of type and code field values.
|
||||
*/
|
||||
#define ICMP_ECHOREPLY 0 /* echo reply */
|
||||
#define ICMP_UNREACH 3 /* dest unreachable, codes: */
|
||||
#define ICMP_UNREACH_NET 0 /* bad net */
|
||||
#define ICMP_UNREACH_HOST 1 /* bad host */
|
||||
#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */
|
||||
#define ICMP_UNREACH_PORT 3 /* bad port */
|
||||
#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */
|
||||
#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */
|
||||
#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */
|
||||
#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */
|
||||
#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */
|
||||
#define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */
|
||||
#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */
|
||||
#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */
|
||||
#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */
|
||||
#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */
|
||||
#define ICMP_REDIRECT 5 /* shorter route, codes: */
|
||||
#define ICMP_REDIRECT_NET 0 /* for network */
|
||||
#define ICMP_REDIRECT_HOST 1 /* for host */
|
||||
#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */
|
||||
#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */
|
||||
#define ICMP_ECHO 8 /* echo service */
|
||||
#define ICMP_ROUTERADVERT 9 /* router advertisement */
|
||||
#define ICMP_ROUTERSOLICIT 10 /* router solicitation */
|
||||
#define ICMP_TIMXCEED 11 /* time exceeded, code: */
|
||||
#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */
|
||||
#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */
|
||||
#define ICMP_PARAMPROB 12 /* ip header bad */
|
||||
#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */
|
||||
#define ICMP_TSTAMP 13 /* timestamp request */
|
||||
#define ICMP_TSTAMPREPLY 14 /* timestamp reply */
|
||||
#define ICMP_IREQ 15 /* information request */
|
||||
#define ICMP_IREQREPLY 16 /* information reply */
|
||||
#define ICMP_MASKREQ 17 /* address mask request */
|
||||
#define ICMP_MASKREPLY 18 /* address mask reply */
|
||||
|
||||
#define ICMP_MAXTYPE 18
|
||||
|
||||
#define ICMP_INFOTYPE(type) \
|
||||
((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
|
||||
(type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
|
||||
(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
|
||||
(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
|
||||
(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
|
||||
|
||||
void icmp_input _P((struct SLIRPmbuf *, int));
|
||||
void icmp_error _P((struct SLIRPmbuf *, u_char, u_char, int, char *));
|
||||
void icmp_reflect _P((struct SLIRPmbuf *));
|
||||
|
||||
#endif
|
||||
24
src/include/slirp/libslirp-version.h
Normal file
24
src/include/slirp/libslirp-version.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
#ifndef LIBSLIRP_VERSION_H_
|
||||
#define LIBSLIRP_VERSION_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SLIRP_MAJOR_VERSION 4
|
||||
#define SLIRP_MINOR_VERSION 3
|
||||
#define SLIRP_MICRO_VERSION 1
|
||||
#define SLIRP_VERSION_STRING "4.3.1-git-86Box"
|
||||
|
||||
#define SLIRP_CHECK_VERSION(major,minor,micro) \
|
||||
(SLIRP_MAJOR_VERSION > (major) || \
|
||||
(SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION > (minor)) || \
|
||||
(SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION == (minor) && \
|
||||
SLIRP_MICRO_VERSION >= (micro)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* LIBSLIRP_VERSION_H_ */
|
||||
@@ -1,41 +1,175 @@
|
||||
#ifndef _LIBSLIRP_H
|
||||
#define _LIBSLIRP_H
|
||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
#ifndef LIBSLIRP_H
|
||||
#define LIBSLIRP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
int inet_aton(const char *cp, struct in_addr *ia);
|
||||
#include <in6addr.h>
|
||||
#else
|
||||
#include <sys/select.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "libslirp-version.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int slirp_init(void);
|
||||
typedef struct Slirp Slirp;
|
||||
|
||||
int slirp_select_fill(int *pnfds,
|
||||
fd_set *readfds, fd_set *writefds, fd_set *xfds);
|
||||
enum {
|
||||
SLIRP_POLL_IN = 1 << 0,
|
||||
SLIRP_POLL_OUT = 1 << 1,
|
||||
SLIRP_POLL_PRI = 1 << 2,
|
||||
SLIRP_POLL_ERR = 1 << 3,
|
||||
SLIRP_POLL_HUP = 1 << 4,
|
||||
};
|
||||
|
||||
void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds);
|
||||
typedef ssize_t (*SlirpReadCb)(void *buf, size_t len, void *opaque);
|
||||
typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque);
|
||||
typedef void (*SlirpTimerCb)(void *opaque);
|
||||
typedef int (*SlirpAddPollCb)(int fd, int events, void *opaque);
|
||||
typedef int (*SlirpGetREventsCb)(int idx, void *opaque);
|
||||
|
||||
void slirp_input(const uint8 *pkt, int pkt_len);
|
||||
/*
|
||||
* Callbacks from slirp
|
||||
*/
|
||||
typedef struct SlirpCb {
|
||||
/*
|
||||
* Send an ethernet frame to the guest network. The opaque
|
||||
* parameter is the one given to slirp_init(). The function
|
||||
* doesn't need to send all the data and may return <len (no
|
||||
* buffering is done on libslirp side, so the data will be dropped
|
||||
* in this case). <0 reports an IO error.
|
||||
*/
|
||||
SlirpWriteCb send_packet;
|
||||
/* Print a message for an error due to guest misbehavior. */
|
||||
void (*guest_error)(const char *msg, void *opaque);
|
||||
/* Return the virtual clock value in nanoseconds */
|
||||
int64_t (*clock_get_ns)(void *opaque);
|
||||
/* Create a new timer with the given callback and opaque data */
|
||||
void *(*timer_new)(SlirpTimerCb cb, void *cb_opaque, void *opaque);
|
||||
/* Remove and free a timer */
|
||||
void (*timer_free)(void *timer, void *opaque);
|
||||
/* Modify a timer to expire at @expire_time */
|
||||
void (*timer_mod)(void *timer, int64_t expire_time, void *opaque);
|
||||
/* Register a fd for future polling */
|
||||
void (*register_poll_fd)(int fd, void *opaque);
|
||||
/* Unregister a fd */
|
||||
void (*unregister_poll_fd)(int fd, void *opaque);
|
||||
/* Kick the io-thread, to signal that new events may be processed */
|
||||
void (*notify)(void *opaque);
|
||||
} SlirpCb;
|
||||
|
||||
/* you must provide the following functions: */
|
||||
int slirp_can_output(void);
|
||||
void slirp_output(const uint8 *pkt, int pkt_len);
|
||||
#define SLIRP_CONFIG_VERSION_MIN 1
|
||||
#define SLIRP_CONFIG_VERSION_MAX 3
|
||||
|
||||
int slirp_redir(int is_udp, int host_port,
|
||||
struct in_addr guest_addr, int guest_port);
|
||||
int slirp_add_exec(int do_pty, const char *args, int addr_low_byte,
|
||||
int guest_port);
|
||||
typedef struct SlirpConfig {
|
||||
/* Version must be provided */
|
||||
uint32_t version;
|
||||
/*
|
||||
* Fields introduced in SlirpConfig version 1 begin
|
||||
*/
|
||||
int restricted;
|
||||
bool in_enabled;
|
||||
struct in_addr vnetwork;
|
||||
struct in_addr vnetmask;
|
||||
struct in_addr vhost;
|
||||
bool in6_enabled;
|
||||
struct in6_addr vprefix_addr6;
|
||||
uint8_t vprefix_len;
|
||||
struct in6_addr vhost6;
|
||||
const char *vhostname;
|
||||
const char *tftp_server_name;
|
||||
const char *tftp_path;
|
||||
const char *bootfile;
|
||||
struct in_addr vdhcp_start;
|
||||
struct in_addr vnameserver;
|
||||
struct in6_addr vnameserver6;
|
||||
const char **vdnssearch;
|
||||
const char *vdomainname;
|
||||
/* Default: IF_MTU_DEFAULT */
|
||||
size_t if_mtu;
|
||||
/* Default: IF_MRU_DEFAULT */
|
||||
size_t if_mru;
|
||||
/* Prohibit connecting to 127.0.0.1:* */
|
||||
bool disable_host_loopback;
|
||||
/*
|
||||
* Enable emulation code (*warning*: this code isn't safe, it is not
|
||||
* recommended to enable it)
|
||||
*/
|
||||
bool enable_emu;
|
||||
/*
|
||||
* Fields introduced in SlirpConfig version 2 begin
|
||||
*/
|
||||
struct sockaddr_in *outbound_addr;
|
||||
struct sockaddr_in6 *outbound_addr6;
|
||||
/*
|
||||
* Fields introduced in SlirpConfig version 3 begin
|
||||
*/
|
||||
bool disable_dns; /* slirp will not redirect/serve any DNS packet */
|
||||
} SlirpConfig;
|
||||
|
||||
extern const char *tftp_prefix;
|
||||
extern char slirp_hostname[33];
|
||||
Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks,
|
||||
void *opaque);
|
||||
/* slirp_init is deprecated in favor of slirp_new */
|
||||
Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
|
||||
struct in_addr vnetmask, struct in_addr vhost,
|
||||
bool in6_enabled, struct in6_addr vprefix_addr6,
|
||||
uint8_t vprefix_len, struct in6_addr vhost6,
|
||||
const char *vhostname, const char *tftp_server_name,
|
||||
const char *tftp_path, const char *bootfile,
|
||||
struct in_addr vdhcp_start, struct in_addr vnameserver,
|
||||
struct in6_addr vnameserver6, const char **vdnssearch,
|
||||
const char *vdomainname, const SlirpCb *callbacks,
|
||||
void *opaque);
|
||||
void slirp_cleanup(Slirp *slirp);
|
||||
|
||||
void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout,
|
||||
SlirpAddPollCb add_poll, void *opaque);
|
||||
|
||||
void slirp_pollfds_poll(Slirp *slirp, int select_error,
|
||||
SlirpGetREventsCb get_revents, void *opaque);
|
||||
|
||||
void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
|
||||
|
||||
int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
|
||||
int host_port, struct in_addr guest_addr, int guest_port);
|
||||
int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
|
||||
int host_port);
|
||||
int slirp_add_exec(Slirp *slirp, const char *cmdline,
|
||||
struct in_addr *guest_addr, int guest_port);
|
||||
int slirp_add_unix(Slirp *slirp, const char *unixsock,
|
||||
struct in_addr *guest_addr, int guest_port);
|
||||
int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque,
|
||||
struct in_addr *guest_addr, int guest_port);
|
||||
/* remove entries added by slirp_add_exec, slirp_add_unix or slirp_add_guestfwd */
|
||||
int slirp_remove_guestfwd(Slirp *slirp, struct in_addr guest_addr,
|
||||
int guest_port);
|
||||
|
||||
char *slirp_connection_info(Slirp *slirp);
|
||||
|
||||
void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port,
|
||||
const uint8_t *buf, int size);
|
||||
size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr,
|
||||
int guest_port);
|
||||
|
||||
void slirp_state_save(Slirp *s, SlirpWriteCb write_cb, void *opaque);
|
||||
|
||||
int slirp_state_load(Slirp *s, int version_id, SlirpReadCb read_cb,
|
||||
void *opaque);
|
||||
|
||||
int slirp_state_version(void);
|
||||
|
||||
const char *slirp_version_string(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* LIBSLIRP_H */
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995 Danny Gasparovski.
|
||||
*
|
||||
* Please read the file COPYRIGHT for the
|
||||
* terms and conditions of the copyright.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#define TOWRITEMAX 512
|
||||
|
||||
extern struct timeval tt;
|
||||
extern int link_up;
|
||||
extern int slirp_socket;
|
||||
extern int slirp_socket_unit;
|
||||
extern int slirp_socket_port;
|
||||
extern u_int32_t slirp_socket_addr;
|
||||
extern char *slirp_socket_passwd;
|
||||
extern int ctty_closed;
|
||||
|
||||
/*
|
||||
* Get the difference in 2 times from updtim()
|
||||
* Allow for wraparound times, "just in case"
|
||||
* x is the greater of the 2 (current time) and y is
|
||||
* what it's being compared against.
|
||||
*/
|
||||
#define TIME_DIFF(x,y) (x)-(y) < 0 ? ~0-(y)+(x) : (x)-(y)
|
||||
|
||||
extern char *slirp_tty;
|
||||
extern char *exec_shell;
|
||||
extern u_int curtime;
|
||||
extern fd_set *global_readfds, *global_writefds, *global_xfds;
|
||||
extern struct in_addr ctl_addr;
|
||||
extern struct in_addr special_addr;
|
||||
extern struct in_addr alias_addr;
|
||||
extern struct in_addr our_addr;
|
||||
extern struct in_addr loopback_addr;
|
||||
extern struct in_addr dns_addr;
|
||||
extern char *username;
|
||||
extern char *socket_path;
|
||||
extern int towrite_max;
|
||||
extern int ppp_exit;
|
||||
extern int so_options;
|
||||
extern int tcp_keepintvl;
|
||||
extern uint8_t client_ethaddr[6];
|
||||
|
||||
#define PROTO_SLIP 0x1
|
||||
#ifdef USE_PPP
|
||||
#define PROTO_PPP 0x2
|
||||
#endif
|
||||
|
||||
void if_encap(const uint8_t *ip_data, int ip_data_len);
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)mbuf.h 8.3 (Berkeley) 1/21/94
|
||||
* mbuf.h,v 1.9 1994/11/14 13:54:20 bde Exp
|
||||
*/
|
||||
|
||||
#ifndef _MBUF_H_
|
||||
#define _MBUF_H_
|
||||
|
||||
#define m_freem m_free
|
||||
|
||||
|
||||
#define MINCSIZE 4096 /* Amount to increase mbuf if too small */
|
||||
|
||||
/*
|
||||
* Macros for type conversion
|
||||
* mtod(m,t) - convert mbuf pointer to data pointer of correct type
|
||||
* dtom(x) - convert data pointer within mbuf to mbuf pointer (XXX)
|
||||
*/
|
||||
#define mtod(m,t) ((t)(m)->m_data)
|
||||
/* #define dtom(x) ((struct SLIRPmbuf *)((int)(x) & ~(M_SIZE-1))) */
|
||||
|
||||
/* XXX About mbufs for slirp:
|
||||
* Only one mbuf is ever used in a chain, for each "cell" of data.
|
||||
* m_nextpkt points to the next packet, if fragmented.
|
||||
* If the data is too large, the M_EXT is used, and a larger block
|
||||
* is alloced. Therefore, m_free[m] must check for M_EXT and if set
|
||||
* free the m_ext. This is inefficient memory-wise, but who cares.
|
||||
*/
|
||||
|
||||
/* XXX should union some of these! */
|
||||
/* header at beginning of each mbuf: */
|
||||
struct m_hdr {
|
||||
struct SLIRPmbuf *mh_next; /* Linked list of mbufs */
|
||||
struct SLIRPmbuf *mh_prev;
|
||||
struct SLIRPmbuf *mh_nextpkt; /* Next packet in queue/record */
|
||||
struct SLIRPmbuf *mh_prevpkt; /* Flags aren't used in the output queue */
|
||||
int mh_flags; /* Misc flags */
|
||||
|
||||
size_t mh_size; /* Size of data */
|
||||
struct SLIRPsocket *mh_so;
|
||||
|
||||
SLIRPcaddr_t mh_data; /* Location of data */
|
||||
int32_t mh_len; /* Amount of data in this mbuf */
|
||||
};
|
||||
|
||||
/*
|
||||
* How much room is in the mbuf, from m_data to the end of the mbuf
|
||||
*/
|
||||
#define M_ROOM(m) ((m->m_flags & M_EXT)? \
|
||||
(((m)->m_ext + (m)->m_size) - (m)->m_data) \
|
||||
: \
|
||||
(((m)->m_dat + (m)->m_size) - (m)->m_data))
|
||||
|
||||
/*
|
||||
* How much free room there is
|
||||
*/
|
||||
#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len)
|
||||
#define M_TRAILINGSPACE M_FREEROOM
|
||||
|
||||
struct SLIRPmbuf {
|
||||
struct m_hdr m_hdr;
|
||||
union M_dat {
|
||||
char m_dat_[1]; /* ANSI don't like 0 sized arrays */
|
||||
char *m_ext_;
|
||||
} M_dat;
|
||||
};
|
||||
|
||||
#define m_next m_hdr.mh_next
|
||||
#define m_prev m_hdr.mh_prev
|
||||
#define m_nextpkt m_hdr.mh_nextpkt
|
||||
#define m_prevpkt m_hdr.mh_prevpkt
|
||||
#define m_flags m_hdr.mh_flags
|
||||
#define m_len m_hdr.mh_len
|
||||
#define m_data m_hdr.mh_data
|
||||
#define m_size m_hdr.mh_size
|
||||
#define m_dat M_dat.m_dat_
|
||||
#define m_ext M_dat.m_ext_
|
||||
#define m_so m_hdr.mh_so
|
||||
|
||||
#define ifq_prev m_prev
|
||||
#define ifq_next m_next
|
||||
#define ifs_prev m_prevpkt
|
||||
#define ifs_next m_nextpkt
|
||||
#define ifq_so m_so
|
||||
|
||||
#define M_EXT 0x01 /* m_ext points to more (malloced) data */
|
||||
#define M_FREELIST 0x02 /* mbuf is on free list */
|
||||
#define M_USEDLIST 0x04 /* XXX mbuf is on used list (for dtom()) */
|
||||
#define M_DOFREE 0x08 /* when m_free is called on the mbuf, free()
|
||||
* it rather than putting it on the free list */
|
||||
|
||||
/*
|
||||
* Mbuf statistics. XXX
|
||||
*/
|
||||
|
||||
struct mbstat {
|
||||
int mbs_alloced; /* Number of mbufs allocated */
|
||||
|
||||
};
|
||||
|
||||
extern struct mbstat mbstat;
|
||||
extern int mbuf_alloced;
|
||||
extern struct SLIRPmbuf m_freelist, m_usedlist;
|
||||
extern int mbuf_max;
|
||||
|
||||
void m_init _P((void));
|
||||
void msize_init _P((void));
|
||||
struct SLIRPmbuf * m_get _P((void));
|
||||
void m_free _P((struct SLIRPmbuf *));
|
||||
void m_cat _P((register struct SLIRPmbuf *, register struct SLIRPmbuf *));
|
||||
void m_inc _P((struct SLIRPmbuf *, int));
|
||||
void m_adj _P((struct SLIRPmbuf *, int));
|
||||
int m_copy _P((struct SLIRPmbuf *, struct SLIRPmbuf *, int, int));
|
||||
struct SLIRPmbuf * dtom _P((void *));
|
||||
|
||||
#endif
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995 Danny Gasparovski.
|
||||
*
|
||||
* Please read the file COPYRIGHT for the
|
||||
* terms and conditions of the copyright.
|
||||
*/
|
||||
|
||||
#ifndef _MISC_H_
|
||||
#define _MISC_H_
|
||||
|
||||
struct ex_list {
|
||||
int ex_pty; /* Do we want a pty? */
|
||||
int ex_addr; /* The last byte of the address */
|
||||
int ex_fport; /* Port to telnet to */
|
||||
char *ex_exec; /* Command line of what to exec */
|
||||
struct ex_list *ex_next;
|
||||
};
|
||||
|
||||
extern struct ex_list *exec_list;
|
||||
extern u_int curtime, time_fasttimo, last_slowtimo, detach_time, detach_wait;
|
||||
|
||||
extern int (*lprint_print) _P((void *, const char *, va_list));
|
||||
extern char *lprint_ptr, *lprint_ptr2, **lprint_arg;
|
||||
extern struct sbuf *lprint_sb;
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
char *strdup _P((const char *));
|
||||
#endif
|
||||
|
||||
void do_wait _P((int));
|
||||
|
||||
#define EMU_NONE 0x0
|
||||
|
||||
/* TCP emulations */
|
||||
#define EMU_CTL 0x1
|
||||
#define EMU_FTP 0x2
|
||||
#define EMU_KSH 0x3
|
||||
#define EMU_IRC 0x4
|
||||
#define EMU_REALAUDIO 0x5
|
||||
#define EMU_RLOGIN 0x6
|
||||
#define EMU_IDENT 0x7
|
||||
#define EMU_RSH 0x8
|
||||
|
||||
#define EMU_NOCONNECT 0x10 /* Don't connect */
|
||||
|
||||
/* UDP emulations */
|
||||
#define EMU_TALK 0x1
|
||||
#define EMU_NTALK 0x2
|
||||
#define EMU_CUSEEME 0x3
|
||||
|
||||
struct tos_t {
|
||||
u_int16_t lport;
|
||||
u_int16_t fport;
|
||||
u_int8_t tos;
|
||||
u_int8_t emu;
|
||||
};
|
||||
|
||||
struct emu_t {
|
||||
u_int16_t lport;
|
||||
u_int16_t fport;
|
||||
u_int8_t tos;
|
||||
u_int8_t emu;
|
||||
struct emu_t *next;
|
||||
};
|
||||
|
||||
extern struct emu_t *tcpemu;
|
||||
|
||||
extern int x_port, x_server, x_display;
|
||||
|
||||
int show_x _P((char *, struct SLIRPsocket *));
|
||||
void redir_x _P((u_int32_t, int, int, int));
|
||||
void getouraddr _P((void));
|
||||
void slirp_insque _P((void *, void *));
|
||||
void slirp_remque _P((void *));
|
||||
int add_exec _P((struct ex_list **, int, char *, int, int));
|
||||
int slirp_openpty _P((int *, int *));
|
||||
int fork_exec _P((struct SLIRPsocket *, char *, int));
|
||||
void snooze_hup _P((int));
|
||||
void snooze _P((void));
|
||||
void relay _P((int));
|
||||
void add_emu _P((char *));
|
||||
void u_sleep _P((int));
|
||||
void fd_nonblock _P((int));
|
||||
void fd_block _P((int));
|
||||
int rsh_exec _P((struct SLIRPsocket *, struct SLIRPsocket *, char *, char *, char *));
|
||||
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* File: queue.h
|
||||
* Author: Robert I. Pitts <rip@cs.bu.edu>
|
||||
* Last Modified: March 9, 2000
|
||||
* Topic: Queue - Array Implementation
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _QUEUE_H
|
||||
#define _QUEUE_H
|
||||
|
||||
/*
|
||||
* Constants
|
||||
* ---------
|
||||
* ERROR_* These signal error conditions in queue functions
|
||||
* and are used as exit codes for the program.
|
||||
*/
|
||||
#define ERROR_QUEUE 2
|
||||
#define ERROR_MEMORY 3
|
||||
|
||||
/*
|
||||
* Type: queueElementT
|
||||
* -------------------
|
||||
* This is the type of objects held in the queue.
|
||||
*/
|
||||
|
||||
/*typedef char queueElementT;
|
||||
typedef unsigned char *queueElementT;
|
||||
*/
|
||||
|
||||
struct queuepacket{
|
||||
int len;
|
||||
unsigned char data[2000];
|
||||
};
|
||||
typedef struct queuepacket *queueElementT;
|
||||
|
||||
/*
|
||||
* Type: queueADT
|
||||
* --------------
|
||||
* The actual implementation of a queue is completely
|
||||
* hidden. Client will work with queueADT which is a
|
||||
* pointer to underlying queueCDT.
|
||||
*/
|
||||
|
||||
/*
|
||||
* NOTE: need word struct below so that the compiler
|
||||
* knows at least that a queueCDT will be some sort
|
||||
* of struct.
|
||||
*/
|
||||
|
||||
typedef struct queueCDT *queueADT;
|
||||
|
||||
/*
|
||||
* Function: QueueCreate
|
||||
* Usage: queue = QueueCreate();
|
||||
* -------------------------
|
||||
* A new empty queue is created and returned.
|
||||
*/
|
||||
|
||||
queueADT QueueCreate(void);
|
||||
|
||||
/* Function: QueueDestroy
|
||||
* Usage: QueueDestroy(queue);
|
||||
* -----------------------
|
||||
* This function frees all memory associated with
|
||||
* the queue. "queue" may not be used again unless
|
||||
* queue = QueueCreate() is called first.
|
||||
*/
|
||||
|
||||
void QueueDestroy(queueADT queue);
|
||||
|
||||
/*
|
||||
* Functions: QueueEnter, QueueDelete
|
||||
* Usage: QueueEnter(queue, element);
|
||||
* element = QueueDelete(queue);
|
||||
* --------------------------------------------
|
||||
* These are the fundamental queue operations that enter
|
||||
* elements in and delete elements from the queue. A call
|
||||
* to QueueDelete() on an empty queue or to QueueEnter()
|
||||
* on a full queue is an error. Make use of QueueIsFull()
|
||||
* and QueueIsEmpty() (see below) to avoid these errors.
|
||||
*/
|
||||
|
||||
void QueueEnter(queueADT queue, queueElementT element);
|
||||
queueElementT QueueDelete(queueADT queue);
|
||||
|
||||
|
||||
/*
|
||||
* Functions: QueueIsEmpty, QueueIsFull
|
||||
* Usage: if (QueueIsEmpty(queue)) ...
|
||||
* -----------------------------------
|
||||
* These return a true/false value based on whether
|
||||
* the queue is empty or full, respectively.
|
||||
*/
|
||||
|
||||
int QueueIsEmpty(queueADT queue);
|
||||
int QueueIsFull(queueADT queue);
|
||||
|
||||
int QueuePeek(queueADT queue);
|
||||
|
||||
#endif /* not defined _QUEUE_H */
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995 Danny Gasparovski.
|
||||
*
|
||||
* Please read the file COPYRIGHT for the
|
||||
* terms and conditions of the copyright.
|
||||
*/
|
||||
|
||||
#ifndef _SBUF_H_
|
||||
#define _SBUF_H_
|
||||
|
||||
#define sbflush(sb) sbdrop((sb),(sb)->sb_cc)
|
||||
#define sbspace(sb) ((sb)->sb_datalen - (sb)->sb_cc)
|
||||
|
||||
struct sbuf {
|
||||
u_int sb_cc; /* actual chars in buffer */
|
||||
u_int sb_datalen; /* Length of data */
|
||||
char *sb_wptr; /* write pointer. points to where the next
|
||||
* bytes should be written in the sbuf */
|
||||
char *sb_rptr; /* read pointer. points to where the next
|
||||
* byte should be read from the sbuf */
|
||||
char *sb_data; /* Actual data */
|
||||
};
|
||||
|
||||
void sbfree _P((struct sbuf *));
|
||||
void sbdrop _P((struct sbuf *, int));
|
||||
void sbreserve _P((struct sbuf *, int));
|
||||
void sbappend _P((struct SLIRPsocket *, struct SLIRPmbuf *));
|
||||
void sbappendsb _P((struct sbuf *, struct SLIRPmbuf *));
|
||||
void sbcopy _P((struct sbuf *, int, int, char *));
|
||||
|
||||
#endif
|
||||
@@ -1,441 +0,0 @@
|
||||
#ifndef __COMMON_H__
|
||||
#define __COMMON_H__
|
||||
|
||||
#define SLIRP_VERSION "Cockatrice special"
|
||||
|
||||
#define CONFIG_QEMU
|
||||
|
||||
#ifndef CONFIG_QEMU
|
||||
#include "version.h"
|
||||
#endif
|
||||
#include "config.h"
|
||||
#include "slirp_config.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef __GNUC__ /* MINGW? */
|
||||
# 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 *SLIRPcaddr_t;
|
||||
typedef int socklen_t;
|
||||
typedef unsigned long ioctlsockopt_t;
|
||||
#else
|
||||
typedef unsigned char u_int8_t;
|
||||
typedef char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short u_int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned int u_int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
typedef unsigned __int64 u_int64_t;
|
||||
typedef char *SLIRPcaddr_t;
|
||||
typedef int socklen_t;
|
||||
typedef unsigned long ioctlsockopt_t;
|
||||
|
||||
#endif
|
||||
|
||||
# include <winsock2.h> /* needs to be on top otherwise, it'll pull in winsock1 */
|
||||
# include <windows.h>
|
||||
|
||||
# include <sys/timeb.h>
|
||||
# include <iphlpapi.h>
|
||||
|
||||
# define USE_FIONBIO 1
|
||||
#ifndef EWOULDBLOCK
|
||||
# define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#endif
|
||||
#ifndef EINPROGRESS
|
||||
# define EINPROGRESS WSAEINPROGRESS
|
||||
#endif
|
||||
#ifndef ENOTCONN
|
||||
# define ENOTCONN WSAENOTCONN
|
||||
#endif
|
||||
#ifndef EHOSTUNREACH
|
||||
# define EHOSTUNREACH WSAEHOSTUNREACH
|
||||
#endif
|
||||
#ifndef ENETUNREACH
|
||||
# define ENETUNREACH WSAENETUNREACH
|
||||
#endif
|
||||
#ifndef ECONNREFUSED
|
||||
# define ECONNREFUSED WSAECONNREFUSED
|
||||
#endif
|
||||
|
||||
/* Basilisk II Router defines those */
|
||||
# define udp_read_completion slirp_udp_read_completion
|
||||
# define write_udp slirp_write_udp
|
||||
# define init_udp slirp_init_udp
|
||||
# define final_udp slirp_final_udp
|
||||
#else
|
||||
# include <inttypes.h>
|
||||
# define HAVE_STDINT_H
|
||||
# define HAVE_STDLIB_H
|
||||
# define HAVE_STRING_H
|
||||
# define HAVE_UNISTD_H
|
||||
# define HAVE_INET_ATON
|
||||
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 *SLIRPcaddr_t;
|
||||
typedef int ioctlsockopt_t;
|
||||
# define ioctlsocket ioctl
|
||||
# define closesocket(s) close(s)
|
||||
# define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_BITYPES_H
|
||||
# include <sys/bitypes.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#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 */
|
||||
|
||||
/* Basilisk II types glue */
|
||||
typedef u_int8_t uint8;
|
||||
typedef u_int16_t uint16;
|
||||
typedef u_int32_t uint32;
|
||||
|
||||
#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
|
||||
# if HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
#ifndef _MSC_VER
|
||||
# include <strings.h>
|
||||
#else
|
||||
#include <string.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/uio.h>
|
||||
#endif
|
||||
|
||||
#ifndef _P
|
||||
#ifndef NO_PROTOTYPES
|
||||
# define _P(x) x
|
||||
#else
|
||||
# define _P(x) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#ifdef GETTIMEOFDAY_ONE_ARG
|
||||
#define gettimeofday(x, y) gettimeofday(x)
|
||||
#endif
|
||||
|
||||
/* Systems lacking strdup() definition in <string.h>. */
|
||||
#if defined(ultrix)
|
||||
char *strdup _P((const char *));
|
||||
#endif
|
||||
|
||||
/* Systems lacking malloc() definition in <stdlib.h>. */
|
||||
#if defined(ultrix) || defined(hcx)
|
||||
void *malloc _P((size_t arg));
|
||||
void free _P((void *ptr));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_ATON
|
||||
int inet_aton _P((const char *cp, struct in_addr *ia));
|
||||
#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
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_IOCTL_H)
|
||||
# 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"
|
||||
|
||||
#if defined __GNUC__
|
||||
#define PACKED__ __attribute__ ((packed))
|
||||
#elif defined __sgi
|
||||
#define PRAGMA_PACK_SUPPORTED 1
|
||||
#define PACK_END 0
|
||||
#define PACKED__
|
||||
#elif _MSC_VER
|
||||
#define PACKED__
|
||||
#else
|
||||
#error "Packed attribute or pragma shall be supported"
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(push, 1)
|
||||
#endif
|
||||
|
||||
#include "ip.h"
|
||||
#include "tcp.h"
|
||||
#include "tcp_timer.h"
|
||||
#include "tcp_var.h"
|
||||
#include "tcpip.h"
|
||||
#include "udp.h"
|
||||
#include "icmp_var.h"
|
||||
#include "mbuf.h"
|
||||
#include "sbuf.h"
|
||||
#include "socket.h"
|
||||
#include "if.h"
|
||||
#include "main.h"
|
||||
#include "misc.h"
|
||||
#include "ctl.h"
|
||||
#ifdef USE_PPP
|
||||
#include "ppp/pppd.h"
|
||||
#include "ppp/ppp.h"
|
||||
#endif
|
||||
|
||||
#include "bootp.h"
|
||||
#include "tftp.h"
|
||||
#include "libslirp.h"
|
||||
|
||||
extern struct ttys *ttys_unit[MAX_INTERFACES];
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (void *)0
|
||||
#endif
|
||||
|
||||
#ifndef FULL_BOLT
|
||||
void if_start _P((void));
|
||||
#else
|
||||
void if_start _P((struct ttys *));
|
||||
#endif
|
||||
|
||||
#ifdef BAD_SPRINTF
|
||||
# define vsprintf vsprintf_len
|
||||
# define sprintf sprintf_len
|
||||
extern int vsprintf_len _P((char *, const char *, va_list));
|
||||
extern int sprintf_len _P((char *, const char *, ...));
|
||||
#endif
|
||||
|
||||
#ifdef DECLARE_SPRINTF
|
||||
# ifndef BAD_SPRINTF
|
||||
extern int vsprintf _P((char *, const char *, va_list));
|
||||
# endif
|
||||
extern int vfprintf _P((FILE *, const char *, va_list));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
#ifndef _MSC_VER
|
||||
extern char *strerror _P((int error));
|
||||
#define HAVE_STRERROR
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INDEX
|
||||
char *index _P((const char *, int));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETHOSTID
|
||||
long gethostid _P((void));
|
||||
#endif
|
||||
|
||||
void lprint _P((const char *, ...));
|
||||
|
||||
extern int do_echo;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define __inline
|
||||
#endif
|
||||
|
||||
#if SIZEOF_CHAR_P == 4
|
||||
# define insque_32 insque
|
||||
# define remque_32 remque
|
||||
#else
|
||||
# ifdef NEED_QUE32_INLINE
|
||||
extern __inline void insque_32 _P((void *, void *));
|
||||
extern __inline void remque_32 _P((void *));
|
||||
# else
|
||||
extern void insque_32 _P((void *, void *));
|
||||
extern void remque_32 _P((void *));
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#define DEFAULT_BAUD 115200
|
||||
|
||||
/* cksum.c */
|
||||
int cksum(struct SLIRPmbuf *m, int len);
|
||||
|
||||
/* if.c */
|
||||
void if_init _P((void));
|
||||
void if_output _P((struct SLIRPsocket *, struct SLIRPmbuf *));
|
||||
|
||||
/* ip_input.c */
|
||||
void ip_init _P((void));
|
||||
void ip_input _P((struct SLIRPmbuf *));
|
||||
struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *));
|
||||
void ip_freef _P((struct ipq *));
|
||||
void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *));
|
||||
void ip_deq _P((register struct ipasfrag *));
|
||||
void ip_slowtimo _P((void));
|
||||
void ip_stripoptions _P((register struct SLIRPmbuf *, struct SLIRPmbuf *));
|
||||
|
||||
/* ip_output.c */
|
||||
int ip_output _P((struct SLIRPsocket *, struct SLIRPmbuf *));
|
||||
|
||||
/* tcp_input.c */
|
||||
int tcp_reass _P((register struct tcpcb *, register struct tcpiphdr *, struct SLIRPmbuf *));
|
||||
void tcp_input _P((register struct SLIRPmbuf *, int, struct SLIRPsocket *));
|
||||
void tcp_dooptions _P((struct tcpcb *, u_char *, int, struct tcpiphdr *));
|
||||
void tcp_xmit_timer _P((register struct tcpcb *, int));
|
||||
int tcp_mss _P((register struct tcpcb *, u_int));
|
||||
|
||||
/* tcp_output.c */
|
||||
int tcp_output _P((register struct tcpcb *));
|
||||
void tcp_setpersist _P((register struct tcpcb *));
|
||||
|
||||
/* tcp_subr.c */
|
||||
void tcp_init _P((void));
|
||||
void tcp_template _P((struct tcpcb *));
|
||||
void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct SLIRPmbuf *, tcp_seq, tcp_seq, int));
|
||||
struct tcpcb * tcp_newtcpcb _P((struct SLIRPsocket *));
|
||||
struct tcpcb * tcp_close _P((register struct tcpcb *));
|
||||
void tcp_drain _P((void));
|
||||
void tcp_sockclosed _P((struct tcpcb *));
|
||||
int tcp_fconnect _P((struct SLIRPsocket *));
|
||||
void tcp_connect _P((struct SLIRPsocket *));
|
||||
int tcp_attach _P((struct SLIRPsocket *));
|
||||
u_int8_t tcp_tos _P((struct SLIRPsocket *));
|
||||
int tcp_emu _P((struct SLIRPsocket *, struct SLIRPmbuf *));
|
||||
int tcp_ctl _P((struct SLIRPsocket *));
|
||||
struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
#ifdef USE_PPP
|
||||
#define MIN_MRU MINMRU
|
||||
#define MAX_MRU MAXMRU
|
||||
#else
|
||||
#define MIN_MRU 128
|
||||
#define MAX_MRU 16384
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#define min(x,y) ((x) < (y) ? (x) : (y))
|
||||
#define max(x,y) ((x) > (y) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef errno
|
||||
#define errno (WSAGetLastError())
|
||||
#endif
|
||||
|
||||
#define PROBE_CONN
|
||||
|
||||
#endif
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* User definable configuration options
|
||||
*/
|
||||
|
||||
/* Undefine if you don't want talk emulation */
|
||||
#undef EMULATE_TALK
|
||||
|
||||
/* Define if you want the connection to be probed */
|
||||
/* XXX Not working yet, so ignore this for now */
|
||||
#undef PROBE_CONN
|
||||
|
||||
/* Define to 1 if you want KEEPALIVE timers */
|
||||
#define DO_KEEPALIVE 0
|
||||
|
||||
/* Define to MAX interfaces you expect to use at once */
|
||||
/* MAX_INTERFACES determines the max. TOTAL number of interfaces (SLIP and PPP) */
|
||||
/* MAX_PPP_INTERFACES determines max. number of PPP interfaces */
|
||||
#define MAX_INTERFACES 1
|
||||
#define MAX_PPP_INTERFACES 1
|
||||
|
||||
/* Define if you want slirp's socket in /tmp */
|
||||
/* XXXXXX Do this in ./configure */
|
||||
#undef USE_TMPSOCKET
|
||||
|
||||
/* Define if you want slirp to use cfsetXspeed() on the terminal */
|
||||
#undef DO_CFSETSPEED
|
||||
|
||||
/* Define this if you want slirp to write to the tty as fast as it can */
|
||||
/* This should only be set if you are using load-balancing, slirp does a */
|
||||
/* pretty good job on single modems already, and seting this will make */
|
||||
/* interactive sessions less responsive */
|
||||
/* XXXXX Talk about having fast modem as unit 0 */
|
||||
#undef FULL_BOLT
|
||||
|
||||
/*
|
||||
* Define if you want slirp to use less CPU
|
||||
* You will notice a small lag in interactive sessions, but it's not that bad
|
||||
* Things like Netscape/ftp/etc. are completely unaffected
|
||||
* This is mainly for sysadmins who have many slirp users
|
||||
*/
|
||||
#undef USE_LOWCPU
|
||||
|
||||
/* Define this if your compiler doesn't like prototypes */
|
||||
#ifndef __STDC__
|
||||
#define NO_PROTOTYPES
|
||||
#endif
|
||||
|
||||
/*********************************************************/
|
||||
/*
|
||||
* Autoconf defined configuration options
|
||||
* You shouldn't need to touch any of these
|
||||
*/
|
||||
|
||||
/* Ignore this */
|
||||
#undef DUMMY_PPP
|
||||
|
||||
/* XXX: Define according to how time.h should be included */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
#define TIME_WITH_SYS_TIME 0
|
||||
#undef HAVE_SYS_TIME_H
|
||||
|
||||
/* Define if your sprintf returns char * instead of int */
|
||||
#undef BAD_SPRINTF
|
||||
|
||||
/* Define if you have readv */
|
||||
#undef HAVE_READV
|
||||
|
||||
/* Define if iovec needs to be declared */
|
||||
#undef DECLARE_IOVEC
|
||||
#ifdef _WIN32
|
||||
#define DECLARE_IOVEC
|
||||
#endif
|
||||
|
||||
/* Define if a declaration of sprintf/fprintf is needed */
|
||||
#undef DECLARE_SPRINTF
|
||||
|
||||
/* Define if you have sys/stropts.h */
|
||||
#undef HAVE_SYS_STROPTS_H
|
||||
|
||||
/* Define if your compiler doesn't like prototypes */
|
||||
#undef NO_PROTOTYPES
|
||||
|
||||
/* Define if you don't have u_int32_t etc. typedef'd */
|
||||
#undef NEED_TYPEDEFS
|
||||
#ifdef __sun__
|
||||
#define NEED_TYPEDEFS
|
||||
#endif
|
||||
|
||||
/* Define to sizeof(char *) */
|
||||
#define SIZEOF_CHAR_P SIZEOF_VOID_P
|
||||
|
||||
/* Define if you have random() */
|
||||
#undef HAVE_RANDOM
|
||||
|
||||
/* Define if you have srandom() */
|
||||
#undef HAVE_SRANDOM
|
||||
|
||||
/* Define if you have setenv */
|
||||
#undef HAVE_SETENV
|
||||
|
||||
/* Define if you have index() */
|
||||
#undef HAVE_INDEX
|
||||
|
||||
/* Define if you have bcmp() */
|
||||
#undef HAVE_BCMP
|
||||
|
||||
/* Define if you have drand48 */
|
||||
#undef HAVE_DRAND48
|
||||
|
||||
/* Define if you have memmove */
|
||||
#define HAVE_MEMMOVE
|
||||
|
||||
/* Define if you have gethostid */
|
||||
#undef HAVE_GETHOSTID
|
||||
|
||||
/* Define if you DON'T have unix-domain sockets */
|
||||
#undef NO_UNIX_SOCKETS
|
||||
#ifdef _WIN32
|
||||
#define NO_UNIX_SOCKETS
|
||||
#endif
|
||||
|
||||
/* Define if gettimeofday only takes one argument */
|
||||
#undef GETTIMEOFDAY_ONE_ARG
|
||||
|
||||
/* Define if you have revoke() */
|
||||
#undef HAVE_REVOKE
|
||||
|
||||
/* Define if you have the sysv method of opening pty's (/dev/ptmx, etc.) */
|
||||
#undef HAVE_GRANTPT
|
||||
|
||||
/* Define if you have fchmod */
|
||||
#undef HAVE_FCHMOD
|
||||
|
||||
/* Define if you have <sys/type32.h> */
|
||||
#undef HAVE_SYS_TYPES32_H
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* 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 SLIRPsocket {
|
||||
struct SLIRPsocket *so_next,*so_prev; /* For a linked list of sockets */
|
||||
|
||||
int s; /* The actual socket */
|
||||
|
||||
/* XXX union these with not-yet-used sbuf params */
|
||||
struct SLIRPmbuf *so_m; /* Pointer to the original SYN packet,
|
||||
* for non-blocking connect()'s, and
|
||||
* PING reply's */
|
||||
struct tcpiphdr *so_ti; /* Pointer to the original ti within
|
||||
* so_mconn, for non-blocking connections */
|
||||
int so_urgc;
|
||||
struct in_addr so_faddr; /* foreign host table entry */
|
||||
struct in_addr so_laddr; /* local host table entry */
|
||||
u_int16_t so_fport; /* foreign port */
|
||||
u_int16_t so_lport; /* local port */
|
||||
|
||||
u_int8_t so_iptos; /* Type of service */
|
||||
u_int8_t so_emu; /* Is the socket emulated? */
|
||||
|
||||
u_char so_type; /* Type of socket, UDP or TCP */
|
||||
int so_state; /* internal state flags SS_*, below */
|
||||
|
||||
struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */
|
||||
u_int so_expire; /* When the socket will expire */
|
||||
|
||||
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 */
|
||||
|
||||
struct sbuf so_rcv; /* Receive buffer */
|
||||
struct sbuf so_snd; /* Send buffer */
|
||||
void * extra; /* Extra pointer */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Socket state bits. (peer means the host on the Internet,
|
||||
* local host means the host on the other end of the modem)
|
||||
*/
|
||||
#define SS_NOFDREF 0x001 /* No fd reference */
|
||||
|
||||
#define SS_ISFCONNECTING 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */
|
||||
#define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */
|
||||
#define SS_FCANTRCVMORE 0x008 /* Socket can't receive more from peer (for half-closes) */
|
||||
#define SS_FCANTSENDMORE 0x010 /* Socket can't send more to peer (for half-closes) */
|
||||
/* #define SS_ISFDISCONNECTED 0x020*/ /* Socket has disconnected from peer, in 2MSL state */
|
||||
#define SS_FWDRAIN 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */
|
||||
|
||||
#define SS_CTL 0x080
|
||||
#define SS_FACCEPTCONN 0x100 /* Socket is accepting connections from a host on the internet */
|
||||
#define SS_FACCEPTONCE 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */
|
||||
|
||||
extern struct SLIRPsocket tcb;
|
||||
|
||||
|
||||
#if defined(DECLARE_IOVEC) && !defined(HAVE_READV)
|
||||
struct iovec {
|
||||
char *iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
#endif
|
||||
|
||||
void so_init _P((void));
|
||||
struct SLIRPsocket * solookup _P((struct SLIRPsocket *, struct in_addr, u_int, struct in_addr, u_int));
|
||||
struct SLIRPsocket * socreate _P((void));
|
||||
void sofree _P((struct SLIRPsocket *));
|
||||
int soread _P((struct SLIRPsocket *));
|
||||
void sorecvoob _P((struct SLIRPsocket *));
|
||||
int sosendoob _P((struct SLIRPsocket *));
|
||||
int sowrite _P((struct SLIRPsocket *));
|
||||
void sorecvfrom _P((struct SLIRPsocket *));
|
||||
int sosendto _P((struct SLIRPsocket *, struct SLIRPmbuf *));
|
||||
struct SLIRPsocket * solisten _P((u_int, u_int32_t, u_int, int));
|
||||
void sorwakeup _P((struct SLIRPsocket *));
|
||||
void sowwakeup _P((struct SLIRPsocket *));
|
||||
void soisfconnecting _P((register struct SLIRPsocket *));
|
||||
void soisfconnected _P((register struct SLIRPsocket *));
|
||||
void sofcantrcvmore _P((struct SLIRPsocket *));
|
||||
void sofcantsendmore _P((struct SLIRPsocket *));
|
||||
void soisfdisconnected _P((struct SLIRPsocket *));
|
||||
void sofwdrain _P((struct SLIRPsocket *));
|
||||
|
||||
#endif /* _SOCKET_H_ */
|
||||
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)tcp.h 8.1 (Berkeley) 6/10/93
|
||||
* tcp.h,v 1.3 1994/08/21 05:27:34 paul Exp
|
||||
*/
|
||||
|
||||
#ifndef _TCP_H_
|
||||
#define _TCP_H_
|
||||
|
||||
#if defined(__amd64__) || defined(__aarch64__)
|
||||
typedef uintptr_t tcp_seq;
|
||||
#else
|
||||
typedef u_int32_t tcp_seq;
|
||||
#endif
|
||||
|
||||
#define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */
|
||||
#define PR_FASTHZ 5 /* 5 fast timeouts per second (not important) */
|
||||
|
||||
extern int tcp_rcvspace;
|
||||
extern int tcp_sndspace;
|
||||
extern struct SLIRPsocket *tcp_last_so;
|
||||
|
||||
#define TCP_SNDSPACE 8192
|
||||
#define TCP_RCVSPACE 8192
|
||||
|
||||
/*
|
||||
* TCP header.
|
||||
* Per RFC 793, September, 1981.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct tcphdr {
|
||||
u_int16_t th_sport; /* source port */
|
||||
u_int16_t th_dport; /* destination port */
|
||||
tcp_seq th_seq; /* sequence number */
|
||||
tcp_seq th_ack; /* acknowledgement number */
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
u_char th_off:4, /* data offset */
|
||||
th_x2:4; /* (unused) */
|
||||
#else
|
||||
u_char th_x2:4, /* (unused) */
|
||||
th_off:4; /* data offset */
|
||||
#endif
|
||||
u_int8_t th_flags;
|
||||
#define TH_FIN 0x01
|
||||
#define TH_SYN 0x02
|
||||
#define TH_RST 0x04
|
||||
#define TH_PUSH 0x08
|
||||
#define TH_ACK 0x10
|
||||
#define TH_URG 0x20
|
||||
u_int16_t th_win; /* window */
|
||||
u_int16_t th_sum; /* checksum */
|
||||
u_int16_t th_urp; /* urgent pointer */
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(PACK_END)
|
||||
#endif
|
||||
|
||||
#include "tcp_var.h"
|
||||
|
||||
#define TCPOPT_EOL 0
|
||||
#define TCPOPT_NOP 1
|
||||
#define TCPOPT_MAXSEG 2
|
||||
#define TCPOLEN_MAXSEG 4
|
||||
#define TCPOPT_WINDOW 3
|
||||
#define TCPOLEN_WINDOW 3
|
||||
#define TCPOPT_SACK_PERMITTED 4 /* Experimental */
|
||||
#define TCPOLEN_SACK_PERMITTED 2
|
||||
#define TCPOPT_SACK 5 /* Experimental */
|
||||
#define TCPOPT_TIMESTAMP 8
|
||||
#define TCPOLEN_TIMESTAMP 10
|
||||
#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
|
||||
|
||||
#define TCPOPT_TSTAMP_HDR \
|
||||
(TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
|
||||
|
||||
/*
|
||||
* Default maximum segment size for TCP.
|
||||
* With an IP MSS of 576, this is 536,
|
||||
* but 512 is probably more convenient.
|
||||
* This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
|
||||
*
|
||||
* We make this 1460 because we only care about Ethernet in the qemu context.
|
||||
*/
|
||||
#define TCP_MSS 1460
|
||||
|
||||
#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */
|
||||
|
||||
#define TCP_MAX_WINSHIFT 14 /* maximum window shift */
|
||||
|
||||
/*
|
||||
* User-settable options (used with setsockopt).
|
||||
*
|
||||
* We don't use the system headers on unix because we have conflicting
|
||||
* local structures. We can't avoid the system definitions on Windows,
|
||||
* so we undefine them.
|
||||
*/
|
||||
#undef TCP_NODELAY
|
||||
#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
|
||||
#undef TCP_MAXSEG
|
||||
/* #define TCP_MAXSEG 0x02 */ /* set maximum segment size */
|
||||
|
||||
/*
|
||||
* TCP FSM state definitions.
|
||||
* Per RFC793, September, 1981.
|
||||
*/
|
||||
|
||||
#define TCP_NSTATES 11
|
||||
|
||||
#define TCPS_CLOSED 0 /* closed */
|
||||
#define TCPS_LISTEN 1 /* listening for connection */
|
||||
#define TCPS_SYN_SENT 2 /* active, have sent syn */
|
||||
#define TCPS_SYN_RECEIVED 3 /* have send and received syn */
|
||||
/* states < TCPS_ESTABLISHED are those where connections not established */
|
||||
#define TCPS_ESTABLISHED 4 /* established */
|
||||
#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
|
||||
/* states > TCPS_CLOSE_WAIT are those where user has closed */
|
||||
#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
|
||||
#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
|
||||
#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
|
||||
/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
|
||||
#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
|
||||
#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
|
||||
|
||||
#define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED)
|
||||
#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED)
|
||||
#define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT)
|
||||
|
||||
/*
|
||||
* TCP sequence numbers are 32 bit integers operated
|
||||
* on with modular arithmetic. These macros can be
|
||||
* used to compare such integers.
|
||||
*/
|
||||
#define SEQ_LT(a,b) ((int)((a)-(b)) < 0)
|
||||
#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
|
||||
#define SEQ_GT(a,b) ((int)((a)-(b)) > 0)
|
||||
#define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0)
|
||||
|
||||
/*
|
||||
* Macros to initialize tcp sequence numbers for
|
||||
* send and receive from initial send and receive
|
||||
* sequence numbers.
|
||||
*/
|
||||
#define tcp_rcvseqinit(tp) \
|
||||
(tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
|
||||
|
||||
#define tcp_sendseqinit(tp) \
|
||||
(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = (tp)->iss
|
||||
|
||||
#define TCP_ISSINCR (125*1024) /* increment for tcp_iss each second */
|
||||
|
||||
extern tcp_seq tcp_iss; /* tcp initial send seq # */
|
||||
|
||||
extern char *tcpstates[];
|
||||
|
||||
#endif
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93
|
||||
* tcp_timer.h,v 1.4 1994/08/21 05:27:38 paul Exp
|
||||
*/
|
||||
|
||||
#ifndef _TCP_TIMER_H_
|
||||
#define _TCP_TIMER_H_
|
||||
|
||||
/*
|
||||
* Definitions of the TCP timers. These timers are counted
|
||||
* down PR_SLOWHZ times a second.
|
||||
*/
|
||||
#define TCPT_NTIMERS 4
|
||||
|
||||
#define TCPT_REXMT 0 /* retransmit */
|
||||
#define TCPT_PERSIST 1 /* retransmit persistence */
|
||||
#define TCPT_KEEP 2 /* keep alive */
|
||||
#define TCPT_2MSL 3 /* 2*msl quiet time timer */
|
||||
|
||||
/*
|
||||
* The TCPT_REXMT timer is used to force retransmissions.
|
||||
* The TCP has the TCPT_REXMT timer set whenever segments
|
||||
* have been sent for which ACKs are expected but not yet
|
||||
* received. If an ACK is received which advances tp->snd_una,
|
||||
* then the retransmit timer is cleared (if there are no more
|
||||
* outstanding segments) or reset to the base value (if there
|
||||
* are more ACKs expected). Whenever the retransmit timer goes off,
|
||||
* we retransmit one unacknowledged segment, and do a backoff
|
||||
* on the retransmit timer.
|
||||
*
|
||||
* The TCPT_PERSIST timer is used to keep window size information
|
||||
* flowing even if the window goes shut. If all previous transmissions
|
||||
* have been acknowledged (so that there are no retransmissions in progress),
|
||||
* and the window is too small to bother sending anything, then we start
|
||||
* the TCPT_PERSIST timer. When it expires, if the window is nonzero,
|
||||
* we go to transmit state. Otherwise, at intervals send a single byte
|
||||
* into the peer's window to force him to update our window information.
|
||||
* We do this at most as often as TCPT_PERSMIN time intervals,
|
||||
* but no more frequently than the current estimate of round-trip
|
||||
* packet time. The TCPT_PERSIST timer is cleared whenever we receive
|
||||
* a window update from the peer.
|
||||
*
|
||||
* The TCPT_KEEP timer is used to keep connections alive. If an
|
||||
* connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time,
|
||||
* but not yet established, then we drop the connection. Once the connection
|
||||
* is established, if the connection is idle for TCPTV_KEEP_IDLE time
|
||||
* (and keepalives have been enabled on the socket), we begin to probe
|
||||
* the connection. We force the peer to send us a segment by sending:
|
||||
* <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
|
||||
* This segment is (deliberately) outside the window, and should elicit
|
||||
* an ack segment in response from the peer. If, despite the TCPT_KEEP
|
||||
* initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE
|
||||
* amount of time probing, then we drop the connection.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Time constants.
|
||||
*/
|
||||
#define TCPTV_MSL ( 5*PR_SLOWHZ) /* max seg lifetime (hah!) */
|
||||
|
||||
#define TCPTV_SRTTBASE 0 /* base roundtrip time;
|
||||
if 0, no idea yet */
|
||||
#define TCPTV_SRTTDFLT ( 3*PR_SLOWHZ) /* assumed RTT if no info */
|
||||
|
||||
#define TCPTV_PERSMIN ( 5*PR_SLOWHZ) /* retransmit persistence */
|
||||
#define TCPTV_PERSMAX ( 60*PR_SLOWHZ) /* maximum persist interval */
|
||||
|
||||
#define TCPTV_KEEP_INIT ( 75*PR_SLOWHZ) /* initial connect keep alive */
|
||||
#define TCPTV_KEEP_IDLE (120*60*PR_SLOWHZ) /* dflt time before probing */
|
||||
#define TCPTV_KEEPINTVL ( 75*PR_SLOWHZ) /* default probe interval */
|
||||
#define TCPTV_KEEPCNT 8 /* max probes before drop */
|
||||
|
||||
#define TCPTV_MIN ( 1*PR_SLOWHZ) /* minimum allowable value */
|
||||
/* #define TCPTV_REXMTMAX ( 64*PR_SLOWHZ) */ /* max allowable REXMT value */
|
||||
#define TCPTV_REXMTMAX ( 12*PR_SLOWHZ) /* max allowable REXMT value */
|
||||
|
||||
#define TCP_LINGERTIME 120 /* linger at most 2 minutes */
|
||||
|
||||
#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */
|
||||
|
||||
|
||||
#ifdef TCPTIMERS
|
||||
char *tcptimers[] =
|
||||
{ "REXMT", "PERSIST", "KEEP", "2MSL" };
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Force a time value to be in a certain range.
|
||||
*/
|
||||
#define TCPT_RANGESET(tv, value, tvmin, tvmax) { \
|
||||
(tv) = (value); \
|
||||
if ((tv) < (tvmin)) \
|
||||
(tv) = (tvmin); \
|
||||
else if ((tv) > (tvmax)) \
|
||||
(tv) = (tvmax); \
|
||||
}
|
||||
|
||||
extern int tcp_keepidle; /* time before keepalive probes begin */
|
||||
extern int tcp_keepintvl; /* time between keepalive probes */
|
||||
extern int tcp_maxidle; /* time to drop after starting probes */
|
||||
extern int tcp_ttl; /* time to live for TCP segs */
|
||||
extern int tcp_backoff[];
|
||||
|
||||
struct tcpcb;
|
||||
|
||||
void tcp_fasttimo _P((void));
|
||||
void tcp_slowtimo _P((void));
|
||||
void tcp_canceltimers _P((struct tcpcb *));
|
||||
struct tcpcb * tcp_timers _P((register struct tcpcb *, int));
|
||||
|
||||
#endif
|
||||
@@ -1,256 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)tcp_var.h 8.3 (Berkeley) 4/10/94
|
||||
* tcp_var.h,v 1.3 1994/08/21 05:27:39 paul Exp
|
||||
*/
|
||||
|
||||
#ifndef _TCP_VAR_H_
|
||||
#define _TCP_VAR_H_
|
||||
|
||||
#include "tcpip.h"
|
||||
#include "tcp_timer.h"
|
||||
|
||||
#if defined(__amd64__) || defined(__aarch64__)
|
||||
typedef uintptr_t tcpiphdrp_32;
|
||||
#else
|
||||
#if SIZEOF_CHAR_P == 4
|
||||
typedef struct tcpiphdr *tcpiphdrp_32;
|
||||
#else
|
||||
typedef u_int32_t tcpiphdrp_32;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Tcp control block, one per tcp; fields:
|
||||
*/
|
||||
struct tcpcb {
|
||||
tcpiphdrp_32 seg_next; /* sequencing queue */
|
||||
tcpiphdrp_32 seg_prev;
|
||||
short t_state; /* state of this connection */
|
||||
short t_timer[TCPT_NTIMERS]; /* tcp timers */
|
||||
short t_rxtshift; /* log(2) of rexmt exp. backoff */
|
||||
short t_rxtcur; /* current retransmit value */
|
||||
short t_dupacks; /* consecutive dup acks recd */
|
||||
u_short t_maxseg; /* maximum segment size */
|
||||
char t_force; /* 1 if forcing out a byte */
|
||||
u_short t_flags;
|
||||
#define TF_ACKNOW 0x0001 /* ack peer immediately */
|
||||
#define TF_DELACK 0x0002 /* ack, but try to delay it */
|
||||
#define TF_NODELAY 0x0004 /* don't delay packets to coalesce */
|
||||
#define TF_NOOPT 0x0008 /* don't use tcp options */
|
||||
#define TF_SENTFIN 0x0010 /* have sent FIN */
|
||||
#define TF_REQ_SCALE 0x0020 /* have/will request window scaling */
|
||||
#define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */
|
||||
#define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */
|
||||
#define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */
|
||||
#define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */
|
||||
|
||||
/* Make it static for now */
|
||||
/* struct tcpiphdr *t_template; / * skeletal packet for transmit */
|
||||
struct tcpiphdr t_template;
|
||||
|
||||
struct SLIRPsocket *t_socket; /* back pointer to socket */
|
||||
/*
|
||||
* The following fields are used as in the protocol specification.
|
||||
* See RFC783, Dec. 1981, page 21.
|
||||
*/
|
||||
/* send sequence variables */
|
||||
tcp_seq snd_una; /* send unacknowledged */
|
||||
tcp_seq snd_nxt; /* send next */
|
||||
tcp_seq snd_up; /* send urgent pointer */
|
||||
tcp_seq snd_wl1; /* window update seg seq number */
|
||||
tcp_seq snd_wl2; /* window update seg ack number */
|
||||
tcp_seq iss; /* initial send sequence number */
|
||||
u_int32_t snd_wnd; /* send window */
|
||||
/* receive sequence variables */
|
||||
u_int32_t rcv_wnd; /* receive window */
|
||||
tcp_seq rcv_nxt; /* receive next */
|
||||
tcp_seq rcv_up; /* receive urgent pointer */
|
||||
tcp_seq irs; /* initial receive sequence number */
|
||||
/*
|
||||
* Additional variables for this implementation.
|
||||
*/
|
||||
/* receive variables */
|
||||
tcp_seq rcv_adv; /* advertised window */
|
||||
/* retransmit variables */
|
||||
tcp_seq snd_max; /* highest sequence number sent;
|
||||
* used to recognize retransmits
|
||||
*/
|
||||
/* congestion control (for slow start, source quench, retransmit after loss) */
|
||||
u_int32_t snd_cwnd; /* congestion-controlled window */
|
||||
u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
|
||||
* for slow start exponential to
|
||||
* linear switch
|
||||
*/
|
||||
/*
|
||||
* transmit timing stuff. See below for scale of srtt and rttvar.
|
||||
* "Variance" is actually smoothed difference.
|
||||
*/
|
||||
short t_idle; /* inactivity time */
|
||||
short t_rtt; /* round trip time */
|
||||
tcp_seq t_rtseq; /* sequence number being timed */
|
||||
short t_srtt; /* smoothed round-trip time */
|
||||
short t_rttvar; /* variance in round-trip time */
|
||||
u_short t_rttmin; /* minimum rtt allowed */
|
||||
u_int32_t max_sndwnd; /* largest window peer has offered */
|
||||
|
||||
/* out-of-band data */
|
||||
char t_oobflags; /* have some */
|
||||
char t_iobc; /* input character */
|
||||
#define TCPOOB_HAVEDATA 0x01
|
||||
#define TCPOOB_HADDATA 0x02
|
||||
short t_softerror; /* possible error not yet reported */
|
||||
|
||||
/* RFC 1323 variables */
|
||||
u_char snd_scale; /* window scaling for send window */
|
||||
u_char rcv_scale; /* window scaling for recv window */
|
||||
u_char request_r_scale; /* pending window scaling */
|
||||
u_char requested_s_scale;
|
||||
u_int32_t ts_recent; /* timestamp echo data */
|
||||
u_int32_t ts_recent_age; /* when last updated */
|
||||
tcp_seq last_ack_sent;
|
||||
|
||||
};
|
||||
|
||||
#define sototcpcb(so) ((so)->so_tcpcb)
|
||||
|
||||
/*
|
||||
* The smoothed round-trip time and estimated variance
|
||||
* are stored as fixed point numbers scaled by the values below.
|
||||
* For convenience, these scales are also used in smoothing the average
|
||||
* (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
|
||||
* With these scales, srtt has 3 bits to the right of the binary point,
|
||||
* and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the
|
||||
* binary point, and is smoothed with an ALPHA of 0.75.
|
||||
*/
|
||||
#define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */
|
||||
#define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */
|
||||
#define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */
|
||||
#define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */
|
||||
|
||||
/*
|
||||
* The initial retransmission should happen at rtt + 4 * rttvar.
|
||||
* Because of the way we do the smoothing, srtt and rttvar
|
||||
* will each average +1/2 tick of bias. When we compute
|
||||
* the retransmit timer, we want 1/2 tick of rounding and
|
||||
* 1 extra tick because of +-1/2 tick uncertainty in the
|
||||
* firing of the timer. The bias will give us exactly the
|
||||
* 1.5 tick we need. But, because the bias is
|
||||
* statistical, we have to test that we don't drop below
|
||||
* the minimum feasible timer (which is 2 ticks).
|
||||
* This macro assumes that the value of TCP_RTTVAR_SCALE
|
||||
* is the same as the multiplier for rttvar.
|
||||
*/
|
||||
#define TCP_REXMTVAL(tp) \
|
||||
(((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar)
|
||||
|
||||
/* XXX
|
||||
* We want to avoid doing m_pullup on incoming packets but that
|
||||
* means avoiding dtom on the tcp reassembly code. That in turn means
|
||||
* keeping an mbuf pointer in the reassembly queue (since we might
|
||||
* have a cluster). As a quick hack, the source & destination
|
||||
* port numbers (which are no longer needed once we've located the
|
||||
* tcpcb) are overlayed with an mbuf pointer.
|
||||
*/
|
||||
#if defined(__amd64__) || defined(__aarch64__)
|
||||
typedef uintptr_t mbufp_32;
|
||||
#else
|
||||
#if SIZEOF_CHAR_P == 4
|
||||
typedef struct SLIRPmbuf *mbufp_32;
|
||||
#else
|
||||
typedef u_int32_t mbufp_32;
|
||||
#endif
|
||||
#endif
|
||||
#define REASS_MBUF(ti) (*(mbufp_32 *)&((ti)->ti_t))
|
||||
|
||||
/*
|
||||
* TCP statistics.
|
||||
* Many of these should be kept per connection,
|
||||
* but that's inconvenient at the moment.
|
||||
*/
|
||||
struct tcpstat {
|
||||
u_long tcps_connattempt; /* connections initiated */
|
||||
u_long tcps_accepts; /* connections accepted */
|
||||
u_long tcps_connects; /* connections established */
|
||||
u_long tcps_drops; /* connections dropped */
|
||||
u_long tcps_conndrops; /* embryonic connections dropped */
|
||||
u_long tcps_closed; /* conn. closed (includes drops) */
|
||||
u_long tcps_segstimed; /* segs where we tried to get rtt */
|
||||
u_long tcps_rttupdated; /* times we succeeded */
|
||||
u_long tcps_delack; /* delayed acks sent */
|
||||
u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */
|
||||
u_long tcps_rexmttimeo; /* retransmit timeouts */
|
||||
u_long tcps_persisttimeo; /* persist timeouts */
|
||||
u_long tcps_keeptimeo; /* keepalive timeouts */
|
||||
u_long tcps_keepprobe; /* keepalive probes sent */
|
||||
u_long tcps_keepdrops; /* connections dropped in keepalive */
|
||||
|
||||
u_long tcps_sndtotal; /* total packets sent */
|
||||
u_long tcps_sndpack; /* data packets sent */
|
||||
u_long tcps_sndbyte; /* data bytes sent */
|
||||
u_long tcps_sndrexmitpack; /* data packets retransmitted */
|
||||
u_long tcps_sndrexmitbyte; /* data bytes retransmitted */
|
||||
u_long tcps_sndacks; /* ack-only packets sent */
|
||||
u_long tcps_sndprobe; /* window probes sent */
|
||||
u_long tcps_sndurg; /* packets sent with URG only */
|
||||
u_long tcps_sndwinup; /* window update-only packets sent */
|
||||
u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */
|
||||
|
||||
u_long tcps_rcvtotal; /* total packets received */
|
||||
u_long tcps_rcvpack; /* packets received in sequence */
|
||||
u_long tcps_rcvbyte; /* bytes received in sequence */
|
||||
u_long tcps_rcvbadsum; /* packets received with ccksum errs */
|
||||
u_long tcps_rcvbadoff; /* packets received with bad offset */
|
||||
/* u_long tcps_rcvshort; */ /* packets received too short */
|
||||
u_long tcps_rcvduppack; /* duplicate-only packets received */
|
||||
u_long tcps_rcvdupbyte; /* duplicate-only bytes received */
|
||||
u_long tcps_rcvpartduppack; /* packets with some duplicate data */
|
||||
u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */
|
||||
u_long tcps_rcvoopack; /* out-of-order packets received */
|
||||
u_long tcps_rcvoobyte; /* out-of-order bytes received */
|
||||
u_long tcps_rcvpackafterwin; /* packets with data after window */
|
||||
u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */
|
||||
u_long tcps_rcvafterclose; /* packets rcvd after "close" */
|
||||
u_long tcps_rcvwinprobe; /* rcvd window probe packets */
|
||||
u_long tcps_rcvdupack; /* rcvd duplicate acks */
|
||||
u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */
|
||||
u_long tcps_rcvackpack; /* rcvd ack packets */
|
||||
u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */
|
||||
u_long tcps_rcvwinupd; /* rcvd window update packets */
|
||||
/* u_long tcps_pawsdrop; */ /* segments dropped due to PAWS */
|
||||
u_long tcps_predack; /* times hdr predict ok for acks */
|
||||
u_long tcps_preddat; /* times hdr predict ok for data pkts */
|
||||
u_long tcps_socachemiss; /* tcp_last_so misses */
|
||||
u_long tcps_didnuttin; /* Times tcp_output didn't do anything XXX */
|
||||
};
|
||||
|
||||
extern struct tcpstat tcpstat; /* tcp statistics */
|
||||
extern u_int32_t tcp_now; /* for RFC 1323 timestamps */
|
||||
|
||||
#endif
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)tcpip.h 8.1 (Berkeley) 6/10/93
|
||||
* tcpip.h,v 1.3 1994/08/21 05:27:40 paul Exp
|
||||
*/
|
||||
|
||||
#ifndef _TCPIP_H_
|
||||
#define _TCPIP_H_
|
||||
|
||||
/*
|
||||
* Tcp+ip header, after ip options removed.
|
||||
*/
|
||||
struct tcpiphdr {
|
||||
struct ipovly ti_i; /* overlaid ip structure */
|
||||
struct tcphdr ti_t; /* tcp header */
|
||||
};
|
||||
#define ti_next ti_i.ih_next
|
||||
#define ti_prev ti_i.ih_prev
|
||||
#define ti_x1 ti_i.ih_x1
|
||||
#define ti_pr ti_i.ih_pr
|
||||
#define ti_len ti_i.ih_len
|
||||
#define ti_src ti_i.ih_src
|
||||
#define ti_dst ti_i.ih_dst
|
||||
#define ti_sport ti_t.th_sport
|
||||
#define ti_dport ti_t.th_dport
|
||||
#define ti_seq ti_t.th_seq
|
||||
#define ti_ack ti_t.th_ack
|
||||
#define ti_x2 ti_t.th_x2
|
||||
#define ti_off ti_t.th_off
|
||||
#define ti_flags ti_t.th_flags
|
||||
#define ti_win ti_t.th_win
|
||||
#define ti_sum ti_t.th_sum
|
||||
#define ti_urp ti_t.th_urp
|
||||
|
||||
/*
|
||||
* Just a clean way to get to the first byte
|
||||
* of the packet
|
||||
*/
|
||||
struct tcpiphdr_2 {
|
||||
struct tcpiphdr dummy;
|
||||
char first_char;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,40 +0,0 @@
|
||||
/* tftp defines */
|
||||
|
||||
#define TFTP_SESSIONS_MAX 3
|
||||
|
||||
#define TFTP_SERVER 69
|
||||
|
||||
#define TFTP_RRQ 1
|
||||
#define TFTP_WRQ 2
|
||||
#define TFTP_DATA 3
|
||||
#define TFTP_ACK 4
|
||||
#define TFTP_ERROR 5
|
||||
|
||||
#define TFTP_FILENAME_MAX 512
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct tftp_t {
|
||||
struct ip ip;
|
||||
struct udphdr udp;
|
||||
u_int16_t tp_op;
|
||||
union {
|
||||
struct {
|
||||
u_int16_t tp_block_nr;
|
||||
u_int8_t tp_buf[512];
|
||||
} tp_data;
|
||||
struct {
|
||||
u_int16_t tp_error_code;
|
||||
u_int8_t tp_msg[512];
|
||||
} tp_error;
|
||||
u_int8_t tp_buf[512 + 2];
|
||||
} x;
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(PACK_END)
|
||||
#endif
|
||||
|
||||
void tftp_input(struct SLIRPmbuf *m);
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)udp.h 8.1 (Berkeley) 6/10/93
|
||||
* udp.h,v 1.3 1994/08/21 05:27:41 paul Exp
|
||||
*/
|
||||
|
||||
#ifndef _UDP_H_
|
||||
#define _UDP_H_
|
||||
|
||||
#define UDP_TTL 0x60
|
||||
#define UDP_UDPDATALEN 16192
|
||||
|
||||
extern struct SLIRPsocket *udp_last_so;
|
||||
|
||||
/*
|
||||
* Udp protocol header.
|
||||
* Per RFC 768, September, 1981.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct udphdr {
|
||||
u_int16_t uh_sport; /* source port */
|
||||
u_int16_t uh_dport; /* destination port */
|
||||
int16_t uh_ulen; /* udp length */
|
||||
u_int16_t uh_sum; /* udp checksum */
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(PACK_END)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* UDP kernel structures and variables.
|
||||
*/
|
||||
struct udpiphdr {
|
||||
struct ipovly ui_i; /* overlaid ip structure */
|
||||
struct udphdr ui_u; /* udp header */
|
||||
};
|
||||
#define ui_next ui_i.ih_next
|
||||
#define ui_prev ui_i.ih_prev
|
||||
#define ui_x1 ui_i.ih_x1
|
||||
#define ui_pr ui_i.ih_pr
|
||||
#define ui_len ui_i.ih_len
|
||||
#define ui_src ui_i.ih_src
|
||||
#define ui_dst ui_i.ih_dst
|
||||
#define ui_sport ui_u.uh_sport
|
||||
#define ui_dport ui_u.uh_dport
|
||||
#define ui_ulen ui_u.uh_ulen
|
||||
#define ui_sum ui_u.uh_sum
|
||||
|
||||
struct udpstat {
|
||||
/* input statistics: */
|
||||
u_long udps_ipackets; /* total input packets */
|
||||
u_long udps_hdrops; /* packet shorter than header */
|
||||
u_long udps_badsum; /* checksum error */
|
||||
u_long udps_badlen; /* data length larger than packet */
|
||||
u_long udps_noport; /* no socket on port */
|
||||
u_long udps_noportbcast; /* of above, arrived as broadcast */
|
||||
u_long udps_fullsock; /* not delivered, input socket full */
|
||||
u_long udpps_pcbcachemiss; /* input packets missing pcb cache */
|
||||
/* output statistics: */
|
||||
u_long udps_opackets; /* total output packets */
|
||||
};
|
||||
|
||||
/*
|
||||
* Names for UDP sysctl objects
|
||||
*/
|
||||
#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */
|
||||
#define UDPCTL_MAXID 2
|
||||
|
||||
extern struct udpstat udpstat;
|
||||
extern struct SLIRPsocket udb;
|
||||
struct SLIRPmbuf;
|
||||
|
||||
void udp_init _P((void));
|
||||
void udp_input _P((register struct SLIRPmbuf *, int));
|
||||
int udp_output _P((struct SLIRPsocket *, struct SLIRPmbuf *, struct sockaddr_in *));
|
||||
int udp_attach _P((struct SLIRPsocket *));
|
||||
void udp_detach _P((struct SLIRPsocket *));
|
||||
u_int8_t udp_tos _P((struct SLIRPsocket *));
|
||||
void udp_emu _P((struct SLIRPsocket *, struct SLIRPmbuf *));
|
||||
struct SLIRPsocket * udp_listen _P((u_int, u_int32_t, u_int, int));
|
||||
int udp_output2(struct SLIRPsocket *so, struct SLIRPmbuf *m,
|
||||
struct sockaddr_in *saddr, struct sockaddr_in *daddr,
|
||||
int iptos);
|
||||
#endif
|
||||
260
src/include/tinyglib.h
Normal file
260
src/include/tinyglib.h
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
||||
* running old operating systems and software designed for IBM
|
||||
* PC systems and compatibles from 1981 through fairly recent
|
||||
* system designs based on the PCI bus.
|
||||
*
|
||||
* This file is part of the 86Box distribution.
|
||||
*
|
||||
* Minimal reimplementation of GLib for libslirp.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Author: RichardG, <richardg867@gmail.com>
|
||||
*
|
||||
* Copyright 2020 RichardG.
|
||||
*/
|
||||
#ifndef TINYGLIB_H
|
||||
# define TINYGLIB_H
|
||||
|
||||
/* Define this to bypass TinyGLib and use full GLib instead. */
|
||||
#ifdef TINYGLIB_USE_GLIB
|
||||
#include <glib.h>
|
||||
#else
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#define HAVE_STDARG_H
|
||||
#include <86box/86box.h>
|
||||
|
||||
|
||||
/* Definitions */
|
||||
|
||||
#define G_LITTLE_ENDIAN 1234
|
||||
#define G_BIG_ENDIAN 4321
|
||||
#define G_PDP_ENDIAN 3412
|
||||
#ifdef __BYTE_ORDER__
|
||||
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
# define G_BYTE_ORDER G_LITTLE_ENDIAN
|
||||
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
# define G_BYTE_ORDER G_BIG_ENDIAN
|
||||
# elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
|
||||
# define G_BYTE_ORDER G_PDP_ENDIAN
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(G_BYTE_ORDER)
|
||||
/* Safe to assume LE for MSVC, as Windows is LE on all architectures. */
|
||||
# define G_BYTE_ORDER G_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# define G_OS_WIN32 1
|
||||
#else
|
||||
# define G_OS_UNIX 1
|
||||
#endif
|
||||
|
||||
#define G_SPAWN_SEARCH_PATH 0
|
||||
|
||||
#if defined(__LP64__) || defined(__LLP64__)
|
||||
# define GLIB_SIZEOF_VOID_P 8
|
||||
#else
|
||||
# define GLIB_SIZEOF_VOID_P 4
|
||||
#endif
|
||||
#ifdef __LP64__
|
||||
# define GLIB_SIZEOF_LONG 8
|
||||
# define GLIB_SIZEOF_SIZE_T 8
|
||||
# define GLIB_SIZEOF_SSIZE_T 8
|
||||
#else
|
||||
# define GLIB_SIZEOF_LONG 4
|
||||
# define GLIB_SIZEOF_SIZE_T 4
|
||||
# define GLIB_SIZEOF_SSIZE_T 4
|
||||
#endif
|
||||
|
||||
|
||||
/* Types */
|
||||
|
||||
#define gboolean int
|
||||
#define gchar char
|
||||
#define gint int
|
||||
#define gint16 int16_t
|
||||
#define gint32 int32_t
|
||||
#define gint64 int64_t
|
||||
#define glong long
|
||||
#define GPid void *
|
||||
#define gpointer void *
|
||||
#define gsize size_t
|
||||
#define GSpawnFlags void *
|
||||
#define GSpawnChildSetupFunc void *
|
||||
#define gssize ssize_t
|
||||
#define GString char
|
||||
#define GStrv char **
|
||||
#define guint unsigned int
|
||||
#define guint16 uint16_t
|
||||
#define guint32 uint32_t
|
||||
#define guint64 uint64_t
|
||||
|
||||
typedef struct _GDebugKey {
|
||||
char key[32];
|
||||
int val;
|
||||
} GDebugKey;
|
||||
|
||||
typedef struct _GError {
|
||||
char message[1];
|
||||
} GError;
|
||||
|
||||
typedef struct _GRand {
|
||||
uint8_t dummy;
|
||||
} GRand;
|
||||
|
||||
|
||||
/* Functions */
|
||||
/* Inlining everything is not the best idea, but it keeps TinyGLib
|
||||
contained to this header file without producing compiler warnings. */
|
||||
|
||||
/* Must be a function, as libslirp redefines it as a macro. */
|
||||
inline gboolean
|
||||
g_spawn_async_with_fds(const gchar *working_directory, gchar **argv,
|
||||
gchar **envp, GSpawnFlags flags,
|
||||
GSpawnChildSetupFunc child_setup,
|
||||
gpointer user_data, GPid *child_pid, gint stdin_fd,
|
||||
gint stdout_fd, gint stderr_fd, GError **error)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Needs bounds checking, but not really used by libslirp. */
|
||||
inline GString *
|
||||
g_string_new(gchar *base)
|
||||
{
|
||||
char *ret = malloc(4096);
|
||||
if (base)
|
||||
strcpy(ret, base);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
inline gchar *
|
||||
g_string_free(GString *string, gboolean free_segment)
|
||||
{
|
||||
return (free_segment ? NULL : string);
|
||||
}
|
||||
|
||||
|
||||
/* Implementation borrowed from GLib itself. */
|
||||
inline gchar *
|
||||
g_strstr_len(const gchar *haystack, gssize haystack_len, const gchar *needle)
|
||||
{
|
||||
if (haystack_len < 0)
|
||||
return strstr(haystack, needle);
|
||||
else {
|
||||
const gchar *p = haystack;
|
||||
gsize needle_len = strlen(needle);
|
||||
gsize haystack_len_unsigned = haystack_len;
|
||||
const gchar *end;
|
||||
gsize i;
|
||||
|
||||
if (needle_len == 0)
|
||||
return (gchar *) haystack;
|
||||
|
||||
if (haystack_len_unsigned < needle_len)
|
||||
return NULL;
|
||||
|
||||
end = haystack + haystack_len - needle_len;
|
||||
|
||||
while (p <= end && *p) {
|
||||
for (i = 0; i < needle_len; i++)
|
||||
if (p[i] != needle[i])
|
||||
goto next;
|
||||
|
||||
return (gchar *)p;
|
||||
|
||||
next:
|
||||
p++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Implementation borrowed from GLib itself. */
|
||||
inline guint
|
||||
g_strv_length(gchar **str_array)
|
||||
{
|
||||
guint i = 0;
|
||||
while (str_array[i] != NULL)
|
||||
++i;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
/* Macros */
|
||||
|
||||
#define tinyglib_pclog(f, s, ...) pclog("TinyGLib " f "(): " s "\n", ##__VA_ARGS__)
|
||||
|
||||
#define GLIB_CHECK_VERSION(a, b, c) 1
|
||||
#ifdef __GNUC__
|
||||
# define G_GNUC_PRINTF(format_idx, arg_idx) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
|
||||
#else
|
||||
# define G_GNUC_PRINTF(format_idx, arg_idx)
|
||||
#endif
|
||||
#define G_N_ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#define G_STATIC_ASSERT(e) /* this should probably do something */
|
||||
#define G_UNLIKELY(e) (e)
|
||||
|
||||
#define g_assert(e) do { if (!(e)) fatal("TinyGLib g_assert(" #e ")\n"); } while (0)
|
||||
#ifdef __GNUC__
|
||||
# define g_assert_not_reached __builtin_unreachable
|
||||
#else
|
||||
# ifdef _MSC_VER
|
||||
# define g_assert_not_reached() __assume(0)
|
||||
# else
|
||||
# define g_assert_not_reached()
|
||||
# endif
|
||||
#endif
|
||||
#define g_critical(s, ...) fatal("TinyGLib g_critical(): " s "\n", ##__VA_ARGS__)
|
||||
#ifdef TINYGLIB_DEBUG
|
||||
# define g_debug(s, ...) tinyglib_pclog("g_debug", s, ##__VA_ARGS__)
|
||||
#else
|
||||
# define g_debug(s, ...)
|
||||
#endif
|
||||
#define g_error(s, ...) tinyglib_pclog("g_error", s, ##__VA_ARGS__)
|
||||
#define g_error_free(err)
|
||||
#define g_malloc0(s) calloc(1, s)
|
||||
#define g_new(t, n) (t *) malloc(sizeof(t) * n)
|
||||
#define g_new0(t, n) (t *) calloc(n, sizeof(t))
|
||||
#ifdef TINYGLIB_DEBUG
|
||||
# define g_parse_debug_string(s, k, n) ((!!sizeof(k)) * -1) /* unimplemented; always enables all debug flags */
|
||||
#else
|
||||
# define g_parse_debug_string(s, k, n) (!sizeof(k))
|
||||
#endif
|
||||
#define g_rand_int_range(r, min, max) (rand() % (max + 1 - min) + min)
|
||||
#define g_rand_new() calloc(1, sizeof(GRand))
|
||||
#define g_return_val_if_fail(e, v) if (!(e)) return (v)
|
||||
#define g_shell_parse_argv(a, b, c, d) !!(sizeof(b)) /* unimplemented */
|
||||
#define g_warn_if_fail(e) do { if (!(e)) pclog("TinyGLib g_warn_if_fail(" #e ")\n"); } while (0)
|
||||
#define g_warn_if_reached() pclog("TinyGLib g_warn_if_reached()\n")
|
||||
#define g_warning(s, ...) tinyglib_pclog("g_warning", s, ##__VA_ARGS__)
|
||||
|
||||
|
||||
/* Remapped functions */
|
||||
#define g_free free
|
||||
#define g_getenv getenv
|
||||
#define g_malloc malloc
|
||||
#define g_rand_free free
|
||||
#define g_realloc realloc
|
||||
#define g_snprintf snprintf
|
||||
#define g_strdup strdup
|
||||
#define g_strerror strerror
|
||||
#define g_strfreev free
|
||||
#define g_string_append_printf sprintf /* unimplemented */
|
||||
#define g_vsnprintf vsnprintf
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user