2019-05-01 16:22:22 -04:00
|
|
|
#ifndef IRSSI_CORE_NETWORK_H
|
|
|
|
#define IRSSI_CORE_NETWORK_H
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-18 16:39:24 -05:00
|
|
|
#ifdef HAVE_SOCKS_H
|
|
|
|
#include <socks.h>
|
|
|
|
#endif
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
#include <sys/types.h>
|
2000-10-26 14:12:20 -04:00
|
|
|
# include <sys/socket.h>
|
|
|
|
# include <netinet/in.h>
|
2001-03-18 16:39:24 -05:00
|
|
|
# include <netdb.h>
|
|
|
|
# include <arpa/inet.h>
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-02-20 22:46:27 -05:00
|
|
|
#ifndef AF_INET6
|
|
|
|
# ifdef PF_INET6
|
|
|
|
# define AF_INET6 PF_INET6
|
|
|
|
# else
|
2001-02-23 00:55:51 -05:00
|
|
|
# define AF_INET6 10
|
2001-02-20 22:46:27 -05:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2001-01-01 02:45:54 -05:00
|
|
|
struct _IPADDR {
|
2000-04-26 04:03:38 -04:00
|
|
|
unsigned short family;
|
2001-03-03 22:00:35 -05:00
|
|
|
struct in6_addr ip;
|
2000-04-26 04:03:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* maxmimum string length of IP address */
|
2016-01-27 08:31:55 -05:00
|
|
|
#define MAX_IP_LEN INET6_ADDRSTRLEN
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-03 20:47:13 -05:00
|
|
|
#define IPADDR_IS_V6(ip) ((ip)->family != AF_INET)
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2003-07-09 19:34:41 -04:00
|
|
|
extern IPADDR ip4_any;
|
|
|
|
|
2010-04-03 16:04:15 -04:00
|
|
|
GIOChannel *g_io_channel_new(int handle);
|
|
|
|
|
2017-10-13 21:30:57 -04:00
|
|
|
/* Returns 1 if IPADDRs are the same. */
|
|
|
|
/* Deprecated since it is unused. It will be deleted in a later release. */
|
|
|
|
int net_ip_compare(IPADDR *ip1, IPADDR *ip2) G_GNUC_DEPRECATED;
|
2015-01-03 19:57:21 -05:00
|
|
|
int g_io_channel_write_block(GIOChannel *channel, void *data, int len);
|
|
|
|
int g_io_channel_read_block(GIOChannel *channel, void *data, int len);
|
2017-10-13 21:28:26 -04:00
|
|
|
|
2017-07-28 13:44:18 -04:00
|
|
|
int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip);
|
2017-07-27 09:20:47 -04:00
|
|
|
|
2002-08-26 15:32:15 -04:00
|
|
|
/* Connect to socket with ip address and SSL*/
|
2013-06-23 19:50:26 -04:00
|
|
|
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server);
|
2017-01-16 14:04:11 -05:00
|
|
|
/* Start TLS */
|
|
|
|
GIOChannel *net_start_ssl(SERVER_REC *server);
|
|
|
|
|
2007-05-31 19:56:51 -04:00
|
|
|
int irssi_ssl_handshake(GIOChannel *handle);
|
2000-04-26 04:03:38 -04:00
|
|
|
/* Connect to socket with ip address */
|
2002-08-26 15:05:14 -04:00
|
|
|
GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip);
|
2002-05-19 10:43:16 -04:00
|
|
|
/* Connect to named UNIX socket */
|
2002-08-26 15:05:14 -04:00
|
|
|
GIOChannel *net_connect_unix(const char *path);
|
2000-04-26 04:03:38 -04:00
|
|
|
/* Disconnect socket */
|
2000-12-04 17:57:18 -05:00
|
|
|
void net_disconnect(GIOChannel *handle);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
/* Listen for connections on a socket */
|
2000-12-04 17:57:18 -05:00
|
|
|
GIOChannel *net_listen(IPADDR *my_ip, int *port);
|
2000-04-26 04:03:38 -04:00
|
|
|
/* Accept a connection on a socket */
|
2000-12-04 17:57:18 -05:00
|
|
|
GIOChannel *net_accept(GIOChannel *handle, IPADDR *addr, int *port);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
/* Read data from socket, return number of bytes read, -1 = error */
|
2000-12-04 17:57:18 -05:00
|
|
|
int net_receive(GIOChannel *handle, char *buf, int len);
|
2000-04-26 04:03:38 -04:00
|
|
|
/* Transmit data, return number of bytes sent, -1 = error */
|
2000-12-04 17:57:18 -05:00
|
|
|
int net_transmit(GIOChannel *handle, const char *data, int len);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-03 20:47:13 -05:00
|
|
|
/* Get IP addresses for host, both IPv4 and IPv6 if possible.
|
|
|
|
If ip->family is 0, the address wasn't found.
|
|
|
|
Returns 0 = ok, others = error code for net_gethosterror() */
|
2015-09-22 15:59:17 -04:00
|
|
|
int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6);
|
2000-05-25 07:30:47 -04:00
|
|
|
/* Get name for host, *name should be g_free()'d unless it's NULL.
|
|
|
|
Return values are the same as with net_gethostbyname() */
|
|
|
|
int net_gethostbyaddr(IPADDR *ip, char **name);
|
2000-04-26 04:03:38 -04:00
|
|
|
/* get error of net_gethostname() */
|
|
|
|
const char *net_gethosterror(int error);
|
2000-07-02 07:56:38 -04:00
|
|
|
/* return TRUE if host lookup failed because it didn't exist (ie. not
|
|
|
|
some error with name server) */
|
|
|
|
int net_hosterror_notfound(int error);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
/* Get socket address/port */
|
2000-12-04 17:57:18 -05:00
|
|
|
int net_getsockname(GIOChannel *handle, IPADDR *addr, int *port);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-12-19 12:48:42 -05:00
|
|
|
/* IPADDR -> char* translation. `host' must be at least MAX_IP_LEN bytes */
|
2000-04-26 04:03:38 -04:00
|
|
|
int net_ip2host(IPADDR *ip, char *host);
|
2000-12-19 12:48:42 -05:00
|
|
|
/* char* -> IPADDR translation. */
|
2000-04-26 04:03:38 -04:00
|
|
|
int net_host2ip(const char *host, IPADDR *ip);
|
|
|
|
|
|
|
|
/* Get socket error */
|
2000-12-04 17:57:18 -05:00
|
|
|
int net_geterror(GIOChannel *handle);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:23:35 -05:00
|
|
|
/* Get name of TCP service */
|
|
|
|
char *net_getservbyport(int port);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
int is_ipv4_address(const char *host);
|
|
|
|
int is_ipv6_address(const char *host);
|
|
|
|
|
|
|
|
#endif
|