blob: 857b0da311b12caba5753b3fcc7155ace1c58172 [file] [log] [blame]
bellardf0cbd3e2004-04-22 00:10:48 +00001/*
2 * Copyright (c) 1995 Danny Gasparovski.
ths5fafdf22007-09-16 21:08:06 +00003 *
4 * Please read the file COPYRIGHT for the
bellardf0cbd3e2004-04-22 00:10:48 +00005 * terms and conditions of the copyright.
6 */
7
bellardf0cbd3e2004-04-22 00:10:48 +00008#ifndef _SLIRP_SOCKET_H_
9#define _SLIRP_SOCKET_H_
10
11#define SO_EXPIRE 240000
12#define SO_EXPIREFAST 10000
13
14/*
15 * Our socket structure
16 */
17
18struct socket {
19 struct socket *so_next,*so_prev; /* For a linked list of sockets */
20
21 int s; /* The actual socket */
22
Jan Kiszka460fec62009-06-24 14:42:31 +020023 Slirp *slirp; /* managing slirp instance */
24
bellardf0cbd3e2004-04-22 00:10:48 +000025 /* XXX union these with not-yet-used sbuf params */
26 struct mbuf *so_m; /* Pointer to the original SYN packet,
27 * for non-blocking connect()'s, and
28 * PING reply's */
29 struct tcpiphdr *so_ti; /* Pointer to the original ti within
30 * so_mconn, for non-blocking connections */
31 int so_urgc;
32 struct in_addr so_faddr; /* foreign host table entry */
33 struct in_addr so_laddr; /* local host table entry */
Stefan Weilb6dce922010-07-22 22:15:23 +020034 uint16_t so_fport; /* foreign port */
35 uint16_t so_lport; /* local port */
ths3b46e622007-09-17 08:09:54 +000036
Stefan Weilb6dce922010-07-22 22:15:23 +020037 uint8_t so_iptos; /* Type of service */
38 uint8_t so_emu; /* Is the socket emulated? */
ths3b46e622007-09-17 08:09:54 +000039
bellardf0cbd3e2004-04-22 00:10:48 +000040 u_char so_type; /* Type of socket, UDP or TCP */
41 int so_state; /* internal state flags SS_*, below */
ths3b46e622007-09-17 08:09:54 +000042
bellardf0cbd3e2004-04-22 00:10:48 +000043 struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */
44 u_int so_expire; /* When the socket will expire */
ths3b46e622007-09-17 08:09:54 +000045
bellardf0cbd3e2004-04-22 00:10:48 +000046 int so_queued; /* Number of packets queued from this socket */
47 int so_nqueued; /* Number of packets queued in a row
48 * Used to determine when to "downgrade" a session
49 * from fastq to batchq */
ths5fafdf22007-09-16 21:08:06 +000050
bellardf0cbd3e2004-04-22 00:10:48 +000051 struct sbuf so_rcv; /* Receive buffer */
52 struct sbuf so_snd; /* Send buffer */
53 void * extra; /* Extra pointer */
54};
55
56
57/*
58 * Socket state bits. (peer means the host on the Internet,
59 * local host means the host on the other end of the modem)
60 */
61#define SS_NOFDREF 0x001 /* No fd reference */
62
63#define SS_ISFCONNECTING 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */
64#define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */
65#define SS_FCANTRCVMORE 0x008 /* Socket can't receive more from peer (for half-closes) */
66#define SS_FCANTSENDMORE 0x010 /* Socket can't send more to peer (for half-closes) */
bellardf0cbd3e2004-04-22 00:10:48 +000067#define SS_FWDRAIN 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */
68
69#define SS_CTL 0x080
70#define SS_FACCEPTCONN 0x100 /* Socket is accepting connections from a host on the internet */
71#define SS_FACCEPTONCE 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */
72
Jan Kiszkaf932b6c2009-06-24 14:42:29 +020073#define SS_PERSISTENT_MASK 0xf000 /* Unremovable state bits */
Jan Kiszka6dd5ffb2009-06-24 14:42:29 +020074#define SS_HOSTFWD 0x1000 /* Socket describes host->guest forwarding */
Jan Kiszka4a823472009-06-24 14:42:29 +020075#define SS_INCOMING 0x2000 /* Connection was initiated by a host on the internet */
Jan Kiszkaf932b6c2009-06-24 14:42:29 +020076
Blue Swirl6cb9c6d2009-07-01 19:11:17 +000077struct socket * solookup(struct socket *, struct in_addr, u_int, struct in_addr, u_int);
78struct socket * socreate(Slirp *);
79void sofree(struct socket *);
80int soread(struct socket *);
81void sorecvoob(struct socket *);
82int sosendoob(struct socket *);
83int sowrite(struct socket *);
84void sorecvfrom(struct socket *);
85int sosendto(struct socket *, struct mbuf *);
Stefan Weilb6dce922010-07-22 22:15:23 +020086struct socket * tcp_listen(Slirp *, uint32_t, u_int, uint32_t, u_int,
Blue Swirl6cb9c6d2009-07-01 19:11:17 +000087 int);
88void soisfconnecting(register struct socket *);
89void soisfconnected(register struct socket *);
90void sofwdrain(struct socket *);
blueswir1b9e82a52009-04-05 18:03:31 +000091struct iovec; /* For win32 */
aliguorie1c5a2b2009-01-08 19:18:21 +000092size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np);
93int soreadbuf(struct socket *so, const char *buf, int size);
bellardf0cbd3e2004-04-22 00:10:48 +000094
95#endif /* _SOCKET_H_ */