12#include <sys/socket.h>
14#include <netinet/in.h>
23#include "fileproto.pb.h"
33 if (istream !=
NULL && field->tag == ListFilesResponse_file_tag)
35 FileInfo fileinfo = {};
37 if (!
pb_decode(istream, FileInfo_fields, &fileinfo))
40 printf(
"%-10lld %s\n", (
long long)fileinfo.inode, fileinfo.name);
54 ListFilesRequest request = {};
61 request.has_path =
false;
65 request.has_path =
true;
66 if (
strlen(path) + 1 >
sizeof(request.path))
68 fprintf(
stderr,
"Too long path.\n");
72 strcpy(request.path, path);
86 ListFilesResponse response = {};
97 if (response.path_error)
99 fprintf(
stderr,
"Server reported error.\n");
110 struct sockaddr_in servaddr;
116 sockfd = socket(AF_INET, SOCK_STREAM, 0);
119 memset(&servaddr, 0,
sizeof(servaddr));
120 servaddr.sin_family = AF_INET;
121 servaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
122 servaddr.sin_port = htons(1234);
124 if (connect(sockfd, (
struct sockaddr *)&servaddr,
sizeof(servaddr)) != 0)
bool ListFilesResponse_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_iter_t *field)
bool listdir(int fd, char *path)
pb_ostream_t pb_ostream_from_socket(int fd)
pb_istream_t pb_istream_from_socket(int fd)
MOSAPI char * strcpy(char *__restrict dest, const char *__restrict src)
#define PB_GET_ERROR(stream)
bool pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct)
#define pb_decode_delimited(s, f, d)
#define pb_encode_delimited(s, f, d)
static void * memset(void *s, int c, size_t n)
static size_t strlen(const char *s)