Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5db9e7086d5d3513a1e3da9d70d88065bb98d39a
[simgrid.git] / src / nws_portability / Include / dnsutil.h
1 /* $Id$ */
2
3
4 #ifndef DNSUTIL_H
5 #define DNSUTIL_H
6
7 #include "config_portability.h"
8
9 /**
10  * This package defines some utilities for determining and converting DNS
11  * machine names and IP addresses.
12  */
13
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19
20 #define MAX_IP_IMAGE 15
21 /* Maximum text length of an IP address, i.e. strlen("255.255.255.255") */
22
23
24 /*
25  * Common typedefs for all portability 
26  */
27 typedef uint32_t IPAddress;
28 typedef int Socket;
29 #define NO_SOCKET ((Socket)-1)
30
31 /**
32  * returns the address of the host connected to #sd#. Returns 0 on error.
33  */
34 IPAddress
35 Peer(Socket sd);
36
37
38 /**
39  * Returns the DNS name of the host connected to #sd#, or descriptive text if
40  * #sd# is not an inter-host connection: returns NULL in case of error
41  * The value returned needs to be freed.
42  */
43 char *
44 PeerName_r(Socket sd);
45
46 /*
47  * returns the port number on the other side of socket sd. -1 is returned
48  * if pipes or unknown
49  */
50 unsigned short
51 PeerNamePort(Socket sd);
52
53
54 /**
55  * Converts #addr# into a printable string and returns the result.  You
56  * are responsible to free the returned string: can return NULL (out of
57  * memory condition).
58  */
59 char *
60 IPAddressImage_r(IPAddress addr);
61
62
63 /**
64  * Converts #addr# to a fully-qualified machine name and returns the result.
65  * You are responsible to free the returned string: can return NULL 
66  * (out of memory or error).
67  */
68 char *
69 IPAddressMachine_r(IPAddress addr);
70
71 /*
72  * Converts #machineOrAddress#, which may be either a DNS name or an IP address
73  * image, into a list of addresses.  Copies the list into the #atMost#-long
74  * array #addressList#.  Returns the number of addresses copied, or zero on
75  * error.  #atMost# may be zero, in which case the function simply returns one
76  * or zero depending on whether or not #machineOrAddress# is a valid machine
77  * name or IP address image.
78  */
79 int
80 IPAddressValues(const char *machineOrAddress,
81                 IPAddress *addressList,
82                 unsigned int atMost);
83 #define IPAddressValue(machineOrAddress,address) \
84         IPAddressValues(machineOrAddress,address,1)
85 #define IsValidIP(machineOrAddress) IPAddressValues(machineOrAddress,NULL,0)
86
87
88 /**
89  * Returns the fully-qualified name of the host machine, or NULL if the name
90  * cannot be determined.  Always returns the same value, so multiple calls
91  * cause no problems.
92  */
93 const char *
94 MyMachineName(void);
95
96
97 /* DEPRECATED! These functions are going to go away: they are not thread
98  * safe. */ 
99 const char *
100 IPAddressImage(IPAddress addr);
101 const char *
102 IPAddressMachine(IPAddress addr);
103 const char *
104 PeerName(Socket sd);
105
106
107 #ifdef __cplusplus
108 }
109 #endif
110
111
112 #endif