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