18b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
28b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Copyright (c) 1995 Danny Gasparovski.
38b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *
48b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Please read the file COPYRIGHT for the
58b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * terms and conditions of the copyright.
68b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
78b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
88b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/* MINE */
98b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#ifndef _SLIRP_SOCKET_H_
118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define _SLIRP_SOCKET_H_
128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SO_EXPIRE 240000
148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SO_EXPIREFAST 10000
158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Our socket structure
188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectstruct socket {
218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  struct socket *so_next,*so_prev;      /* For a linked list of sockets */
228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  int s;                           /* The actual socket */
248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			/* XXX union these with not-yet-used sbuf params */
265d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  struct mbuf *so_m;	           /* Pointer to the original SYN packet,
278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project				    * for non-blocking connect()'s, and
288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project				    * PING reply's */
298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  struct tcpiphdr *so_ti;	   /* Pointer to the original ti within
308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project				    * so_mconn, for non-blocking connections */
318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  int so_urgc;
328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  uint32_t   so_faddr_ip;
338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  uint32_t   so_laddr_ip;
348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  uint16_t   so_faddr_port;
358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  uint16_t   so_laddr_port;
368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  uint16_t   so_haddr_port;
378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  u_int8_t	so_iptos;	/* Type of service */
398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  u_int8_t	so_emu;		/* Is the socket emulated? */
408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  u_char	so_type;		/* Type of socket, UDP or TCP */
428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  int	so_state;		/* internal state flags SS_*, below */
438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  struct 	tcpcb *so_tcpcb;	/* pointer to TCP protocol control block */
458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  u_int	so_expire;		/* When the socket will expire */
468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  int	so_queued;		/* Number of packets queued from this socket */
488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  int	so_nqueued;		/* Number of packets queued in a row
498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project				 * Used to determine when to "downgrade" a session
508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project					 * from fastq to batchq */
518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
525d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  struct sbuf so_rcv;		/* Receive buffer */
535d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  struct sbuf so_snd;		/* Send buffer */
548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void * extra;			/* Extra pointer */
558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project};
568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Socket state bits. (peer means the host on the Internet,
608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * local host means the host on the other end of the modem)
618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_NOFDREF		0x001	/* No fd reference */
638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_ISFCONNECTING	0x002	/* Socket is connecting to peer (non-blocking connect()'s) */
658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_ISFCONNECTED		0x004	/* Socket is connected to peer */
668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_FCANTRCVMORE		0x008	/* Socket can't receive more from peer (for half-closes) */
678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_FCANTSENDMORE	0x010	/* Socket can't send more to peer (for half-closes) */
688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/* #define SS_ISFDISCONNECTED	0x020*/	/* Socket has disconnected from peer, in 2MSL state */
698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_FWDRAIN		0x040	/* We received a FIN, drain data and set SS_FCANTSENDMORE */
708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_CTL			0x080
728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_FACCEPTCONN		0x100	/* Socket is accepting connections from a host on the internet */
738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_FACCEPTONCE		0x200	/* If set, the SS_FACCEPTCONN socket will die after one accept */
748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define SS_PROXIFIED            0x400   /* Socket is trying to connect through a proxy, only makes sense
758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project                                           when SS_ISFCONNECTING is also set */
768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
775d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerextern struct socket tcb;
788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid so_init _P((void));
808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectstruct socket * solookup _P((struct socket *, uint32_t, u_int, uint32_t, u_int));
818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectstruct socket * socreate _P((void));
828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid sofree _P((struct socket *));
838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectint soread _P((struct socket *));
848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid sorecvoob _P((struct socket *));
858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectint sosendoob _P((struct socket *));
868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectint sowrite _P((struct socket *));
878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid sorecvfrom _P((struct socket *));
885d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerint sosendto _P((struct socket *, struct mbuf *));
898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectstruct socket * solisten _P((u_int, u_int32_t, u_int, int));
908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectint  sounlisten _P((u_int port));
918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid soisfconnecting _P((register struct socket *));
928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid soisfconnected _P((register struct socket *));
938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid soisfdisconnected _P((struct socket *));
948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid sofwdrain _P((struct socket *));
955d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstruct iovec; /* For win32 */
965d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnersize_t sopreprbuf(struct socket *so, struct iovec *iov, int *np);
975d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerint soreadbuf(struct socket *so, const char *buf, int size);
988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif /* _SOCKET_H_ */
100