QoreNet.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreNet.h
Network functions and macros
Qore Programming Language
Copyright (C) 2003 - 2015 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_QORENET_H
#define _QORE_QORENET_H
#include <sys/types.h>
DLLEXPORT int q_gethostbyname(const char* host, struct in_addr* sin_addr);
DLLEXPORT QoreHashNode* q_gethostbyname_to_hash(const char* host);
DLLEXPORT QoreStringNode* q_gethostbyname_to_string(const char* host);
DLLEXPORT char* q_gethostbyaddr(const char* addr, int len, int type);
DLLEXPORT QoreHashNode* q_gethostbyaddr_to_hash(ExceptionSink* xsink, const char* addr, int type = Q_AF_INET);
DLLEXPORT QoreStringNode* q_gethostbyaddr_to_string(ExceptionSink* xsink, const char* addr, int type = Q_AF_INET);
DLLEXPORT QoreStringNode* q_addr_to_string(int address_family, const char* addr);
DLLEXPORT int q_addr_to_string(int address_family, const char* addr, QoreString& str);
DLLEXPORT QoreStringNode* q_addr_to_string2(const struct sockaddr* ai_addr);
DLLEXPORT int q_addr_to_string2(const struct sockaddr* ai_addr, QoreString& str);
DLLEXPORT int q_get_port_from_addr(const struct sockaddr* ai_addr);
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);
DLLEXPORT void q_af_to_hash(int af, QoreHashNode& h, ExceptionSink* xsink);
class QoreAddrInfo {
protected:
struct addrinfo* ai;
bool has_svc;
public:
DLLEXPORT QoreAddrInfo();
DLLEXPORT ~QoreAddrInfo();
DLLEXPORT void clear();
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);
DLLLOCAL struct addrinfo* getAddrInfo() const {
return ai;
}
DLLEXPORT QoreListNode* getList() const;
DLLEXPORT static const char* getFamilyName(int address_family);
DLLEXPORT static QoreStringNode* getAddressDesc(int address_family, const char* addr);
};
#endif // _QORE_QORENET_H
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
Q_AF_UNSPEC
#define Q_AF_UNSPEC
cross-platform define for AF_UNSPEC
Definition: common.h:58
QoreAddrInfo
provides an interface to getaddrinfo
Definition: QoreNet.h:132
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
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,...
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
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)
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreAddrInfo::QoreAddrInfo
DLLEXPORT QoreAddrInfo()
create an empty structure
Q_SOCK_STREAM
#define Q_SOCK_STREAM
platform-independent define for SOCK_STREAM
Definition: common.h:67
QoreAddrInfo::getList
DLLEXPORT QoreListNode * getList() const
returns a list of hashes of address info, if an addrinfo structure is being managed
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
Q_AF_INET
#define Q_AF_INET
cross-platform define for AF_INET
Definition: common.h:61
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
QoreStringNode
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50