24 #include <netcomm/service_discovery/service.h> 25 #include <netcomm/utils/resolver.h> 26 #include <core/exceptions/system.h> 28 #include <sys/types.h> 29 #include <arpa/inet.h> 30 #include <netinet/in.h> 64 unsigned short int port)
68 _domain = strdup(domain);
72 _modified_name = NULL;
94 unsigned short int port,
95 const struct sockaddr *addr,
96 const socklen_t addr_size,
97 std::list<std::string> &
txt)
100 _name = strdup(name);
101 _type = strdup(type);
102 _domain = strdup(domain);
103 _host = strdup(host);
106 _modified_name = NULL;
108 _addr = (
struct sockaddr *)malloc(addr_size);
109 memcpy(_addr, addr, addr_size);
110 _addr_size = addr_size;
125 unsigned short int port)
127 _name = strdup(name);
128 _type = strdup(type);
133 _modified_name = NULL;
155 unsigned short int port)
157 std::string s =
name;
158 std::string::size_type hpos = s.find(
"%h");
159 if (nnresolver && (hpos != std::string::npos)) {
162 _name = strdup(s.c_str());
163 _type = strdup(type);
168 _modified_name = NULL;
184 _name = strdup(name);
185 _type = strdup(type);
186 _domain = strdup(domain);
188 _modified_name = NULL;
200 if ( _name != NULL) free( _name );
201 if ( _type != NULL) free( _type );
202 if ( _domain != NULL) free( _domain );
203 if ( _host != NULL) free( _host );
204 if ( _addr != NULL) free( _addr );
205 if ( _modified_name != NULL) free( _modified_name );
215 _name = strdup(s->_name);
216 _type = strdup(s->_type);
218 if ( s->_domain != NULL ) {
219 _domain = strdup(s->_domain);
223 if ( s->_host != NULL ) {
224 _host = strdup(s->_host);
229 _modified_name = NULL;
230 if (s->_modified_name != NULL) {
231 _modified_name = strdup(s->_modified_name);
247 _name = strdup(s._name);
248 _type = strdup(s._type);
250 if ( s._domain != NULL ) {
251 _domain = strdup(s._domain);
255 if ( s._host != NULL ) {
256 _host = strdup(s._host);
261 _modified_name = NULL;
262 if (s._modified_name != NULL) {
263 _modified_name = strdup(s._modified_name);
281 va_start(arg, format);
283 if (vasprintf(&tmp, format, arg) == -1) {
309 _name = strdup(new_name);
331 if (_modified_name) free(_modified_name);
332 _modified_name = strdup(new_name);
345 return _modified_name;
396 char ipaddr[INET_ADDRSTRLEN];
397 struct sockaddr_in *saddr = (
struct sockaddr_in *)_addr;
398 return std::string(inet_ntop(AF_INET, &(saddr->sin_addr), ipaddr,
sizeof(ipaddr)));
405 const std::list<std::string> &
419 return ( (strcmp(_name, s._name) == 0) &&
420 (strcmp(_type, s._type) == 0) );
431 return ( (strcmp(_name, s->_name) == 0) &&
432 (strcmp(_type, s->_type) == 0) );
444 int typediff = strcmp(_type, s._type);
445 if ( typediff == 0 ) {
446 return (strcmp(_name, s._name) < 0);
448 return (typediff < 0);
const char * type() const
Get type of service.
Fawkes library namespace.
bool operator<(const NetworkService &s) const
Less than operator.
std::string addr_string() const
Get IP address of entry as string.
const char * short_hostname()
Get short hostname.
void set_name(const char *new_name)
Set name of service.
const char * host() const
Get host of service.
void add_txt(const char *format,...)
Add a TXT record.
NetworkService(const char *name, const char *type, const char *domain, const char *host, unsigned short int port)
Constructor.
void set_modified_name(const char *new_name) const
Set modified name of service.
bool operator==(const NetworkService &s) const
Equal operator for NetworkService reference.
unsigned short int port() const
Get port of service.
Representation of a service announced or found via service discovery (i.e.
const char * domain() const
Get domain of service.
Network name and address resolver.
void set_txt(std::list< std::string > &txtlist)
Set TXT records all at once.
~NetworkService()
Destructor.
const std::list< std::string > & txt() const
Get TXT record list of service.
System ran out of memory and desired operation could not be fulfilled.
const char * name() const
Get name of service.
const char * modified_name() const
Get modified name of service.