| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | #ifndef __NEBULA_H |
|---|
| 18 | #define __NEBULA_H |
|---|
| 19 | |
|---|
| 20 | #define _GNU_SOURCE 1 |
|---|
| 21 | |
|---|
| 22 | #include <netinet/in.h> |
|---|
| 23 | |
|---|
| 24 | #define HMAC_BLOCK_SIZE 256 |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | typedef enum nebula_errno { |
|---|
| 28 | NERR_SUCCESS = 0, |
|---|
| 29 | NERR_HMACINIT, |
|---|
| 30 | NERR_HMACHASH, |
|---|
| 31 | NERR_HMAC, |
|---|
| 32 | NERR_ZMEM, |
|---|
| 33 | NERR_ZBUF, |
|---|
| 34 | NERR_ZUNKNOWN, |
|---|
| 35 | NERR_TIMEOUT, |
|---|
| 36 | NERR_INVALID, |
|---|
| 37 | NERR_RECV, |
|---|
| 38 | NERR_INVALIDFLAGS, |
|---|
| 39 | NERR_PROXYERRNO, |
|---|
| 40 | unknown |
|---|
| 41 | } nebula_errno; |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | const char *nebula_errstr[] = { |
|---|
| 45 | "Success", |
|---|
| 46 | "HMAC initialization failed", |
|---|
| 47 | "Hash calculation failed", |
|---|
| 48 | "HMAC computation failed", |
|---|
| 49 | "Memory error during compression", |
|---|
| 50 | "Compression output buffer too small", |
|---|
| 51 | "Unknown error during data compression", |
|---|
| 52 | "Operation timed out", |
|---|
| 53 | "Server returned an invalid response", |
|---|
| 54 | "Server did not return a response", |
|---|
| 55 | "Invalid flags provided", |
|---|
| 56 | "Unknown" |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | typedef struct nebula { |
|---|
| 61 | nebula_errno nerrno; |
|---|
| 62 | int sockfd; |
|---|
| 63 | struct sockaddr_in server; |
|---|
| 64 | char *secret; |
|---|
| 65 | struct { |
|---|
| 66 | u_char k[HMAC_BLOCK_SIZE]; |
|---|
| 67 | u_char k_ipad[HMAC_BLOCK_SIZE]; |
|---|
| 68 | u_char k_opad[HMAC_BLOCK_SIZE]; |
|---|
| 69 | char *key; |
|---|
| 70 | } hmac; |
|---|
| 71 | } nebula; |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | #define NSCK_PERSIST 0x0001 |
|---|
| 76 | #define NSCK_NONBLCK 0x0002 |
|---|
| 77 | |
|---|
| 78 | nebula *nebula_new(void); |
|---|
| 79 | int nebula_init(nebula *n); |
|---|
| 80 | void nebula_cleanup(nebula *); |
|---|
| 81 | int nebula_connect(nebula *n, struct in_addr host, u_int16_t port, int flags); |
|---|
| 82 | int nebula_send(nebula *n, u_char protocol, u_int16_t port, u_char *data, size_t len); |
|---|
| 83 | int nebula_disconnect(nebula *); |
|---|
| 84 | int nebula_socket(nebula *); |
|---|
| 85 | int nebula_error(nebula *); |
|---|
| 86 | const char *nebula_strerr(nebula *); |
|---|
| 87 | |
|---|
| 88 | #endif |
|---|