-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.h
52 lines (40 loc) · 973 Bytes
/
utils.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
#ifndef __NMB_UTILS
#define __NMB_UTILS
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <sys/types.h>
#include <sys/msg.h>
#include <unistd.h>
#define TCP_PORT 1111
#define UDP_PORT 1112
#define RCVBUFSIZE 32
#define MSGSND 1
#define MSGRCV 2
#define LENGTH 100
struct msgbuf {
long mtype;
char mtext[LENGTH];
};
typedef struct msgbuf MsgBuf;
struct tcp_call{
int action;
struct msgbuf msg;
};
typedef struct tcp_call TcpCall;
typedef int nmb_t;
nmb_t msgget_nmb();
int msgsnd_nmb(nmb_t nmbid, MsgBuf msg,
size_t msgsz, int msgflg);
ssize_t msgrcv_nmb(nmb_t nmbid, MsgBuf* msgp,
size_t msgsz, long msgtyp, int msgflg);
int msgrem_nmb(nmb_t nmbid);
void die(char* str);
MsgBuf dummyMsg();
void ip_to_string(uint32_t addr, char* str);
long get_mtype(char* ip, int port);
void extract(long type, uint32_t* ip, int* port);
void get_my_port(nmb_t nmbid, int* p);
#endif