Qore Programming Language  0.8.11.1
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 - 2014 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 
43 DLLEXPORT int q_gethostbyname(const char *host, struct in_addr *sin_addr);
44 
46 DLLEXPORT QoreHashNode *q_gethostbyname_to_hash(const char *host);
47 
49 DLLEXPORT QoreStringNode *q_gethostbyname_to_string(const char *host);
50 
52 DLLEXPORT char *q_gethostbyaddr(const char *addr, int len, int type);
53 
55 DLLEXPORT QoreHashNode *q_gethostbyaddr_to_hash(ExceptionSink *xsink, const char *addr, int type = Q_AF_INET);
56 
58 DLLEXPORT QoreStringNode *q_gethostbyaddr_to_string(ExceptionSink *xsink, const char *addr, int type = Q_AF_INET);
59 
61 
63 DLLEXPORT QoreStringNode *q_addr_to_string(int address_family, const char *addr);
64 
66 
74 DLLEXPORT int q_addr_to_string(int address_family, const char* addr, QoreString& str);
75 
77 DLLEXPORT QoreStringNode *q_addr_to_string2(const struct sockaddr *ai_addr);
78 
80 
87 DLLEXPORT int q_addr_to_string2(const struct sockaddr *ai_addr, QoreString& str);
88 
90 DLLEXPORT int q_get_port_from_addr(const struct sockaddr *ai_addr);
91 
93 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);
94 
96 DLLEXPORT void q_af_to_hash(int af, QoreHashNode& h, ExceptionSink* xsink);
97 
99 class QoreAddrInfo {
100 protected:
101  struct addrinfo *ai;
102  bool has_svc;
103 
104 public:
106  DLLEXPORT QoreAddrInfo();
107 
109  DLLEXPORT ~QoreAddrInfo();
110 
112  DLLEXPORT void clear();
113 
115 
123  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);
124 
126  DLLLOCAL struct addrinfo *getAddrInfo() const {
127  return ai;
128  }
129 
131  DLLEXPORT QoreListNode *getList() const;
132 
134  DLLEXPORT static const char *getFamilyName(int address_family);
135 
137  DLLEXPORT static QoreStringNode *getAddressDesc(int address_family, const char *addr);
138 };
139 
140 #endif // _QORE_QORENET_H
#define Q_SOCK_STREAM
platform-independent define for SOCK_STREAM
Definition: common.h:64
DLLEXPORT QoreAddrInfo()
create an empty structure
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:49
DLLLOCAL struct addrinfo * getAddrInfo() const
returns the struct addrinfo * being managed (may by 0)
Definition: QoreNet.h:126
DLLEXPORT QoreListNode * getList() const
returns a list of hashes of address info, if an addrinfo structure is being managed ...
#define Q_AF_INET
cross-platform define for AF_INET
Definition: common.h:58
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 ...
DLLEXPORT void clear()
clears the current results, if any
provides an interface to getaddrinfo
Definition: QoreNet.h:99
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:50
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:48
static DLLEXPORT const char * getFamilyName(int address_family)
returns the name of the address family as a string (ie AF_INET = "ipv4", etc)
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
DLLEXPORT ~QoreAddrInfo()
destroy the object
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]")
#define Q_AF_UNSPEC
cross-platform define for AF_UNSPEC
Definition: common.h:55