-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
executable file
·56 lines (51 loc) · 1.52 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/***
*
*/
#ifndef __COMMON_H
#define __COMMON_H
/******************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
/******************************************************************************/
#define MAXSIZE 256
#define MAXBUFLEN 264
#define PORT_SERVER 2222
#define PORT_CLIENTE 12344
#define VERSION 0x01
#define OP_NUEVO_REG 0x01
#define OP_CONSULTA_REG 0x02
#define OP_ELIM_REG 0x03
#define OP_OK 0x00
#define OP_KO 0x01
#define VERBOSE 1
#define NOVERBOSE 0
/******************************************************************************/
struct nuevo_registro /* 1 + 1 + 2 + 4 + 256 = 264 bytes */
{
char version;
char op;
unsigned short puerto;
unsigned long ip;
char id[MAXSIZE];
} __attribute__((packed));
struct respuesta /* 1 + 1 + 256 = 258 bytes */
{
char version;
char op;
char mensaje[MAXSIZE];
} __attribute__((packed));
struct resp_consulta /* 1 + 1 + 2 + 4 = 8 bytes */
{
char version;
char op;
unsigned short puerto;
unsigned long ip;
} __attribute__((packed));
/******************************************************************************/
int envia_paquete(int sockfd, struct sockaddr_in server_addr, void * paquete, int len, int verbose);
char * recibe_paquete(int sockfd, struct sockaddr_in server_addr);
/******************************************************************************/
#endif