File: hostentry.h

package info (click to toggle)
librudiments0 0.27-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,528 kB
  • ctags: 2,284
  • sloc: cpp: 14,657; sh: 7,547; ansic: 2,664; makefile: 945; xml: 15
file content (82 lines) | stat: -rw-r--r-- 2,440 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2002 David Muse
// See the COPYING file for more information.

#ifndef RUDIMENTS_HOSTENTRY_H
#define RUDIMENTS_HOSTENTRY_H

#include <rudiments/private/hostentryincludes.h>

// The hostentry class provides methods for retrieving entries from /etc/hosts

class hostentry {
	public:

		// If you need to quickly look up a specific field, use one of
		// these methods.
		//
		// These methods return true on success and false on failure.
		static	bool	getAliasList(const char *hostname,
						char ***aliaslist);
		static	bool	getAddressType(const char *hostname,
						int *addresstype);
		static	bool	getAddressLength(const char *hostname,
						int *addresslength);
		static	bool	getAddressList(const char *hostname,
						char ***addresslist);
		static	bool	getAddressString(const char *hostname,
						int index,
						char **addressstring);

		static	bool	getName(const char *address,
						int len, int type,
						char **name);
		static	bool	getAliasList(const char *address,
						int len, int type,
						char ***aliaslist);
		static	bool	getAddressList(const char *address,
						int len, int type,
						char ***addresslist);
		static	bool	getAddressString(const char *address,
						int len, int type,
						int index,
						char **addressstring);

		// If you need to look up a host entry and refer to multiple
		// fields, use these methods.
			hostentry();
			~hostentry();

		bool	initialize(const char *hostname);
			// Looks up a host entry by name.
		bool	initialize(const char *address, int len, int type);
			// Looks up a host entry by address.

		char	*getName() const;
		char	**getAliasList() const;
		int	getAddressType() const;
		int	getAddressLength() const;
		char	**getAddressList() const;
		char	*getAddressString(int index) const;

		void	print() const;
			// Prints out the host entry.

#ifdef RUDIMENTS_HAS_THREADS
		static	bool	needsMutex();
			// If your system doesn't support gethostbyname_r()
			// and gethostbyaddr_r() then this class needs a
			// mutex to assure thread safety.
			//
			// This method returns true if this class needs a mutex
			// to operate safely in a threaded environment and false
			// otherwise.
		static	void	setMutex(pthread_mutex_t *mutex);
			// Allows you to supply a mutex is the class needs it.
			// If your application is not multithreaded, then
			// there is no need to supply a mutex.
#endif

	#include <rudiments/private/hostentry.h>
};

#endif