]> Git Repo - qemu.git/blob - slirp/socket.h
Merge remote-tracking branch 'remotes/mcayland/tags/qemu-openbios-signed' into staging
[qemu.git] / slirp / socket.h
1 /*
2  * Copyright (c) 1995 Danny Gasparovski.
3  *
4  * Please read the file COPYRIGHT for the
5  * terms and conditions of the copyright.
6  */
7
8 #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
18 struct socket {
19   struct socket *so_next,*so_prev;      /* For a linked list of sockets */
20
21   int s;                           /* The actual socket */
22
23   int pollfds_idx;                 /* GPollFD GArray index */
24
25   Slirp *slirp;                    /* managing slirp instance */
26
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
30                                     * PING reply's */
31   struct tcpiphdr *so_ti;          /* Pointer to the original ti within
32                                     * so_mconn, for non-blocking connections */
33   int so_urgc;
34   union {   /* foreign host */
35       struct sockaddr_storage ss;
36       struct sockaddr_in sin;
37   } fhost;
38 #define so_faddr fhost.sin.sin_addr
39 #define so_fport fhost.sin.sin_port
40 #define so_ffamily fhost.ss.ss_family
41
42   union {   /* local host */
43       struct sockaddr_storage ss;
44       struct sockaddr_in sin;
45   } lhost;
46 #define so_laddr lhost.sin.sin_addr
47 #define so_lport lhost.sin.sin_port
48 #define so_lfamily lhost.ss.ss_family
49
50   uint8_t       so_iptos;       /* Type of service */
51   uint8_t       so_emu;         /* Is the socket emulated? */
52
53   u_char        so_type;                /* Type of socket, UDP or TCP */
54   int   so_state;               /* internal state flags SS_*, below */
55
56   struct        tcpcb *so_tcpcb;        /* pointer to TCP protocol control block */
57   u_int so_expire;              /* When the socket will expire */
58
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 */
63
64   struct sbuf so_rcv;           /* Receive buffer */
65   struct sbuf so_snd;           /* Send buffer */
66   void * extra;                 /* Extra pointer */
67 };
68
69
70 /*
71  * Socket state bits. (peer means the host on the Internet,
72  * local host means the host on the other end of the modem)
73  */
74 #define SS_NOFDREF              0x001   /* No fd reference */
75
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 */
81
82 #define SS_CTL                  0x080
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 */
85
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 */
89
90 static inline int sockaddr_equal(struct sockaddr_storage *a,
91         struct sockaddr_storage *b)
92 {
93     if (a->ss_family != b->ss_family) {
94         return 0;
95     }
96
97     switch (a->ss_family) {
98     case AF_INET:
99     {
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;
104     }
105     default:
106         g_assert_not_reached();
107     }
108
109     return 0;
110 }
111
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,
123                                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);
130
131 void sotranslate_out(struct socket *, struct sockaddr_storage *);
132 void sotranslate_in(struct socket *, struct sockaddr_storage *);
133 void sotranslate_accept(struct socket *);
134
135
136 #endif /* _SOCKET_H_ */
This page took 0.032139 seconds and 4 git commands to generate.