Home | History | Annotate | Download | only in slirp-android
      1 #ifndef _LIBSLIRP_H
      2 #define _LIBSLIRP_H
      3 
      4 #include <stdint.h>
      5 #include <stdio.h>
      6 #include "android/sockets.h"
      7 #include "slirp.h"
      8 #ifdef _WIN32
      9 #  define WIN32_LEAN_AND_MEAN
     10 #  define socket_close  winsock2_socket_close3
     11 #  include <winsock2.h>
     12 #  undef socket_close
     13 #else
     14 #  include <sys/select.h>
     15 #endif
     16 
     17 #ifdef __cplusplus
     18 extern "C" {
     19 #endif
     20 
     21 struct mbuf;
     22 
     23 int    inet_strtoip(const char*  str, uint32_t  *ip);
     24 char*  inet_iptostr(uint32_t  ip);
     25 
     26 void slirp_init(int restricted, const char *special_ip);
     27 
     28 void slirp_select_fill(int *pnfds,
     29                        fd_set *readfds, fd_set *writefds, fd_set *xfds);
     30 
     31 void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds);
     32 
     33 void slirp_input(const uint8_t *pkt, int pkt_len);
     34 
     35 /* you must provide the following functions: */
     36 int slirp_can_output(void);
     37 void slirp_output(const uint8_t *pkt, int pkt_len);
     38 
     39 /* ---------------------------------------------------*/
     40 /* User mode network stack restrictions */
     41 void slirp_drop_udp();
     42 void slirp_drop_tcp();
     43 void slirp_add_allow(unsigned long dst_addr, int dst_lport,
     44                      int dst_hport, u_int8_t proto);
     45 void slirp_drop_log_fd(FILE* fd);
     46 
     47 /** Get the drop log fd */
     48 FILE* get_slirp_drop_log_fd(void);
     49 int slirp_should_drop(unsigned long dst_addr,
     50                       int dst_port,
     51                       u_int8_t proto);
     52 int slirp_drop_log(const char* format, ...);
     53 
     54 /* for network forwards */
     55 void slirp_add_net_forward(unsigned long dest_ip, unsigned long dest_mask,
     56                            int dest_lport, int dest_hport,
     57                            unsigned long redirect_ip, int redirect_port);
     58 
     59 int slirp_should_net_forward(unsigned long remote_ip, int remote_port,
     60                              unsigned long *redirect_ip, int *redirect_port);
     61 /* ---------------------------------------------------*/
     62 
     63 /**
     64  * Additional network stack modifications, aiming to detect and log
     65  * any network activity initiated by any binary outisde the context of
     66  * the running browser.
     67  */
     68 
     69 void slirp_dns_log_fd(FILE* fd);
     70 /** Get the dns log fd */
     71 FILE* get_slirp_dns_log_fd(void);
     72 /** Logs the DNS name in DNS query issued by the VM. */
     73 int slirp_log_dns(struct mbuf* m, int dropped);
     74 /** IP packet dump of DNS queris and responses. */
     75 int slirp_dump_dns(struct mbuf* m);
     76 /** Sets an upper limit for the number of allowed DNS requests from
     77  * the VM.
     78  */
     79 void slirp_set_max_dns_conns(int max_dns_conns);
     80 /* Returns the max number of allowed DNS requests.*/
     81 int slirp_get_max_dns_conns();
     82 
     83 /**
     84  * Modifications for implementing "-net-forward-tcp2sink' option.
     85  */
     86 
     87 void slirp_forward_dropped_tcp2sink(unsigned long sink_ip,  int sink_port);
     88 int slirp_should_forward_dropped_tcp2sink();
     89 unsigned long slirp_get_tcp_sink_ip();
     90 int slirp_get_tcp_sink_port();
     91 
     92 
     93 
     94 
     95 /* ---------------------------------------------------*/
     96 
     97 void slirp_redir_loop(void (*func)(void *opaque, int is_udp,
     98                                    const SockAddress *laddr,
     99                                    const SockAddress *faddr),
    100                      void *opaque);
    101 int slirp_redir_rm(int is_udp, int host_port);
    102 int slirp_redir(int is_udp, int host_port,
    103                 uint32_t guest_addr, int guest_port);
    104 
    105 int slirp_unredir(int is_udp, int host_port);
    106 
    107 int slirp_add_dns_server(const SockAddress*  dns_addr);
    108 int slirp_get_system_dns_servers(void);
    109 int slirp_add_exec(int do_pty, const void *args, int addr_low_byte,
    110                    int guest_port);
    111 
    112 extern const char *tftp_prefix;
    113 extern char slirp_hostname[33];
    114 extern const char *bootp_filename;
    115 
    116 void slirp_stats(void);
    117 void slirp_socket_recv(int addr_low_byte, int guest_port, const uint8_t *buf,
    118 		int size);
    119 size_t slirp_socket_can_recv(int addr_low_byte, int guest_port);
    120 
    121 #ifdef __cplusplus
    122 }
    123 #endif
    124 
    125 #endif
    126