⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socket.h

📁 OpenVPN is a robust and highly flexible tunneling application that uses all of the encryption, authe
💻 H
📖 第 1 页 / 共 2 页
字号:
/* *  OpenVPN -- An application to securely tunnel IP networks *             over a single TCP/UDP port, with support for SSL/TLS-based *             session authentication and key exchange, *             packet encryption, packet authentication, and *             packet compression. * *  Copyright (C) 2002-2004 James Yonan <jim@yonan.net> * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program (see the file COPYING included with this *  distribution); if not, write to the Free Software Foundation, Inc., *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#ifndef SOCKET_H#define SOCKET_H#include "buffer.h"#include "common.h"#include "error.h"#include "mtu.h"#include "win32.h"#include "event.h"#include "proxy.h"#include "socks.h"#define REMOTE_LIST_SIZE 64struct remote_entry{  const char *hostname;  int port;};struct remote_list{  int len;  int current;  struct remote_entry array[REMOTE_LIST_SIZE];};/*  * packet_size_type is used communicate packet size * over the wire when stream oriented protocols are * being used */typedef uint16_t packet_size_type;/* convert a packet_size_type from host to network order */#define htonps(x) htons(x)/* convert a packet_size_type from network to host order */#define ntohps(x) ntohs(x)/* IP addresses which are persistant across SIGUSR1s */struct link_socket_addr{  struct sockaddr_in local;  struct sockaddr_in remote; /* initial remote */  struct sockaddr_in actual; /* remote may change due to --float */};struct link_socket_info{  struct link_socket_addr *lsa;  bool connection_established;  const char *ipchange_command;  bool remote_float;    int proto;                    /* Protocol (PROTO_x defined below) */  int mtu_changed;              /* Set to true when mtu value is changed */};/* * Used to extract packets encapsulated in streams into a buffer, * in this case IP packets embedded in a TCP stream. */struct stream_buf{  struct buffer buf_init;  struct buffer residual;  int maxlen;  bool residual_fully_formed;  struct buffer buf;  struct buffer next;  int len;     /* -1 if not yet known */  bool error;  /* if true, fatal TCP error has occurred,		  requiring that connection be restarted */};/* * Used to set socket buffer sizes */struct socket_buffer_size{  int rcvbuf;  int sndbuf;};/* * This is the main socket structure used by OpenVPN.  The SOCKET_ * defines try to abstract away our implementation differences between * using sockets on Posix vs. Win32. */struct link_socket{  struct link_socket_info info;  socket_descriptor_t sd;  socket_descriptor_t ctrl_sd;  /* only used for UDP over Socks */#ifdef WIN32  struct overlapped_io reads;  struct overlapped_io writes;  struct rw_handle rw_handle;#endif  /* used for printing status info only */  unsigned int rwflags;  /* set on initial call to init phase 1 */  struct remote_list *remote_list;  const char *remote_host;  int remote_port;  const char *local_host;  int local_port;  bool bind_local;# define INETD_NONE   0# define INETD_WAIT   1# define INETD_NOWAIT 2  int inetd;# define LS_MODE_DEFAULT           0# define LS_MODE_TCP_LISTEN        1# define LS_MODE_TCP_ACCEPT_FROM   2  int mode;  int resolve_retry_seconds;  int connect_retry_seconds;  int mtu_discover_type;  struct socket_buffer_size socket_buffer_sizes;  int mtu;                      /* OS discovered MTU, or 0 if unknown */  bool did_resolve_remote;  /* for stream sockets */  struct stream_buf stream_buf;  struct buffer stream_buf_data;  bool stream_reset;  /* HTTP proxy */  struct http_proxy_info *http_proxy;  /* Socks proxy */  struct socks_proxy_info *socks_proxy;  struct sockaddr_in socks_relay; /* Socks UDP relay address */  /* The OpenVPN server we will use the proxy to connect to */  const char *proxy_dest_host;  int proxy_dest_port;};/* * Some Posix/Win32 differences. */#ifndef MSG_NOSIGNAL#define MSG_NOSIGNAL 0#endif#ifdef WIN32#define ECONNRESET WSAECONNRESET#define openvpn_close_socket(s) closesocket(s)int inet_aton (const char *name, struct in_addr *addr);int socket_recv_queue (struct link_socket *sock, int maxsize);int socket_send_queue (struct link_socket *sock,		       struct buffer *buf,		       const struct sockaddr_in *to);int socket_finalize (		     SOCKET s,		     struct overlapped_io *io,		     struct buffer *buf,		     struct sockaddr_in *from);#else#define openvpn_close_socket(s) close(s)#endifstruct link_socket *link_socket_new (void);/* * Initialize link_socket object. */voidlink_socket_init_phase1 (struct link_socket *sock,			 const char *local_host,			 struct remote_list *remote_list,			 int local_port,			 int proto,			 int mode,			 const struct link_socket *accept_from,			 struct http_proxy_info *http_proxy,			 struct socks_proxy_info *socks_proxy,			 bool bind_local,			 bool remote_float,			 int inetd,			 struct link_socket_addr *lsa,			 const char *ipchange_command,			 int resolve_retry_seconds,			 int connect_retry_seconds,			 int mtu_discover_type,			 int rcvbuf,			 int sndbuf);void link_socket_init_phase2 (struct link_socket *sock,			      const struct frame *frame,			      volatile int *signal_received);void link_socket_post_fork (const struct link_socket *sock,			    const struct sockaddr_in *remote);void socket_adjust_frame_parameters (struct frame *frame, int proto);void frame_adjust_path_mtu (struct frame *frame, int pmtu, int proto);void link_socket_close (struct link_socket *sock);const char *print_sockaddr_ex (const struct sockaddr_in *addr,			       bool do_port,			       const char* separator,			       struct gc_arena *gc);const char *print_sockaddr (const struct sockaddr_in *addr,			    struct gc_arena *gc);const char *print_in_addr_t (in_addr_t addr,			     bool empty_if_undef,			     struct gc_arena *gc);void setenv_sockaddr (const char *name_prefix,		      const struct sockaddr_in *addr);void setenv_in_addr_t (const char *name_prefix, in_addr_t addr);void bad_address_length (int actual, int expected);in_addr_t link_socket_current_remote (const struct link_socket_info *info);void link_socket_connection_initiated (const struct buffer *buf,				       struct link_socket_info *info,				       const struct sockaddr_in *addr,				       const char *common_name);void link_socket_bad_incoming_addr (struct buffer *buf,				    const struct link_socket_info *info,				    const struct sockaddr_in *from_addr);void link_socket_bad_outgoing_addr (void);void setenv_trusted (const struct link_socket_info *info);void remote_list_randomize (struct remote_list *l);/* * DNS resolution */#define GETADDR_RESOLVE               (1<<0)#define GETADDR_FATAL                 (1<<1)#define GETADDR_HOST_ORDER            (1<<2)#define GETADDR_MENTION_RESOLVE_RETRY (1<<3)#define GETADDR_FATAL_ON_SIGNAL       (1<<4)#define GETADDR_WARN_ON_SIGNAL        (1<<5)in_addr_t getaddr (unsigned int flags,		   const char *hostname,		   int resolve_retry_seconds,		   bool *succeeded,		   volatile int *signal_received);/* * Transport protocol naming and other details. */#define PROTO_UDPv4        0#define PROTO_TCPv4_SERVER 1#define PROTO_TCPv4_CLIENT 2#define PROTO_N            3int ascii2proto (const char* proto_name);const char *proto2ascii (int proto, bool display_form);const char *proto2ascii_all (struct gc_arena *gc);int proto_remote (int proto, bool remote);/* * Overhead added to packets by various protocols. */#define IPv4_UDP_HEADER_SIZE              28#define IPv4_TCP_HEADER_SIZE              40#define IPv6_UDP_HEADER_SIZE              40static const int proto_overhead[] = { /* indexed by PROTO_x */  IPv4_UDP_HEADER_SIZE,  IPv4_TCP_HEADER_SIZE,  IPv4_TCP_HEADER_SIZE};static inline intdatagram_overhead (int proto){  ASSERT (proto >= 0 && proto < PROTO_N);  return proto_overhead [proto];}/* * Misc inline functions */static inline intremote_list_len (const struct remote_list *rl){  if (rl)    return rl->len;  else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -