HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_NetUtil.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_NetUtil.h (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_NETUTIL_H_INCLUDED__
12 #define __UT_NETUTIL_H_INCLUDED__
13 
14 #include "UT_API.h"
15 
16 #ifdef _WIN32
17  #include <ws2tcpip.h>
18 #else
19  #include <netinet/in.h>
20 #endif
21 
22 /// @file
23 /// Common network utilities
24 
25 template <typename T> class UT_Array;
26 class UT_IpAddress;
27 class UT_IpAddressV4;
28 class UT_String;
29 class UT_StringHolder;
30 class UT_StringRef;
31 class UT_WorkBuffer;
32 
33 /// Given host, resolves it to the canonical name if possible.
34 /// If false is returned, then host is untouched.
36 
37 /// Convert an IP address to a hostname
38 /// @{
41 /// @}
42 
43 /// Convert either an IP address or host alias to its given name.
44 UT_API extern bool UTgetHostnameByAlias(UT_StringHolder& host, const char* alias, UT_StringHolder& error);
45 
46 /// Remove the domain name and append back the port number if provided.
47 /// i.e. matane.local -> matane, matane.local:3080 -> matane:3080
48 /// @{
49 UT_API extern void UTstripDomainName(UT_String& host);
50 UT_API extern void UTstripDomainName(UT_WorkBuffer& host);
51 /// @}
52 
53 /// Check if the ports match both hosts ports
54 /// @{
55 UT_API extern bool UTdoPortsMatch(const UT_String& host1, const UT_String& host2);
56 UT_API extern bool UTdoPortsMatch(const UT_WorkBuffer& host1, const UT_WorkBuffer& host2);
57 /// @}
58 
59 /// Check if string is at a delimeter (at end of string or at '.')
60 UT_API extern bool UTatHostnameDelimeter(const char* p);
61 
62 /// Check if rest of string is non alpha character from a hostname
63 UT_API extern bool UTisHostnameAllNonAlpha(const char* str);
64 
65 /// Get list of IP addresses for local interfaces on this machine
66 UT_API extern bool UTgetLocalInterfaces(UT_Array<UT_IpAddress> &local_addrs);
67 
68 /// Convert a hostname to a list of resolved ip addresses
69 UT_API extern bool UThostnameToIpAddress(
70  const UT_StringRef& host,
71  UT_Array<UT_IpAddress>& address);
72 
73 #endif // __UT_NETUTIL_H_INCLUDED__
UT_API UT_StringHolder UTipAddressToHostname(const UT_StringRef &ip_address, UT_StringHolder &error)
This represents a Ipv4 address.
Definition: UT_IpAddress.h:34
UT_API bool UTatHostnameDelimeter(const char *p)
Check if string is at a delimeter (at end of string or at '.')
#define UT_API
Definition: UT_API.h:14
UT_API bool UTisHostnameAllNonAlpha(const char *str)
Check if rest of string is non alpha character from a hostname.
< returns > If no error
Definition: snippets.dox:2
This represents either an Ipv4 address or an Ipv6 address.
Definition: UT_IpAddress.h:230
UT_API bool UTdoPortsMatch(const UT_String &host1, const UT_String &host2)
UT_API bool UThostnameToIpAddress(const UT_StringRef &host, UT_Array< UT_IpAddress > &address)
Convert a hostname to a list of resolved ip addresses.
UT_API void UTstripDomainName(UT_String &host)
UT_API bool UTresolveCanonicalHostname(UT_String &host, UT_StringHolder &error)
UT_API bool UTgetLocalInterfaces(UT_Array< UT_IpAddress > &local_addrs)
Get list of IP addresses for local interfaces on this machine.
UT_API bool UTgetHostnameByAlias(UT_StringHolder &host, const char *alias, UT_StringHolder &error)
Convert either an IP address or host alias to its given name.