Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/checkpoint-restore/criu.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2018-06-09 16:06:49 +0300
committerAndrei Vagin <avagin@virtuozzo.com>2018-06-19 22:51:01 +0300
commit21f09b44ced7e74996be7b7a045d9c6ecf99698d (patch)
tree4a1ccaccc6137b3301ab591b45daf0cb69fbacb2
parent5c26d8063923bdf4213c1e8a83157ac7beede88c (diff)
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>
-rw-r--r--criu/include/sockets.h3
-rw-r--r--criu/sockets.c44
2 files changed, 47 insertions, 0 deletions
diff --git a/criu/include/sockets.h b/criu/include/sockets.h
index db3304288..1d0e1f293 100644
--- a/criu/include/sockets.h
+++ b/criu/include/sockets.h
@@ -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__ */
diff --git a/criu/sockets.c b/criu/sockets.c
index f8504d9c5..eec282027 100644
--- a/criu/sockets.c
+++ b/criu/sockets.c
@@ -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;