forked from TelegramMessenger/MTProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvv-io.h
76 lines (63 loc) · 2.09 KB
/
vv-io.h
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
/*
This file is part of Mtproto-proxy Library.
Mtproto-proxy Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Mtproto-proxy Library 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Mtproto-proxy Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2012-2013 Vkontakte Ltd
2012-2013 Vitaliy Valtman
*/
#pragma once
#include <stdio.h>
#include <arpa/inet.h>
#define PID_PRINT_STR "[" IP_PRINT_STR ":%d:%d:%d]"
#define IP_PRINT_STR "%d.%d.%d.%d"
#define PID_TO_PRINT(a) IP_TO_PRINT((a)->ip), (int)(a)->port, (int)(a)->pid, (a)->utime
#define IP_TO_PRINT(a) ((a) >> 24) & 0xff, ((a) >> 16) & 0xff, ((a) >> 8) & 0xff, (a) & 0xff
#define IPV6_PRINT_STR "%s"
static inline char *IPV6_TO_PRINT(void *ip) {
unsigned short *ipv6 = ip;
static char s[100];
int p = 0;
p += sprintf (s + p, "%x:", htons (ipv6[0]));
if (!ipv6[1]) {
p += sprintf (s + p, ":");
} else {
p += sprintf (s + p, "%x:", htons (ipv6[1]));
}
if (!ipv6[2]) {
p += sprintf (s + p, ":");
} else {
p += sprintf (s + p, "%x:", htons (ipv6[2]));
}
if (!ipv6[3]) {
p += sprintf (s + p, ":");
} else {
p += sprintf (s + p, "%x:", htons (ipv6[3]));
}
if (!ipv6[4]) {
p += sprintf (s + p, ":");
} else {
p += sprintf (s + p, "%x:", htons (ipv6[4]));
}
if (!ipv6[5]) {
p += sprintf (s + p, ":");
} else {
p += sprintf (s + p, "%x:", htons (ipv6[5]));
}
if (!ipv6[6]) {
p += sprintf (s + p, ":");
} else {
p += sprintf (s + p, "%x:", htons (ipv6[6]));
}
if (ipv6[7]) {
p += sprintf (s + p, "%x", htons (ipv6[7]));
}
return s;
}