File: address.h

package info (click to toggle)
dbeacon 0.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: cpp: 2,346; perl: 1,549; makefile: 42; sh: 21
file content (72 lines) | stat: -rw-r--r-- 1,346 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright 2005-2010, Hugo Santos <hugo@fivebits.net>
 * Distributed under the terms of the MIT License.
 */

#ifndef _address_h_
#define _address_h_

#include <sys/types.h>
#include <sys/socket.h>

#include <string>

struct sockaddr_in;
struct sockaddr_in6;

struct address {
	address();
	address(int family);
	address(const address &address);

	sockaddr_in *v4();
	sockaddr_in6 *v6();

	const sockaddr_in *v4() const;
	const sockaddr_in6 *v6() const;

	sockaddr *saddr();
	const sockaddr *saddr() const;

	int family() const;
	bool set_family(int);

	int optlevel() const;
	int addrlen() const;

	bool parse(const char *, bool multicast = true, bool addport = true);
	bool set_addr(const char *);
	bool set_port(int);

	bool is_multicast() const;
	bool is_unspecified() const;

	int port() const;

	bool is_equal(const address &) const;
	int compare(const address &) const;

	bool copy_address(const address &source);

	void set(const sockaddr *);

	int fromsocket(int sock);

	char *to_string(char *, size_t, bool port = true) const;
	std::string to_string(bool port = true) const;

	friend bool operator== (const address &a1, const address &a2) {
		return a1.is_equal(a2);
	}

	friend bool operator < (const address &a1, const address &a2) {
		return a1.compare(a2) < 0;
	}

// #ifdef POSIX
	sockaddr_storage stor;
// #endif
};

#endif