| Qore Programming Language - C/C++ Library 1.0.8

QoreNet.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 QoreNet.h
4
5 Network functions and macros
6
7 Qore Programming Language
8
9 Copyright (C) 2003 - 2015 David Nichols
10
11 Permission is hereby granted, free of charge, to any person obtaining a
12 copy of this software and associated documentation files (the "Software"),
13 to deal in the Software without restriction, including without limitation
14 the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 and/or sell copies of the Software, and to permit persons to whom the
16 Software is furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28
29 Note that the Qore library is released under a choice of three open-source
30 licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31 information.
32 */
33
34 #ifndef _QORE_QORENET_H
35
36 #define _QORE_QORENET_H
37
38 #include <sys/types.h>
39
41
48 DLLEXPORT int q_gethostbyname(const char* host, struct in_addr* sin_addr);
49
51
57 DLLEXPORT QoreHashNode* q_gethostbyname_to_hash(const char* host);
58
60
66 DLLEXPORT QoreStringNode* q_gethostbyname_to_string(const char* host);
67
69
77 DLLEXPORT char* q_gethostbyaddr(const char* addr, int len, int type);
78
80 DLLEXPORT QoreHashNode* q_gethostbyaddr_to_hash(ExceptionSink* xsink, const char* addr, int type = Q_AF_INET);
81
83
91 DLLEXPORT QoreStringNode* q_gethostbyaddr_to_string(ExceptionSink* xsink, const char* addr, int type = Q_AF_INET);
92
94
96 DLLEXPORT QoreStringNode* q_addr_to_string(int address_family, const char* addr);
97
99
107 DLLEXPORT int q_addr_to_string(int address_family, const char* addr, QoreString& str);
108
110 DLLEXPORT QoreStringNode* q_addr_to_string2(const struct sockaddr* ai_addr);
111
113
120 DLLEXPORT int q_addr_to_string2(const struct sockaddr* ai_addr, QoreString& str);
121
123 DLLEXPORT int q_get_port_from_addr(const struct sockaddr* ai_addr);
124
126 DLLEXPORT QoreListNode* q_getaddrinfo_to_list(ExceptionSink* xsink, const char* node, const char* service, int family = Q_AF_UNSPEC, int flags = 0, int socktype = Q_SOCK_STREAM);
127
129 DLLEXPORT void q_af_to_hash(int af, QoreHashNode& h, ExceptionSink* xsink);
130
132 class QoreAddrInfo {
133 protected:
134 struct addrinfo* ai;
135 bool has_svc;
136
137 public:
139 DLLEXPORT QoreAddrInfo();
140
142 DLLEXPORT ~QoreAddrInfo();
143
145 DLLEXPORT void clear();
146
148
156 DLLEXPORT int getInfo(ExceptionSink* xsink, const char* node, const char* service, int family = Q_AF_UNSPEC, int flags = 0, int socktype = Q_SOCK_STREAM, int protocol = 0);
157
159 DLLLOCAL struct addrinfo* getAddrInfo() const {
160 return ai;
161 }
162
164 DLLEXPORT QoreListNode* getList() const;
165
167 DLLEXPORT static const char* getFamilyName(int address_family);
168
170 DLLEXPORT static QoreStringNode* getAddressDesc(int address_family, const char* addr);
171 };
172
173 #endif // _QORE_QORENET_H
Q_SOCK_STREAM
#define Q_SOCK_STREAM
platform-independent define for SOCK_STREAM
Definition: common.h:67
QoreAddrInfo::QoreAddrInfo
DLLEXPORT QoreAddrInfo()
create an empty structure
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
Q_AF_INET
#define Q_AF_INET
cross-platform define for AF_INET
Definition: common.h:61
QoreAddrInfo::getInfo
DLLEXPORT int getInfo(ExceptionSink *xsink, const char *node, const char *service, int family=Q_AF_UNSPEC, int flags=0, int socktype=Q_SOCK_STREAM, int protocol=0)
get address info with the given parameters, if any errors occur, a Qore-language exception is thrown ...
QoreAddrInfo::clear
DLLEXPORT void clear()
clears the current results, if any
QoreAddrInfo::getAddrInfo
DLLLOCAL struct addrinfo * getAddrInfo() const
returns the struct addrinfo * being managed (may by 0)
Definition: QoreNet.h:159
QoreAddrInfo
provides an interface to getaddrinfo
Definition: QoreNet.h:132
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
QoreAddrInfo::getFamilyName
static DLLEXPORT const char * getFamilyName(int address_family)
returns the name of the address family as a string (ie AF_INET = "ipv4", etc)
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
QoreAddrInfo::getList
DLLEXPORT QoreListNode * getList() const
returns a list of hashes of address info, if an addrinfo structure is being managed ...
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreAddrInfo::~QoreAddrInfo
DLLEXPORT ~QoreAddrInfo()
destroy the object
QoreAddrInfo::getAddressDesc
static DLLEXPORT QoreStringNode * getAddressDesc(int address_family, const char *addr)
returns a descriptive string for the address family and an address string (ie AF_INET6, "::1" = "ipv6[::1]")
Q_AF_UNSPEC
#define Q_AF_UNSPEC
cross-platform define for AF_UNSPEC
Definition: common.h:58