aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmdsclient/address.h
blob: e710ba6caa2aed7e5be49093f07ad663155070d8 (plain) (blame)
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
83
84
85
86
87
88
89
90
91
92
93
/**
 * mds — A micro-display server
 * Copyright © 2014, 2015, 2016, 2017  Mattias Andrée (maandree@kth.se)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef MDS_LIBMDSCLIENT_ADDRESS_H
#define MDS_LIBMDSCLIENT_ADDRESS_H


#include <sys/socket.h>


/**
 * The address of the display, parsed into arguments
 */
typedef struct libmds_display_address
{
	/**
	 * The domain (protocol family), that is
	 * the first argument for socket(2), a
	 * value whose constant is prefixed PF_;
	 * -1 if not detected
	 */
	int domain;

	/**
	 * The socket type, that is the second
	 * argument for socket(2), a value whose
	 * constant is prefixed SOCK_; -1 if not
	 * detected
	 */
	int type;

	/**
	 * The protocol, that is the third
	 * argument for socket(2), a value whose
	 * constant is affixed PROTO_ (zero
	 * for the default); -1 if not detected
	 */
	int protocol;

	/**
	 * The address, `NULL` if not detected,
	 * you are responsible for freeing this
	 */
	struct sockaddr *address;

	/**
	 * The size of `address`, may be set
	 * even if `address` is `NULL`
	 */
	socklen_t address_len;

	/**
	 * Code for an error that has occured
	 * when parsing the address, whose
	 * description can be retrieved using
	 * `gia_strerror`, zero if none
	 */
	int gai_error;

} libmds_display_address_t;


/**
 * Parse a display address string
 * 
 * @param   display  The address in MDS_DISPLAY-formatting, must not be `NULL`
 * @param   address  Output parameter for parsed address, must not be `NULL`
 * @return           Zero on success, even if parsing failed, -1 on error,
 *                   `errno` will have been set accordinly on error
 * 
 * @throws  ENOMEM        Out of memory. Possibly, the application hit the
 *                        RLIMIT_AS or RLIMIT_DATA limit described in getrlimit(2).
 * @throws  ENAMETOOLONG  The filename of the target socket is too long
 */
__attribute__((nonnull))
int libmds_parse_display_address(const char *restrict display, libmds_display_address_t *restrict address);


#endif