Documentation updates
[runtime.git] / lib / silcutil / silcnet.h
1 /*
2
3   silcnet.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2008 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcutil/Network Interface
21  *
22  * DESCRIPTION
23  *
24  * SILC Net API provides various network routines for applications. It can
25  * be used to create TCP/IP and UDP/IP connections and listeners.  Various
26  * utility functions for resolving various information is also provided.
27  * The interface supports both IPv4 and IPv6.
28  *
29  * EXAMPLE
30  *
31  * // Create TCP connection to example.com at port 25
32  * silc_net_tcp_connect(NULL, "example.com", 25, schedule, connected_cb, ctx);
33  *
34  * // Create UDP listener on local interface 10.2.1.7 on port 500
35  * SilcStream udpstream;
36  *
37  * udpstream = silc_net_udp_connect("10.2.1.7", 500, NULL, 0, schedule);
38  * silc_stream_set_notifier(udpstream, schedule, receive_callback, ctx);
39  *
40  ***/
41
42 #ifndef SILCNET_H
43 #define SILCNET_H
44
45 /* Prototypes */
46
47 /****s* silcutil/SilcNetListener
48  *
49  * NAME
50  *
51  *    typedef struct SilcNetListenerStruct *SilcNetListener;
52  *
53  * DESCRIPTION
54  *
55  *    The network listenr context.  This context is created with the
56  *    silc_net_tcp_create_listener function and destroyed with
57  *    silc_net_close_listener function.
58  *
59  ***/
60 typedef struct SilcNetListenerStruct *SilcNetListener;
61
62 /****f* silcutil/SilcNetCallback
63  *
64  * SYNOPSIS
65  *
66  *    typedef void (*SilcNetCallback)(SilcResult status,
67  *                                    SilcStream stream, void *context);
68  *
69  * DESCRIPTION
70  *
71  *    A callback of this type is returned by silc_net_tcp_create_listener
72  *    and silc_net_tcp_connect functions.  For silc_net_tcp_create_listener
73  *    this callback means that new incoming connection was accepted, and the
74  *    `stream' is the socket stream representing the socket connection.
75  *
76  *    For silc_net_tcp_connect this means that we have connected to the
77  *    remote host and the `stream' is the socket stream for the socket
78  *    connection.  The SILC Stream API (such as silc_stream_read, etc.) can
79  *    be used to read and write to the stream.  The created stream is socket
80  *    stream so various SilcSocketStream API functions can be used with
81  *    the `stream'.
82  *
83  ***/
84 typedef void (*SilcNetCallback)(SilcResult status,
85                                 SilcStream stream, void *context);
86
87 /****f* silcutil/silc_net_tcp_create_listener
88  *
89  * SYNOPSIS
90  *
91  *    SilcNetListener
92  *    silc_net_tcp_create_listener(const char **local_ip_addr,
93  *                                 SilcUInt32 local_ip_count, int port,
94  *                                 SilcBool lookup, SilcBool require_fqdn,
95  *                                 SilcSchedule schedule,
96  *                                 SilcNetCallback callback, void *context);
97  *
98  * DESCRIPTION
99  *
100  *    This function creates TCP listener.  This is used to create network
101  *    listener for incoming connections, and `callback' will be called
102  *    everytime new connection is received.  If `local_ip_addr' is NULL 'any'
103  *    address is used.  If provided it can be used bind the listener to
104  *    `local_ip_count' many IP addresses provided in `local_ip_addr' table.
105  *    On success returns the SilcNetListener context, or NULL on error.
106  *    If `require_fqdn' is TRUE the listener will require that the incoming
107  *    connection has FQDN to be able to connect.  If the `lookup' is TRUE
108  *    then the incoming connection hostname will be resolved.  If the `port'
109  *    is zero (0), operating system will define it automatically.
110  *
111  *    The `callback' always delivers valid new stream.  It is not called
112  *    with an error status.  If `schedule' is NULL this will call
113  *    silc_schedule_get_global to try to get global scheduler.
114  *
115  ***/
116 SilcNetListener
117 silc_net_tcp_create_listener(const char **local_ip_addr,
118                              SilcUInt32 local_ip_count, int port,
119                              SilcBool lookup, SilcBool require_fqdn,
120                              SilcSchedule schedule,
121                              SilcNetCallback callback, void *context);
122
123 /****f* silcutil/silc_net_tcp_create_listener2
124  *
125  * SYNOPSIS
126  *
127  *    SilcNetListener
128  *    silc_net_tcp_create_listener2(const char *local_ip_addr, int *ports,
129  *                                  SilcUInt32 port_count,
130  *                                  SilcBool ignore_port_error,
131  *                                  SilcBool lookup, SilcBool require_fqdn,
132  *                                  SilcSchedule schedule,
133  *                                  SilcNetCallback callback, void *context);
134  *
135  * DESCRIPTION
136  *
137  *    This function creates TCP listener.  This is used to create network
138  *    listener for incoming connections, and `callback' will be called
139  *    everytime new connection is received.  If `local_ip_addr' is NULL 'any'
140  *    address is used.  If `ports' is NULL or it contains a zero (0) port,
141  *    operating system will define it automatically.  This function can be
142  *    used to bind to many ports at the same time.  If `ignore_port_error'
143  *    is TRUE this won't return NULL if at least one of the ports could
144  *    be bound.  Otherwise, NULL will be returned on error.
145  *
146  *    If `require_fqdn' is TRUE the listener will require that the incoming
147  *    connection has FQDN to be able to connect.  If the `lookup' is TRUE
148  *    then the incoming connection hostname will be resolved.
149  *
150  *    The `callback' always delivers valid new stream.  It is not called
151  *    with an error status.  If `schedule' is NULL this will call
152  *    silc_schedule_get_global to try to get global scheduler.
153  *
154  ***/
155 SilcNetListener
156 silc_net_tcp_create_listener2(const char *local_ip_addr, int *ports,
157                               SilcUInt32 port_count,
158                               SilcBool ignore_port_error,
159                               SilcBool lookup, SilcBool require_fqdn,
160                               SilcSchedule schedule,
161                               SilcNetCallback callback, void *context);
162
163 /****f* silcutil/silc_net_listener_get_port
164  *
165  * SYNOPSIS
166  *
167  *    SilcUInt16 *silc_net_listener_get_port(SilcNetListener listener,
168  *                                           SilcUInt32 *port_count);
169  *
170  * DESCRIPTION
171  *
172  *    Returns the ports to where the `listener' is bound.  This can be used
173  *    to get the port if none was specified in silc_net_tcp_create_listener.
174  *    Returns an array of ports of size of `port_count'.  The caller must
175  *    free the array with silc_free.  There are as many ports in the array
176  *    as there were IP addresses provided in silc_net_tcp_create_listener,
177  *    or as there were ports provided in silc_net_tcp_create_listener2.
178  *
179  ***/
180 SilcUInt16 *silc_net_listener_get_port(SilcNetListener listener,
181                                        SilcUInt32 *port_count);
182
183 /****f* silcutil/silc_net_listener_get_ip
184  *
185  * SYNOPSIS
186  *
187  *    char **silc_net_listener_get_ip(SilcNetListener listener,
188  *                                    SilcUInt32 *ip_count);
189  *
190  * DESCRIPTION
191  *
192  *    Returns the IP's to where the `listener' is bound.  Returns an array
193  *    of IP addresses of size of `ip_count'.  The caller must free the
194  *    array and its strings with silc_free.
195  *
196  ***/
197 char **silc_net_listener_get_ip(SilcNetListener listener,
198                                 SilcUInt32 *ip_count);
199
200 /****f* silcutil/silc_net_listener_get_hostname
201  *
202  * SYNOPSIS
203  *
204  *    char **silc_net_listener_get_hostname(SilcNetListener listener,
205  *                                          SilcUInt32 *hostname_count);
206  *
207  * DESCRIPTION
208  *
209  *    Returns the hostnames to where the `listener' is bound.  Returns an
210  *    array of hostnames of size of `hostname_count'.  The caller must free
211  *    the array and its strings with silc_free.
212  *
213  ***/
214 char **silc_net_listener_get_hostname(SilcNetListener listener,
215                                       SilcUInt32 *hostname_count);
216
217 /****f* silcutil/silc_net_close_listener
218  *
219  * SYNOPSIS
220  *
221  *    void silc_net_close_listener(SilcNetListener listener);
222  *
223  * DESCRIPTION
224  *
225  *    Closes the network listener indicated by `listener'.
226  *
227  ***/
228 void silc_net_close_listener(SilcNetListener listener);
229
230 /****f* silcutil/silc_net_tcp_connect
231  *
232  * SYNOPSIS
233  *
234  *    SilcAsyncOperation silc_net_tcp_connect(const char *local_ip_addr,
235  *                                            const char *remote_ip_addr,
236  *                                            int remote_port,
237  *                                            SilcSchedule schedule,
238  *                                            SilcNetCallback callback,
239  *                                            void *context);
240  *
241  * DESCRIPTION
242  *
243  *    Creates TCP/IP connection to the remote host indicated by `remote_host'
244  *    which may be hostname or IP address, on the port indicated by
245  *    `remote_port'.  If the `local_ip_addr' is provided the local host is
246  *    bound to that address before creating the connection.  This is
247  *    asynchronous call, and this function returns before the connection is
248  *    actually established.  The `callback' will be called after the
249  *    connection is created to deliver the SilcStream for the created
250  *    connection.  This function supports IPv6 if the platform supports it.
251  *
252  *    The returned SilcAsyncOperation context can be used to control the
253  *    asynchronous connecting, such as to abort it.  If it is aborted
254  *    using silc_async_abort the `callback' will not be called.  If NULL
255  *    is returned the operation cannot be aborted.  If `schedule' is NULL
256  *    this will call silc_schedule_get_global to try to get global scheduler.
257  *
258  ***/
259 SilcAsyncOperation silc_net_tcp_connect(const char *local_ip_addr,
260                                         const char *remote_ip_addr,
261                                         int remote_port,
262                                         SilcSchedule schedule,
263                                         SilcNetCallback callback,
264                                         void *context);
265
266 /****f* silcutil/silc_net_udp_connect
267  *
268  * SYNOPSIS
269  *
270  *    SilcStream
271  *    silc_net_udp_connect(const char *local_ip_addr, int local_port,
272  *                         const char *remote_ip_addr, int remote_port,
273  *                         SilcSchedule schedule);
274  *
275  * DESCRIPTION
276  *
277  *    This function creates UDP stream.  The UDP stream is bound to the
278  *    `local_ip_addr' if it is specified.  If `local_port' is non-zero the
279  *    stream is bound to that port.  If the `remote_ip_addr' and `remote_port'
280  *    is also provided, packets may be sent to that address using
281  *    silc_stream_write function and packets may be received using
282  *    silc_stream_read function.
283  *
284  *    If the remote address is not provided the stream is in connectionless
285  *    state.  This means that packets can be received only by using
286  *    silc_net_udp_receive and sent only by using the function
287  *    silc_net_udp_send.
288  *
289  *    To receive packets the silc_stream_set_notifier must be called for the
290  *    returned SilcStream.  The packets are always received in the notifier
291  *    callback when the SILC_STREAM_CAN_READ is returned to the callback.
292  *    To read the packet use silc_stream_read if the `remote_ip_addr' was
293  *    provided, and silc_net_udp_receive if it was not.
294  *
295  *    Supports IPv6 if the platform supports it.  If `schedule' is NULL this
296  *    will call silc_schedule_get_global to try to get global scheduler.
297  *
298  * EXAMPLE
299  *
300  *    SilcStream udpstream;
301  *
302  *    // Create UDP stream and prepare to receive packets
303  *    udpstream = silc_net_udp_connect("10.2.1.7", 5000,
304  *                                     "10.2.1.100, 5000, schedule);
305  *    silc_stream_set_notifier(udpstream, schedule, receive_callback, context);
306  *
307  *    // Send packet to remote host
308  *    silc_stream_write(udpstream, data, data_len);
309  *
310  *    Create UDP listener:
311  *
312  *    udpstream = silc_net_udp_connect("0.0.0.0", 500, NULL, 0, schedule);
313  *    silc_stream_set_notifier(udpstream, schedule, receive_callback, context);
314  *
315  ***/
316 SilcStream silc_net_udp_connect(const char *local_ip_addr, int local_port,
317                                 const char *remote_ip_addr, int remote_port,
318                                 SilcSchedule schedule);
319
320 /****f* silcutil/silc_net_udp_receive
321  *
322  * SYNOPSIS
323  *
324  *    int
325  *    silc_net_udp_receive(SilcStream stream, char *remote_ip_addr,
326  *                         SilcUInt32 remote_ip_addr_size, int *remote_port,
327  *                         unsigned char *ret_data, SilcUInt32 data_size)
328  *
329  * DESCRIPTION
330  *
331  *    Receive a UDP packet from the `stream'.  The IP address and port of
332  *    the sender is returned into `remote_ip_addr' buffer and `remote_port'
333  *    pointer.  The packet data is returned into the `ret_data' buffer.
334  *
335  *    Returns the length of the packet, or -1 on error or 0 in case of EOF.
336  *    In case of error the silc_errno will indicate the error.  If the
337  *    error is SILC_ERR_WOULD_BLOCK data is not currently available from the
338  *    `stream'.
339  *
340  ***/
341 int silc_net_udp_receive(SilcStream stream, char *remote_ip_addr,
342                          SilcUInt32 remote_ip_addr_size, int *remote_port,
343                          unsigned char *ret_data, SilcUInt32 data_size);
344
345 /****f* silcutil/silc_net_udp_send
346  *
347  * SYNOPSIS
348  *
349  *    int silc_net_udp_send(SilcStream stream,
350  *                          const char *remote_ip_addr, int remote_port,
351  *                          const unsigned char *data, SilcUInt32 data_len);
352  *
353  * DESCRIPTION
354  *
355  *    Sends an UDP packet to remote host `remote_ip_addr' on `remote_port'.
356  *    This may be used with UDP streams that are not connected to any
357  *    specific remote host.  With those streams silc_stream_write cannot be
358  *    used.  In those cases, this function must be used.  However, this may
359  *    also be used even if the stream is in connected state.
360  *
361  *    You can create the `stream' by calling silc_net_udp_connect.
362  *
363  *    Returns the amount of data written, -1 if data could not be written
364  *    at this moment, or -2 if error occurred.  If -1 is returned the
365  *    notifier callback will later be called with SILC_STREAM_CAN_WRITE
366  *    status when stream is again ready for writing.
367  *
368  ***/
369 int silc_net_udp_send(SilcStream stream,
370                       const char *remote_ip_addr, int remote_port,
371                       const unsigned char *data, SilcUInt32 data_len);
372
373 /****f* silcutil/silc_net_close_connection
374  *
375  * SYNOPSIS
376  *
377  *    void silc_net_close_connection(int sock);
378  *
379  * DESCRIPTION
380  *
381  *    Closes the connection by closing the socket connection.  This routine
382  *    can only be used with POSIX compliant systems.
383  *
384  ***/
385 void silc_net_close_connection(int sock);
386
387 /****f* silcutil/silc_net_accept_connection
388  *
389  * SYNOPSIS
390  *
391  *    int silc_net_accept_connection(int sock);
392  *
393  * DESCRIPTION
394  *
395  *    Accepts a connection from a particular socket.  This routine can only
396  *    be used with POSIX compliant systems.  This call is equivalent to
397  *    accept(2).
398  *
399  ***/
400 int silc_net_accept_connection(int sock);
401
402 /****f* silcutil/silc_net_set_socket_opt
403  *
404  * SYNOPSIS
405  *
406  *    int silc_net_set_socket_opt(int sock, int level, int option, int on);
407  *
408  * DESCRIPTION
409  *
410  *    Sets a option for a socket.  This function can be used to set
411  *    various options for the socket.  Some of the options might be
412  *    system specific.  This routine can only be used with POSIX compliant
413  *    systems.  This call is equivalent to setsockopt(2);
414  *
415  ***/
416 int silc_net_set_socket_opt(int sock, int level, int option, int on);
417
418 /****f* silcutil/silc_net_get_socket_opt
419  *
420  * SYNOPSIS
421  *
422  *    int silc_net_get_socket_opt(int sock, int level, int option,
423  *                                void *optval, int *opt_len);
424  *
425  * DESCRIPTION
426  *
427  *    Return socket options to the `optval' and `opt_len'.  This routine
428  *    can only be used with POSIX compliant systems.  This call is
429  *    equivalent to getsockopt(2).
430  *
431  ***/
432 int silc_net_get_socket_opt(int sock, int level, int option,
433                             void *optval, int *opt_len);
434
435 /****f* silcutil/silc_net_set_socket_nonblock
436  *
437  * SYNOPSIS
438  *
439  *    int silc_net_set_socket_nonblock(SilcSocket sock);
440  *
441  * DESCRIPTION
442  *
443  *    Sets the socket `sock' to non-blocking mode.
444  *
445  ***/
446 int silc_net_set_socket_nonblock(SilcSocket sock);
447
448 /****f* silcutil/silc_net_is_ip4
449  *
450  * SYNOPSIS
451  *
452  *    SilcBool silc_net_is_ip4(const char *addr);
453  *
454  * DESCRIPTION
455  *
456  *    Checks whether IP address sent as argument is valid IPv4 address.
457  *
458  ***/
459 SilcBool silc_net_is_ip4(const char *addr);
460
461 /****f* silcutil/silc_net_is_ip6
462  *
463  * SYNOPSIS
464  *
465  *    SilcBool silc_net_is_ip6(const char *addr);
466  *
467  * DESCRIPTION
468  *
469  *    Checks whether IP address sent as argument is valid IPv6 address.
470  *
471  ***/
472 SilcBool silc_net_is_ip6(const char *addr);
473
474 /****f* silcutil/silc_net_is_ip
475  *
476  * SYNOPSIS
477  *
478  *    SilcBool silc_net_is_ip(const char *addr);
479  *
480  * DESCRIPTION
481  *
482  *    Checks whether IP address sent as argument is valid IP address.
483  *    This supports both IPv4 and IPv6 addresses.
484  *
485  ***/
486 SilcBool silc_net_is_ip(const char *addr);
487
488 /****f* silcutil/silc_net_addr2bin
489  *
490  * SYNOPSIS
491  *
492  *    SilcBool silc_net_addr2bin(const char *addr, void *bin,
493  *                               SilcUInt32 bin_len);
494  *
495  * DESCRIPTION
496  *
497  *    Converts the IP number string from numbers-and-dots notation to
498  *    binary form in network byte order.  The address can be either
499  *    IPv4 or IPv6 address.
500  *
501  ***/
502 SilcBool silc_net_addr2bin(const char *addr, void *bin, SilcUInt32 bin_len);
503
504 /****f* silcutil/silc_net_bin2addr
505  *
506  * SYNOPSIS
507  *
508  *    SilcBool silc_net_bin2addr(const void *bin, SilcUInt32 bin_len,
509  *                               char *addr, SilcUInt32 addr_size);
510  *
511  * DESCRIPTION
512  *
513  *    Converts network byte ordered IP address into a numbers-and-dots
514  *    string notation.  The `bin' address can be either IPv4 or IPv6 address.
515  *
516  ***/
517 SilcBool silc_net_bin2addr(const void *bin, SilcUInt32 bin_len,
518                            char *addr, SilcUInt32 addr_size);
519
520 /****f* silcutil/SilcNetResolveCallback
521  *
522  * SYNOPSIS
523  *
524  *    typedef void (*SilcNetResolveCallback)(const char *result,
525  *                                           void *context);
526  *
527  * DESCRIPTION
528  *
529  *    A callback function of this type is called after the asynchronous
530  *    resolving operation has been completed.  This callback is used
531  *    when asynchronously resolving IP addresses and hostnames.
532  *
533  ***/
534 typedef void (*SilcNetResolveCallback)(const char *result, void *context);
535
536 /****f* silcutil/silc_net_gethostbyname
537  *
538  * SYNOPSIS
539  *
540  *    SilcBool silc_net_gethostbyname(const char *name, SilcBool prefer_ipv6,
541  *                                    char *address, SilcUInt32 address_len);
542  *
543  * DESCRIPTION
544  *
545  *    Resolves the IP address of the hostname indicated by the `name'.
546  *    This returns TRUE and the IP address of the host to the `address'
547  *    buffer, or FALSE if the address could not be resolved.  This is
548  *    synchronous function and will block the calling process.  If the
549  *    `prefer_ipv6' is TRUE then this will return IPv6 address if it
550  *    finds.  If FALSE if returns IPv4 address even if it found IPv6
551  *    address also.
552  *
553  ***/
554 SilcBool silc_net_gethostbyname(const char *name, SilcBool prefer_ipv6,
555                                 char *address, SilcUInt32 address_len);
556
557 /****f* silcutil/silc_net_gethostbyname_async
558  *
559  * SYNOPSIS
560  *
561  *    void silc_net_gethostbyname_async(const char *name,
562  *                                      SilcBool prefer_ipv6,
563  *                                      SilcSchedule schedule,
564  *                                      SilcNetResolveCallback completion,
565  *                                      void *context)
566  *
567  * DESCRIPTION
568  *
569  *    Asynchronously resolves the IP address of the hostname indicated
570  *    by the `name'.  This function returns immediately, and the
571  *    `completion' callback will be called after the resolving is
572  *    completed.  If `schedule' is NULL this will call silc_schedule_get_global
573  *    to try to get global scheduler.
574  *
575  *    If the `prefer_ipv6' is TRUE then this will return IPv6 address if it
576  *    finds.  If FALSE if returns IPv4 address even if it found IPv6
577  *    address also.
578  *
579  ***/
580 void silc_net_gethostbyname_async(const char *name,
581                                   SilcBool prefer_ipv6,
582                                   SilcSchedule schedule,
583                                   SilcNetResolveCallback completion,
584                                   void *context);
585
586 /****f* silcutil/silc_net_gethostbyaddr
587  *
588  * SYNOPSIS
589  *
590  *   SilcBool silc_net_gethostbyaddr(const char *addr, char *name,
591  *                                   SilcUInt32 name_len);
592  *
593  * DESCRIPTION
594  *
595  *    Resolves the hostname for the IP address indicated by the `addr'
596  *    This returns TRUE and the resolved hostname to the `name' buffer,
597  *    or FALSE on error. The `addr' may be either IPv4 or IPv6 address.
598  *    This is synchronous function and will block the calling process.
599  *
600  ***/
601 SilcBool silc_net_gethostbyaddr(const char *addr, char *name,
602                                 SilcUInt32 name_len);
603
604 /****f* silcutil/silc_net_gethostbyaddr_async
605  *
606  * SYNOPSIS
607  *
608  *    void silc_net_gethostbyaddr_async(const char *addr,
609  *                                      SilcSchedule schedule,
610  *                                      SilcNetResolveCallback completion,
611  *                                      void *context)
612  *
613  * DESCRIPTION
614  *
615  *    Asynchronously resolves the hostname for the IP address indicated
616  *    by the `addr'.  This function returns immediately, and the
617  *    `completion' callback will be called after the resolving is
618  *    completed.  If `schedule' is NULL this will call silc_schedule_get_global
619  *    to try to get global scheduler.
620  *
621  ***/
622 void silc_net_gethostbyaddr_async(const char *addr,
623                                   SilcSchedule schedule,
624                                   SilcNetResolveCallback completion,
625                                   void *context);
626
627 /****f* silcutil/silc_net_check_host_by_sock
628  *
629  * SYNOPSIS
630  *
631  *    SilcBool silc_net_check_host_by_sock(SilcSocket sock, char **hostname,
632  *                                         char **ip);
633  *
634  * DESCRIPTION
635  *
636  *    Performs lookups for remote name and IP address. This peforms reverse
637  *    lookup as well to verify that the IP has FQDN.
638  *
639  ***/
640 SilcBool silc_net_check_host_by_sock(SilcSocket sock, char **hostname,
641                                      char **ip);
642
643 /****f* silcutil/silc_net_check_local_by_sock
644  *
645  * SYNOPSIS
646  *
647  *    SilcBool silc_net_check_local_by_sock(SilcSocket sock, char **hostname,
648  *                                          char **ip);
649  *
650  * DESCRIPTION
651  *
652  *    Performs lookups for local name and IP address. This peforms reverse
653  *    lookup as well to verify that the IP has FQDN.
654  *
655  ***/
656 SilcBool silc_net_check_local_by_sock(SilcSocket sock, char **hostname,
657                                       char **ip);
658
659 /****f* silcutil/silc_net_get_remote_port
660  *
661  * SYNOPSIS
662  *
663  *    SilcUInt16 silc_net_get_remote_port(SilcSocket sock);
664  *
665  * DESCRIPTION
666  *
667  *    Return remote port by socket.
668  *
669  ***/
670 SilcUInt16 silc_net_get_remote_port(SilcSocket sock);
671
672 /****f* silcutil/silc_net_get_local_port
673  *
674  * SYNOPSIS
675  *
676  *    SilcUInt16 silc_net_get_local_port(SilcSocket sock);
677  *
678  * DESCRIPTION
679  *
680  *    Return local port by socket.
681  *
682  ***/
683 SilcUInt16 silc_net_get_local_port(SilcSocket sock);
684
685 /****f* silcutil/silc_net_localhost
686  *
687  * SYNOPSIS
688  *
689  *    char *silc_net_localhost(void);
690  *
691  * DESCRIPTION
692  *
693  *    Return name of localhost.  This will also attempt to resolve
694  *    the real hostname by the local host's IP address.  If unsuccessful
695  *    the first found hostname is returned.  The caller must free
696  *    returned hostname.
697  *
698  ***/
699 char *silc_net_localhost(void);
700
701 /****f* silcutil/silc_net_localip
702  *
703  * SYNOPSIS
704  *
705  *    char *silc_net_localip(void)
706  *
707  * DESCRIPTION
708  *
709  *    Return IP of localhost.  The caller must free the returned IP.
710  *
711  ***/
712 char *silc_net_localip(void);
713
714 /****f* silcutil/silc_htonl
715  *
716  * SYNOPSIS
717  *
718  *    SilcUInt32 silc_htonl(SilcUInt32 host);
719  *
720  * DESCRIPTION
721  *
722  *    Converts integer `host' from host byte order to network byte order.
723  *
724  ***/
725 SilcUInt32 silc_htonl(SilcUInt32 host);
726
727 /****f* silcutil/silc_ntohl
728  *
729  * SYNOPSIS
730  *
731  *    SilcUInt32 silc_ntohl(SilcUInt32 net);
732  *
733  * DESCRIPTION
734  *
735  *    Converts integer `net' from network byte order to host byte order.
736  *
737  ***/
738 SilcUInt32 silc_ntohl(SilcUInt32 net);
739
740 /****f* silcutil/silc_htons
741  *
742  * SYNOPSIS
743  *
744  *    SilcUInt16 silc_htons(SilcUInt16 host);
745  *
746  * DESCRIPTION
747  *
748  *    Converts integer `host' from host byte order to network byte order.
749  *
750  ***/
751 SilcUInt16 silc_htons(SilcUInt16 host);
752
753 /****f* silcutil/silc_ntohs
754  *
755  * SYNOPSIS
756  *
757  *    SilcUInt16 silc_ntohs(SilcUInt16 net);
758  *
759  * DESCRIPTION
760  *
761  *    Converts integer `net' from network byte order to host byte order.
762  *
763  ***/
764 SilcUInt16 silc_ntohs(SilcUInt16 net);
765
766 #include "silcnet_i.h"
767
768 #endif /* SILCNET_H */