1 | /* |
2 | This file is part of Mtproto-proxy Library. |
3 | |
4 | Mtproto-proxy Library is free software: you can redistribute it and/or modify |
5 | it under the terms of the GNU Lesser General Public License as published by |
6 | the Free Software Foundation, either version 2 of the License, or |
7 | (at your option) any later version. |
8 | |
9 | Mtproto-proxy Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public License |
15 | along with Mtproto-proxy Library. If not, see <http://www.gnu.org/licenses/>. |
16 | |
17 | Copyright 2012-2013 Vkontakte Ltd |
18 | 2012-2013 Vitaliy Valtman |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include <stdio.h> |
24 | #include <arpa/inet.h> |
25 | |
26 | #define PID_PRINT_STR "[" IP_PRINT_STR ":%d:%d:%d]" |
27 | #define IP_PRINT_STR "%d.%d.%d.%d" |
28 | |
29 | #define PID_TO_PRINT(a) IP_TO_PRINT((a)->ip), (int)(a)->port, (int)(a)->pid, (a)->utime |
30 | #define IP_TO_PRINT(a) ((a) >> 24) & 0xff, ((a) >> 16) & 0xff, ((a) >> 8) & 0xff, (a) & 0xff |
31 | |
32 | #define IPV6_PRINT_STR "%s" |
33 | |
34 | static inline char *IPV6_TO_PRINT(void *ip) { |
35 | unsigned short *ipv6 = ip; |
36 | |
37 | static char s[100]; |
38 | int p = 0; |
39 | p += sprintf (s + p, "%x:" , htons (ipv6[0])); |
40 | if (!ipv6[1]) { |
41 | p += sprintf (s + p, ":" ); |
42 | } else { |
43 | p += sprintf (s + p, "%x:" , htons (ipv6[1])); |
44 | } |
45 | if (!ipv6[2]) { |
46 | p += sprintf (s + p, ":" ); |
47 | } else { |
48 | p += sprintf (s + p, "%x:" , htons (ipv6[2])); |
49 | } |
50 | if (!ipv6[3]) { |
51 | p += sprintf (s + p, ":" ); |
52 | } else { |
53 | p += sprintf (s + p, "%x:" , htons (ipv6[3])); |
54 | } |
55 | if (!ipv6[4]) { |
56 | p += sprintf (s + p, ":" ); |
57 | } else { |
58 | p += sprintf (s + p, "%x:" , htons (ipv6[4])); |
59 | } |
60 | if (!ipv6[5]) { |
61 | p += sprintf (s + p, ":" ); |
62 | } else { |
63 | p += sprintf (s + p, "%x:" , htons (ipv6[5])); |
64 | } |
65 | if (!ipv6[6]) { |
66 | p += sprintf (s + p, ":" ); |
67 | } else { |
68 | p += sprintf (s + p, "%x:" , htons (ipv6[6])); |
69 | } |
70 | if (ipv6[7]) { |
71 | p += sprintf (s + p, "%x" , htons (ipv6[7])); |
72 | } |
73 | |
74 | return s; |
75 | } |
76 | |
77 | |