Qore Programming Language 1.19.2
Loading...
Searching...
No Matches
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 - 2023 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
48DLLEXPORT int q_gethostbyname(const char* host, struct in_addr* sin_addr);
49
51
57DLLEXPORT QoreHashNode* q_gethostbyname_to_hash(const char* host);
58
60
66DLLEXPORT QoreStringNode* q_gethostbyname_to_string(const char* host);
67
69
77DLLEXPORT char* q_gethostbyaddr(const char* addr, int len, int type);
78
80DLLEXPORT QoreHashNode* q_gethostbyaddr_to_hash(ExceptionSink* xsink, const char* addr, int type = Q_AF_INET);
81
83
91DLLEXPORT QoreStringNode* q_gethostbyaddr_to_string(ExceptionSink* xsink, const char* addr, int type = Q_AF_INET);
92
94
96DLLEXPORT QoreStringNode* q_addr_to_string(int address_family, const char* addr);
97
99
107DLLEXPORT int q_addr_to_string(int address_family, const char* addr, QoreString& str);
108
110DLLEXPORT QoreStringNode* q_addr_to_string2(const struct sockaddr* ai_addr);
111
113
120DLLEXPORT int q_addr_to_string2(const struct sockaddr* ai_addr, QoreString& str);
121
123DLLEXPORT int q_get_port_from_addr(const struct sockaddr* ai_addr);
124
126DLLEXPORT 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
129DLLEXPORT void q_af_to_hash(int af, QoreHashNode& h, ExceptionSink* xsink);
130
133protected:
134 hashdecl addrinfo* ai;
135 bool has_svc;
136
137public:
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 hashdecl 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
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
provides an interface to getaddrinfo
Definition: QoreNet.h:132
DLLLOCAL hashdecl addrinfo * getAddrInfo() const
returns the hashdecl addrinfo * being managed (may by 0)
Definition: QoreNet.h:159
DLLEXPORT ~QoreAddrInfo()
destroy the object
DLLEXPORT void clear()
clears the current results, if any
DLLEXPORT QoreListNode * getList() const
returns a list of hashes of address info, if an addrinfo structure is being managed
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,...
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
static DLLEXPORT const char * getFamilyName(int address_family)
returns the name of the address family as a string (ie AF_INET = "ipv4", etc)
DLLEXPORT QoreAddrInfo()
create an empty structure
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
#define Q_AF_INET
cross-platform define for AF_INET
Definition: common.h:61
#define Q_AF_UNSPEC
cross-platform define for AF_UNSPEC
Definition: common.h:58
#define Q_SOCK_STREAM
platform-independent define for SOCK_STREAM
Definition: common.h:67