2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-29 05:18:00 +00:00

sockets: Add sock_type_name and tcp_state_name helpers

For readable printings.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Cyrill Gorcunov 2018-06-09 16:06:49 +03:00 committed by Andrei Vagin
parent 5c26d80639
commit 21f09b44ce
2 changed files with 47 additions and 0 deletions

View File

@ -97,4 +97,7 @@ extern int set_netns(uint32_t ns_id);
extern int kerndat_socket_netns(void);
extern int kerndat_socket_unix_file(void);
extern const char *tcp_state_name(unsigned int state);
extern const char *socket_type_name(unsigned int type);
#endif /* __CR_SOCKETS_H__ */

View File

@ -39,6 +39,50 @@
#define SO_GET_FILTER SO_ATTACH_FILTER
#endif
const char *socket_type_name(unsigned int type)
{
static const char *types[] = {
[SOCK_STREAM] = __stringify_1(SOCK_STREAM),
[SOCK_DGRAM] = __stringify_1(SOCK_DGRAM),
[SOCK_RAW] = __stringify_1(SOCK_RAW),
[SOCK_SEQPACKET] = __stringify_1(SOCK_SEQPACKET),
[SOCK_PACKET] = __stringify_1(SOCK_PACKET),
};
size_t i;
for (i = 0; i < ARRAY_SIZE(types); i++) {
if (type == i)
return types[i];
}
return "UNKNOWN";
}
const char *tcp_state_name(unsigned int state)
{
static const char *states[] = {
[TCP_ESTABLISHED] = __stringify_1(TCP_ESTABLISHED),
[TCP_SYN_SENT] = __stringify_1(TCP_SYN_SENT),
[TCP_SYN_RECV] = __stringify_1(TCP_SYN_RECV),
[TCP_FIN_WAIT1] = __stringify_1(TCP_FIN_WAIT1),
[TCP_FIN_WAIT2] = __stringify_1(TCP_FIN_WAIT2),
[TCP_TIME_WAIT] = __stringify_1(TCP_TIME_WAIT),
[TCP_CLOSE] = __stringify_1(TCP_CLOSE),
[TCP_CLOSE_WAIT] = __stringify_1(TCP_CLOSE_WAIT),
[TCP_LAST_ACK] = __stringify_1(TCP_LAST_ACK),
[TCP_LISTEN] = __stringify_1(TCP_LISTEN),
[TCP_CLOSING] = __stringify_1(TCP_CLOSING),
};
size_t i;
for (i = 0; i < ARRAY_SIZE(states); i++) {
if (state == i)
return states[i];
}
return "UNKNOWN";
}
struct sock_diag_greq {
u8 family;
u8 protocol;