00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef socket_info_h
00040 #define socket_info_h
00041
00042 #include "ip_addr.h"
00043 #include "dprint.h"
00044 #include "globals.h"
00045
00046
00047
00048
00049 #define MAX_SOCKET_STR (sizeof("unknown") - 1 + IP_ADDR_MAX_STR_SIZE + \
00050 INT2STR_MAX_LEN + 2 + 2)
00051
00052 int socket2str(char* s, int* len, struct socket_info* si);
00053 int socketinfo2str(char* s, int* len, struct socket_info* si, int mode);
00054
00055
00056
00057
00058 extern struct socket_info* udp_listen;
00059 #ifdef USE_TCP
00060 extern struct socket_info* tcp_listen;
00061 #endif
00062 #ifdef USE_TLS
00063 extern struct socket_info* tls_listen;
00064 #endif
00065 #ifdef USE_SCTP
00066 extern struct socket_info* sctp_listen;
00067 #endif
00068
00069 extern enum sip_protos nxt_proto[PROTO_LAST+1];
00070
00071
00072
00073
00074 #define SOCKET_T_IPV4 1
00075 #define SOCKET_T_IPV6 2
00076 #define SOCKET_T_UDP 4
00077 #define SOCKET_T_TCP 8
00078 #define SOCKET_T_TLS 16
00079 #define SOCKET_T_SCTP 32
00080
00081 extern int socket_types;
00082
00083 void init_proto_order(void);
00084
00085 int add_listen_iface(char* name, struct name_lst* nlst,
00086 unsigned short port, unsigned short proto,
00087 enum si_flags flags);
00088 int add_listen_advertise_iface(char* name, struct name_lst* nlst,
00089 unsigned short port, unsigned short proto,
00090 char *useaddr, unsigned short useport,
00091 enum si_flags flags);
00092 int fix_all_socket_lists(void);
00093 void print_all_socket_lists(void);
00094 void print_aliases(void);
00095
00096 struct socket_info* grep_sock_info(str* host, unsigned short port,
00097 unsigned short proto);
00098 struct socket_info* grep_sock_info_by_port(unsigned short port,
00099 unsigned short proto);
00100 struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
00101 unsigned short proto);
00102
00103 struct socket_info** get_sock_info_list(unsigned short proto);
00104
00105 int parse_phostport(char* s, char** host, int* hlen,
00106 int* port, int* proto);
00107
00108
00109
00110
00111
00112 static inline int next_proto(unsigned short proto)
00113 {
00114 if (proto>PROTO_LAST)
00115 LOG(L_ERR, "ERROR: next_proto: unknown proto %d\n", proto);
00116 else
00117 return nxt_proto[proto];
00118 return 0;
00119 }
00120
00121
00122
00123
00124
00125
00126 inline static struct socket_info* get_first_socket(void)
00127 {
00128 if (udp_listen) return udp_listen;
00129 #ifdef USE_TCP
00130 else if (tcp_listen) return tcp_listen;
00131 #endif
00132 #ifdef USE_SCTP
00133 else if (sctp_listen) return sctp_listen;
00134 #endif
00135 #ifdef USE_TCP
00136 #ifdef USE_TLS
00137 else if (tls_listen) return tls_listen;
00138 #endif
00139 #endif
00140 return 0;
00141 }
00142
00143
00144 #endif