updates.
[silc.git] / lib / silcutil / silcnet.h
1 /****h* silcutil/silcnet.h
2  *
3  * NAME
4  *
5  * silcnet.h
6  *
7  * COPYRIGHT
8  *
9  * Author: Pekka Riikonen <priikone@silcnet.org>
10  *
11  * Copyright (C) 1997 - 2001 Pekka Riikonen
12  *
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.
17  *
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.
22  *
23  */
24
25 #ifndef SILCNET_H
26 #define SILCNET_H
27
28 /* Prototypes */
29
30 /****f* silcutil/SilcNetAPI/silc_net_create_server
31  *
32  * SYNOPSIS
33  *
34  *    int silc_net_create_server(int port, char *ip_addr);
35  *
36  * DESCRIPTION
37  *
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.
43  *
44  ***/
45 int silc_net_create_server(int port, char *ip_addr);
46
47 /****f* silcutil/SilcNetAPI/silc_net_close_server
48  *
49  * SYNOPSIS
50  *
51  *    void silc_net_close_server(int sock);
52  *
53  * DESCRIPTION
54  *
55  *    Closes the server by closing the socket connection.
56  *
57  ***/
58 void silc_net_close_server(int sock);
59
60 /****f* silcutil/SilcNetAPI/silc_net_create_connection
61  *
62  * SYNOPSIS
63  *
64  *    int silc_net_create_connection(int port, char *host);
65  *
66  * DESCRIPTION
67  *
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
70  *    the connection.
71  *
72  ***/
73 int silc_net_create_connection(int port, char *host);
74
75 /****f* silcutil/SilcNetAPI/silc_net_create_connection_async
76  *
77  * SYNOPSIS
78  *
79  *    int silc_net_create_connection_async(int port, char *host);
80  *
81  * DESCRIPTION
82  *
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.
87  *
88  ***/
89 int silc_net_create_connection_async(int port, char *host);
90
91 /****f* silcutil/SilcNetAPI/silc_net_close_connection
92  *
93  * SYNOPSIS
94  *
95  *    void silc_net_close_connection(int sock);
96  *
97  * DESCRIPTION
98  *
99  *    Closes the connection by closing the socket connection.
100  *
101  ***/
102 void silc_net_close_connection(int sock);
103
104 /****f* silcutil/SilcNetAPI/silc_net_accept_connection
105  *
106  * SYNOPSIS
107  *
108  *    int silc_net_accept_connection(int sock);
109  *
110  * DESCRIPTION
111  *
112  *    Accepts a connection from a particular socket.
113  *
114  ***/
115 int silc_net_accept_connection(int sock);
116
117 /****f* silcutil/SilcNetAPI/silc_net_set_socket_opt
118  *
119  * SYNOPSIS
120  *
121  *    int silc_net_set_socket_opt(int sock, int level, int option, int on);
122  *
123  * DESCRIPTION
124  *
125  *    Sets a option for a socket.  This function can be used to set
126  *    various options for the socket.  Some of the options might be
127  *    system specific.
128  *
129  ***/
130 int silc_net_set_socket_opt(int sock, int level, int option, int on);
131
132 /****f* silcutil/SilcNetAPI/silc_net_is_ip
133  *
134  * SYNOPSIS
135  *
136  *    bool silc_net_is_ip(const char *addr);
137  *
138  * DESCRIPTION
139  *
140  *    Checks whether IP address sent as argument is valid IP address.
141  *
142  ***/
143 bool silc_net_is_ip(const char *addr);
144
145 /****f* silcutil/SilcNetAPI/silc_net_addr2bin
146  *
147  * SYNOPSIS
148  *
149  *    bool silc_net_addr2bin(const char *addr, unsigned char *bin,
150  *                           uint32 bin_len);
151  *
152  * DESCRIPTION
153  *
154  *    Converts the IP number string from numbers-and-dots notation to
155  *    binary form.
156  *
157  ***/
158 bool silc_net_addr2bin(const char *addr, unsigned char *bin,
159                        uint32 bin_len);
160
161 /****f* silcutil/SilcNetAPI/silc_net_check_host_by_sock
162  *
163  * SYNOPSIS
164  *
165  *    bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip);
166  *
167  * DESCRIPTION
168  *
169  *    Performs lookups for remote name and IP address. This peforms reverse
170  *    lookup as well to verify that the IP has FQDN.
171  *
172  ***/
173 bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip);
174
175 /****f* silcutil/SilcNetAPI/silc_net_check_local_by_sock
176  *
177  * SYNOPSIS
178  *
179  *    bool silc_net_check_local_by_sock(int sock, char **hostname, char **ip);
180  *
181  * DESCRIPTION
182  *
183  *    Performs lookups for local name and IP address. This peforms reverse
184  *    lookup as well to verify that the IP has FQDN.
185  *
186  ***/
187 bool silc_net_check_local_by_sock(int sock, char **hostname, char **ip);
188
189 /****f* silcutil/SilcNetAPI/silc_net_get_remote_port
190  *
191  * SYNOPSIS
192  *
193  *    uint16 silc_net_get_remote_port(int sock);
194  *
195  * DESCRIPTION
196  *
197  *    Return remote port by socket.
198  *
199  ***/
200 uint16 silc_net_get_remote_port(int sock);
201
202 /****f* silcutil/SilcNetAPI/silc_net_get_local_port
203  *
204  * SYNOPSIS
205  *
206  *    uint16 silc_net_get_local_port(int sock);
207  *
208  * DESCRIPTION
209  *
210  *    Return local port by socket.
211  *
212  ***/
213 uint16 silc_net_get_local_port(int sock);
214
215 /****f* silcutil/SilcNetAPI/silc_net_localhost
216  *
217  * SYNOPSIS
218  *
219  *    char *silc_net_localhost();
220  *
221  * DESCRIPTION
222  *
223  *    Return name of localhost.  This will also attempt to resolve
224  *    the real hostname by the local host's IP address.  If unsuccessful
225  *    the first found hostname is returned.
226  *
227  ***/
228 char *silc_net_localhost();
229
230 #endif