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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 *  Copyright (c) 2005 Ian McDonald <[email protected]>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "common.hpp"

enum proto default_proto = DCCP;
string port = "5001";
string default_dest_path = "/video/m2m/inbox/VN_DEBRECEN_0115_recv.gxf";
string file = "/video/m2m/outbox/VN_DEBRECEN_0115.gxf";
int64_t fileSize = 1579685032;

void printerrno(const char *msg) {
	cout << msg << " " << errno << " " << strerror(errno) << endl;
}

void sigpipe(int dummy) {
}

string usedProto(enum proto protoNum) {
	string name = "";

	switch(protoNum) {
		case TCP:
			name = "TCP";
			break;
		case DCCP:
			name = "DCCP";
			break;
		case UDP:
			name = "UDP";
			break;
		case PUDT:
			name = "UDT";
			break;
	}

	return name;
}

int make_socket(void) {
	int new_sock;
	
	switch (default_proto) {
		case TCP:
			new_sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
			break;

		case DCCP:
			new_sock = socket(AF_INET,SOCK_DCCP,IPPROTO_DCCP);
			break;

		case UDP:
			new_sock = socket(AF_INET, SOCK_DGRAM, 0);
			break;

		case PUDT:
			new_sock = UDT::socket(AF_INET, SOCK_STREAM, 0);
			break;

		default:
			printf("make_socket - invalid protocol\n");
	}
	return new_sock;
}

void socket_options(int conn_sock) {
	int pkt_size = 256;
	
	int mtu_size = 256;
	int on = 1;
	socklen_t sizeMTU = (socklen_t) sizeof(mtu_size);
	
	switch (default_proto) {
		case DCCP:
			/*getsockopt(conn_sock, SOL_DCCP, DCCP_SOCKOPT_GET_CUR_MPS,(socklen_t*) &mtu_size, &sizeMTU);
			 *
			 *setsockopt(conn_sock,SOL_DCCP,DCCP_SOCKOPT_PACKET_SIZE,
			 *		(char*)&mtu_size,sizeof(mtu_size));
			 */
			setsockopt(conn_sock,SOL_DCCP,DCCP_SOCKOPT_SERVICE,
					(char*)&mtu_size,sizeof(mtu_size));

			setsockopt(conn_sock, SOL_DCCP, SO_REUSEADDR, (char*) &on, sizeof(on));

			break;
		case TCP:
		case UDP:
		case PUDT:
			break;
		default:
			printf("socket_options - invalid protocol\n");
	}

	int optval23 = 1;

	signal(SIGPIPE, sigpipe);
}

int str_to_int (string str) {
	int i;

	istringstream myStream(str);

	if (myStream >> i)
		return i;
	else
		return -1;
}

string convert_int2string(int64_t i) {
	stringstream s;
	s << i;
	return s.str();
}