1 /****h* silcutil/silcnet.h
9 * Author: Pekka Riikonen <priikone@silcnet.org>
11 * Copyright (C) 1997 - 2001 Pekka Riikonen
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
30 /****f* silcutil/SilcNetAPI/silc_net_create_server
34 * int silc_net_create_server(int port, char *ip_addr);
38 * This function creates server or daemon or listener or what ever. This
39 * does not fork a new process, it must be done by the caller if caller
40 * wants to create a child process. This is used by the SILC server.
41 * If argument `ip_addr' is NULL `any' address will be used. Returns
42 * the created socket or -1 on error.
45 int silc_net_create_server(int port, char *ip_addr);
47 /****f* silcutil/SilcNetAPI/silc_net_close_server
51 * void silc_net_close_server(int sock);
55 * Closes the server by closing the socket connection.
58 void silc_net_close_server(int sock);
60 /****f* silcutil/SilcNetAPI/silc_net_create_connection
64 * int silc_net_create_connection(int port, char *host);
68 * Creates a connection (TCP/IP) to a remote host. Returns the connection
69 * socket or -1 on error. This blocks the process while trying to create
73 int silc_net_create_connection(int port, char *host);
75 /****f* silcutil/SilcNetAPI/silc_net_create_connection_async
79 * int silc_net_create_connection_async(int port, char *host);
83 * Creates a connection (TCP/IP) to a remote host. Returns the connection
84 * socket or -1 on error. This creates non-blocking socket hence the
85 * connection returns directly. To get the result of the connect() one
86 * must select() the socket and read the result after it's ready.
89 int silc_net_create_connection_async(int port, char *host);
91 /****f* silcutil/SilcNetAPI/silc_net_close_connection
95 * void silc_net_close_connection(int sock);
99 * Closes the connection by closing the socket connection.
102 void silc_net_close_connection(int sock);
104 /****f* silcutil/SilcNetAPI/silc_net_accept_connection
108 * int silc_net_accept_connection(int sock);
112 * Accepts a connection from a particular socket.
115 int silc_net_accept_connection(int sock);
117 /****f* silcutil/SilcNetAPI/silc_net_set_socket_nonblock
121 * int silc_net_set_socket_nonblock(int sock);
125 * Sets the socket to non-blocking mode.
128 int silc_net_set_socket_nonblock(int sock);
130 /****f* silcutil/SilcNetAPI/silc_net_set_socket_opt
134 * int silc_net_set_socket_opt(int sock, int level, int option, int on);
138 * Sets a option for a socket. This function can be used to set
139 * various options for the socket. Some of the options might be
143 int silc_net_set_socket_opt(int sock, int level, int option, int on);
145 /****f* silcutil/SilcNetAPI/silc_net_get_socket_opt
149 * int silc_net_get_socket_opt(int sock, int level, int option,
150 * void *optval, int *opt_len);
154 * Return socket options to the `optval' and `opt_len'.
157 int silc_net_get_socket_opt(int sock, int level, int option,
158 void *optval, int *opt_len);
160 /****f* silcutil/SilcNetAPI/silc_net_is_ip
164 * bool silc_net_is_ip(const char *addr);
168 * Checks whether IP address sent as argument is valid IP address.
171 bool silc_net_is_ip(const char *addr);
173 /****f* silcutil/SilcNetAPI/silc_net_addr2bin
177 * bool silc_net_addr2bin(const char *addr, unsigned char *bin,
182 * Converts the IP number string from numbers-and-dots notation to
186 bool silc_net_addr2bin(const char *addr, unsigned char *bin,
189 /****f* silcutil/SilcNetAPI/silc_net_check_host_by_sock
193 * bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip);
197 * Performs lookups for remote name and IP address. This peforms reverse
198 * lookup as well to verify that the IP has FQDN.
201 bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip);
203 /****f* silcutil/SilcNetAPI/silc_net_check_local_by_sock
207 * bool silc_net_check_local_by_sock(int sock, char **hostname, char **ip);
211 * Performs lookups for local name and IP address. This peforms reverse
212 * lookup as well to verify that the IP has FQDN.
215 bool silc_net_check_local_by_sock(int sock, char **hostname, char **ip);
217 /****f* silcutil/SilcNetAPI/silc_net_get_remote_port
221 * uint16 silc_net_get_remote_port(int sock);
225 * Return remote port by socket.
228 uint16 silc_net_get_remote_port(int sock);
230 /****f* silcutil/SilcNetAPI/silc_net_get_local_port
234 * uint16 silc_net_get_local_port(int sock);
238 * Return local port by socket.
241 uint16 silc_net_get_local_port(int sock);
243 /****f* silcutil/SilcNetAPI/silc_net_localhost
247 * char *silc_net_localhost();
251 * Return name of localhost. This will also attempt to resolve
252 * the real hostname by the local host's IP address. If unsuccessful
253 * the first found hostname is returned.
256 char *silc_net_localhost();