-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.h
63 lines (53 loc) · 1.28 KB
/
net.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
57
58
59
60
61
62
63
/**
* portmap net part
*
* author:liyangguang ([email protected])
* date: 2011-01-14 15:11:01
*
* changes
*/
#ifndef _PORTMAP_NET_H
#define _PORTMAP_NET_H
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <pthread.h>
#include "list.h"
#define MAX_PORT_NUM 65536
#define MAX_REQ_SIZE 1024
#define MAX_DATA_LEN 65536
struct local_server
{
int sockfd;
unsigned int listen_port;
unsigned int accepted_num;
/** port range to map */
unsigned int lower_port;
unsigned int high_port;
unsigned int used_ports[MAX_PORT_NUM];
};
struct mapped_server
{
int sockfd;
unsigned int listen_port;
unsigned int accepted_num;
/** src address to map */
char src_addr[INET_ADDRSTRLEN];
unsigned int src_port;
/** mapped address */
char dest_addr[INET_ADDRSTRLEN];
struct local_server *ls;
struct list_head ms_list;
};
struct mapped_pair
{
int remote_sockfd; // connect to src address
int local_sockfd; // client connect to dest address
unsigned int send_bytes;
unsigned int recv_bytes;
int ref; //ref = 2
struct mapped_server *ms;
pthread_mutex_t mutex;
};
int init_local_server(unsigned int port, unsigned int lower_port, unsigned int high_port);
#endif /*_PORTMAP_NET_H */