Skip to content

Instantly share code, notes, and snippets.

@ammarfaizi2
Created October 11, 2023 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ammarfaizi2/228cea37709c0e57c2b250ac6d8dfe45 to your computer and use it in GitHub Desktop.
Save ammarfaizi2/228cea37709c0e57c2b250ac6d8dfe45 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2023 Ammar Faizi <ammarfaizi2@gnuweeb.org>
* Copyright (C) 2023 Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
*/
#ifndef GWFT_H
#define GWFT_H
#include <stdint.h>
#ifndef __packed
#define __packed __attribute__((__packed__))
#endif
typedef uint16_t __be16;
typedef uint32_t __be32;
typedef uint64_t __be64;
struct gwft_pkt_handshake {
__be16 version;
__be16 patch_level;
__be16 sub_level;
uint8_t extra_len;
uint8_t flags;
char extra[];
} __packed;
struct gwft_pktcl_get_list_file {
__be32 limit;
__be32 offset;
} __packed;
struct gwft_pktsr_list_file {
__be32 nr_files;
} __packed;
struct gwft_pktsr_file {
__be64 file_size;
__be32 id;
__be16 file_name_len;
char file_name[];
} __packed;
struct gwft_pktsr_file_data {
__be64 offset;
__be64 len;
__be32 file_id;
char data[];
} __packed;
struct gwft_pktcl_get_file {
__be64 offset;
__be64 len;
__be32 file_id;
} __packed;
enum {
GWFT_PKT_CLOSE = 0x00,
GWFT_PKT_CL_HANDSHAKE = 0x10,
GWFT_PKT_CL_GET_LIST_FILE = 0x11,
GWFT_PKT_CL_GET_FILE = 0x12,
GWFT_PKT_SR_HANDSHAKE = 0x20,
GWFT_PKT_SR_LIST_FILE = 0x21,
GWFT_PKT_SR_FILE = 0x22,
GWFT_PKT_SR_FILE_DATA = 0x23,
};
struct gwft_pkt {
uint8_t type;
uint8_t __pad;
__be16 len;
union {
struct gwft_pkt_handshake handshake;
struct gwft_pktcl_get_list_file get_list_file;
struct gwft_pktcl_get_file get_file;
struct gwft_pktsr_list_file list_file;
struct gwft_pktsr_file file;
struct gwft_pktsr_file_data file_data;
char __raw[4096];
};
};
int run_server(int argc, char *argv[]);
int run_client(int argc, char *argv[]);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment