2 * Copyright (c) 1995 Danny Gasparovski.
4 * Please read the file COPYRIGHT for the
5 * terms and conditions of the copyright.
8 #ifndef _SLIRP_SOCKET_H_
9 #define _SLIRP_SOCKET_H_
11 #define SO_EXPIRE 240000
12 #define SO_EXPIREFAST 10000
15 * Our socket structure
19 struct socket
*so_next
,*so_prev
; /* For a linked list of sockets */
21 int s
; /* The actual socket */
23 int pollfds_idx
; /* GPollFD GArray index */
25 Slirp
*slirp
; /* managing slirp instance */
27 /* XXX union these with not-yet-used sbuf params */
28 struct mbuf
*so_m
; /* Pointer to the original SYN packet,
29 * for non-blocking connect()'s, and
31 struct tcpiphdr
*so_ti
; /* Pointer to the original ti within
32 * so_mconn, for non-blocking connections */
34 union { /* foreign host */
35 struct sockaddr_storage ss
;
36 struct sockaddr_in sin
;
38 #define so_faddr fhost.sin.sin_addr
39 #define so_fport fhost.sin.sin_port
40 #define so_ffamily fhost.ss.ss_family
42 union { /* local host */
43 struct sockaddr_storage ss
;
44 struct sockaddr_in sin
;
46 #define so_laddr lhost.sin.sin_addr
47 #define so_lport lhost.sin.sin_port
48 #define so_lfamily lhost.ss.ss_family
50 uint8_t so_iptos
; /* Type of service */
51 uint8_t so_emu
; /* Is the socket emulated? */
53 u_char so_type
; /* Type of socket, UDP or TCP */
54 int so_state
; /* internal state flags SS_*, below */
56 struct tcpcb
*so_tcpcb
; /* pointer to TCP protocol control block */
57 u_int so_expire
; /* When the socket will expire */
59 int so_queued
; /* Number of packets queued from this socket */
60 int so_nqueued
; /* Number of packets queued in a row
61 * Used to determine when to "downgrade" a session
62 * from fastq to batchq */
64 struct sbuf so_rcv
; /* Receive buffer */
65 struct sbuf so_snd
; /* Send buffer */
66 void * extra
; /* Extra pointer */
71 * Socket state bits. (peer means the host on the Internet,
72 * local host means the host on the other end of the modem)
74 #define SS_NOFDREF 0x001 /* No fd reference */
76 #define SS_ISFCONNECTING 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */
77 #define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */
78 #define SS_FCANTRCVMORE 0x008 /* Socket can't receive more from peer (for half-closes) */
79 #define SS_FCANTSENDMORE 0x010 /* Socket can't send more to peer (for half-closes) */
80 #define SS_FWDRAIN 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */
83 #define SS_FACCEPTCONN 0x100 /* Socket is accepting connections from a host on the internet */
84 #define SS_FACCEPTONCE 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */
86 #define SS_PERSISTENT_MASK 0xf000 /* Unremovable state bits */
87 #define SS_HOSTFWD 0x1000 /* Socket describes host->guest forwarding */
88 #define SS_INCOMING 0x2000 /* Connection was initiated by a host on the internet */
90 static inline int sockaddr_equal(struct sockaddr_storage
*a
,
91 struct sockaddr_storage
*b
)
93 if (a
->ss_family
!= b
->ss_family
) {
97 switch (a
->ss_family
) {
100 struct sockaddr_in
*a4
= (struct sockaddr_in
*) a
;
101 struct sockaddr_in
*b4
= (struct sockaddr_in
*) b
;
102 return a4
->sin_addr
.s_addr
== b4
->sin_addr
.s_addr
103 && a4
->sin_port
== b4
->sin_port
;
106 g_assert_not_reached();
112 struct socket
*solookup(struct socket
**, struct socket
*,
113 struct sockaddr_storage
*, struct sockaddr_storage
*);
114 struct socket
*socreate(Slirp
*);
115 void sofree(struct socket
*);
116 int soread(struct socket
*);
117 void sorecvoob(struct socket
*);
118 int sosendoob(struct socket
*);
119 int sowrite(struct socket
*);
120 void sorecvfrom(struct socket
*);
121 int sosendto(struct socket
*, struct mbuf
*);
122 struct socket
* tcp_listen(Slirp
*, uint32_t, u_int
, uint32_t, u_int
,
124 void soisfconnecting(register struct socket
*);
125 void soisfconnected(register struct socket
*);
126 void sofwdrain(struct socket
*);
127 struct iovec
; /* For win32 */
128 size_t sopreprbuf(struct socket
*so
, struct iovec
*iov
, int *np
);
129 int soreadbuf(struct socket
*so
, const char *buf
, int size
);
131 void sotranslate_out(struct socket
*, struct sockaddr_storage
*);
132 void sotranslate_in(struct socket
*, struct sockaddr_storage
*);
133 void sotranslate_accept(struct socket
*);
136 #endif /* _SOCKET_H_ */