-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.h
More file actions
48 lines (38 loc) · 997 Bytes
/
client.h
File metadata and controls
48 lines (38 loc) · 997 Bytes
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
#ifndef CLIENT_H
#define CLIENT_H
#include "contact.h"
#include "txqueue.h"
#include "buffer.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <mbedtls/ssl.h>
#include <libubox/uloop.h>
struct client {
mbedtls_ssl_context ssl;
struct uloop_fd fd;
struct contact *contact;
struct buffer buf;
struct tx_queue txq;
struct sockaddr_storage ss;
socklen_t sslen;
time_t last_seen;
struct list_head list;
};
static inline const char * ss_ntoa(struct sockaddr_storage *ss)
{
static char addr[INET6_ADDRSTRLEN + 8];
u16 port;
if (ss->ss_family == AF_INET) {
const struct sockaddr_in *in = (struct sockaddr_in *)ss;
inet_ntop(AF_INET, &in->sin_addr, addr, INET_ADDRSTRLEN);
port = ntohs(in->sin_port);
} else {
const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *)ss;
inet_ntop(AF_INET6, &in6->sin6_addr, addr, INET6_ADDRSTRLEN);
port = ntohs(in6->sin6_port);
}
sprintf(&addr[strlen(addr)], ":%hu", port);
return addr;
}
#endif