summaryrefslogtreecommitdiff
path: root/include/nebula.h
blob: 48bcfcc49746bede322ddd5cbb4343274a686e12 (plain)
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
/* nebula.h
 *
 * Copyright (C) 2009 Tillmann Werner <tillmann.werner@gmx.de>
 *
 * This file is free software; as a special exception the author gives
 * unlimited permission to copy and/or distribute it, with or without
 * modifications, as long as this notice is preserved.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * $Id$
 */

#ifndef __NEBULA_H
#define __NEBULA_H

#define _GNU_SOURCE 1

#include <netinet/in.h>

#define HMAC_BLOCK_SIZE 256


typedef enum nebula_errno {
	NERR_SUCCESS = 0,
	NERR_HMACINIT,
	NERR_HMACHASH,
	NERR_HMAC,
	NERR_ZMEM,
	NERR_ZBUF,
	NERR_ZUNKNOWN,
	NERR_TIMEOUT,
	NERR_INVALID,
	NERR_RECV,
	NERR_INVALIDFLAGS,
	NERR_PROXYERRNO,
	unknown
} nebula_errno;


const char *nebula_errstr[] = {
	"Success",
	"HMAC initialization failed",
	"Hash calculation failed",
	"HMAC computation failed",
	"Memory error during compression",
	"Compression output buffer too small",
	"Unknown error during data compression",
	"Operation timed out",
	"Server returned an invalid response",
	"Server did not return a response",
	"Invalid flags provided",
	"Unknown"
};


typedef struct nebula {
	nebula_errno		nerrno;
	int			sockfd;
	struct sockaddr_in	server;
	char			*secret;
	struct {
		u_char	k[HMAC_BLOCK_SIZE];
		u_char	k_ipad[HMAC_BLOCK_SIZE];
		u_char	k_opad[HMAC_BLOCK_SIZE];
		char	*key;
	} hmac;
} nebula;


// flags for controlling the type of a nebula connection
#define NSCK_PERSIST	0x0001
#define NSCK_NONBLCK	0x0002

nebula *nebula_new(void);
int nebula_init(nebula *n);
void nebula_cleanup(nebula *);
int nebula_connect(nebula *n, struct in_addr host, u_int16_t port, int flags);
int nebula_send(nebula *n, u_char protocol, u_int16_t port, u_char *data, size_t len);
int nebula_disconnect(nebula *);
int nebula_socket(nebula *);
int nebula_error(nebula *);
const char *nebula_strerr(nebula *);

#endif