Revision 11fce711

View differences:

ml.c
55 55
#include "transmissionHandler.h"
56 56

  
57 57
#define LOG_MODULE "[ml] "
58
#include "grapes_log.h"
58
#include "ml_log.h"
59 59

  
60 60
/**************************** START OF INTERNALS ***********************/
61 61

  
......
161 161
void register_recv_localsocketID_cb(receive_localsocketID_cb local_socketID_cb)
162 162
{
163 163
	if (local_socketID_cb == NULL)
164
		printf("Register receive_localsocketID_cb: NULL ptr \n");
164
		error("ML : Register receive_localsocketID_cb: NULL ptr \n");
165 165
	else
166 166
	receive_SocketID_cb = local_socketID_cb;
167 167
}
168 168

  
169 169

  
170
void keep_connection_alive(const int connectionID)
171
{
172

  
173
    // to be done with the NAT traversal
174
    // send a message over the wire
175
    printf("\n");
176

  
177
}
170
//void keep_connection_alive(const int connectionID)
171
//{
172
//
173
//    // to be done with the NAT traversal
174
//    // send a message over the wire
175
//    printf("\n");
176
//
177
//}
178 178

  
179 179
void unsetStunServer()
180 180
{
......
304 304
		connectbuf[con_id]->ctrl_msg_buf = malloc(MAX);
305 305

  
306 306
	if(connectbuf[con_id]->ctrl_msg_buf == NULL) {
307
		error("ML: can not allocate memory for connection message");
307
		error("ML: can not allocate memory for connection message\n");
308 308
		return;
309 309
	}
310 310

  
......
361 361
		* send an ok
362 362
		*/
363 363
		case INVITE:
364
			debug("ML: received INVITE");
364
			debug("ML: received INVITE\n");
365 365
			/*
366 366
			* check if another connection for the external connectionID exist
367 367
			* that was established within the last 2 seconds
......
381 381
			if (con_id == CONNECTBUFSIZE) {
382 382
				// create an entry in the connecttrybuf
383 383
				if(free_con_id == -1) {
384
					error("ML: no new connect_buf available");
384
					error("ML: no new connect_buf available\n");
385 385
					return;
386 386
				}
387 387
				connectbuf[free_con_id] = (connect_data *) malloc(sizeof(connect_data));
......
403 403
			}
404 404
			break;
405 405
		case CONNECT:
406
			debug("ML: received CONNECT");
406
			debug("ML: received CONNECT\n");
407 407

  
408 408
			if(msg_h->remote_con_id != -1 && connectbuf[msg_h->remote_con_id] == NULL) {
409
				error("ML: received CONNECT for unexistent connection");
409
				error("ML: received CONNECT for inexistent connection\n");
410 410
				return;
411 411
			}
412 412

  
......
441 441
				// send the READY
442 442
				send_conn_msg(msg_h->remote_con_id, con_msg->pmtu_size, READY);
443 443

  
444
			debug("ML: active connection established");
444
			debug("ML: active connection established\n");
445 445
			break;
446 446

  
447 447
			/*
......
449 449
			* connection active change the pmtu size
450 450
			*/
451 451
		case READY:
452
			debug("ML: received READY");
452
			debug("ML: received READY\n");
453 453
			if(connectbuf[msg_h->remote_con_id] == NULL) {
454
				error("ML: received READY for unexistent connection");
454
				error("ML: received READY for inexistent connection\n");
455 455
				return;
456 456
			}
457 457
			/*
......
475 475
				}
476 476
				connectbuf[msg_h->remote_con_id]->connection_head =
477 477
					connectbuf[msg_h->remote_con_id]->connection_last = NULL;
478
				debug("ML: passiv connection established");
478
				debug("ML: passive connection established\n");
479 479
			}
480 480
			break;
481 481
	}
......
516 516
void recv_timeout_cb(int fd, short event, void *arg)
517 517
{
518 518
	int recv_id = (long) arg;
519
	debug("ML: recv_timeout_cb called");
519
	debug("ML: recv_timeout_cb called\n");
520 520

  
521 521
	if (recvdatabuf[recv_id] == NULL) {
522 522
		return;
......
584 584
// process a single recv data message
585 585
void recv_data_msg(struct msg_header *msg_h, char *msgbuf, int bufsize)
586 586
{
587
	debug("transmissionHandler: received data message called");
587
	debug("ML: received data message called\n");
588 588

  
589 589
	int recv_id, free_recv_id = -1;
590 590

  
591 591
	if(connectbuf[msg_h->remote_con_id] == NULL) {
592
		debug("ML: Received a message not related to any opened connection!");
592
		debug("ML: Received a message not related to any opened connection!\n");
593 593
		return;
594 594
	}
595 595

  
......
708 708
//done
709 709
void pmtu_timeout_cb(int fd, short event, void *arg)
710 710
{
711
	debug("ML: pmtu timeout called");
711
	debug("ML: pmtu timeout called\n");
712 712

  
713 713
	int con_id = (long) arg;
714 714
	pmtu new_pmtusize;
715 715
	struct timeval timeout;
716 716

  
717 717
	if(connectbuf[con_id] == NULL) {
718
		error("ML: pmtu timeout called on non existing con_id");
718
		error("ML: pmtu timeout called on non existing con_id\n");
719 719
		return;
720 720
	}
721 721

  
......
751 751
			connectbuf[con_id]->pmtusize = MAX;
752 752
		} else {
753 753
			//nothing to do we have to give up
754
			error("ML: Could not create connection with connectionID %i!",con_id);
754
			error("ML: Could not create connection with connectionID %i!\n",con_id);
755 755
			// envoke the callback for failed connection establishment
756 756
			if(failed_Connection_cb != NULL)
757 757
				(failed_Connection_cb) (con_id, NULL);
......
794 794

  
795 795
void pmtu_error_cb_th(char *msg, int msglen)
796 796
{
797
	debug("ML: pmtu_error callback called msg_size: %d",msglen);
797
	debug("ML: pmtu_error callback called msg_size: %d\n",msglen);
798 798
	//TODO debug
799 799
	return;
800 800

  
......
846 846
//    connectbuf[connectionID]->pmtutrysize = new_pmtusize;
847 847

  
848 848
    if (new_pmtusize == ERROR) {
849
		fprintf(stderr,
850
			"transmissionHandler:  Could not create connection with connectionID %i !\n",
849
		error("ML:  Could not create connection with connectionID %i !\n",
851 850
			connectionID);
852 851

  
853 852
		if(failed_Connection_cb != NULL)
......
940 939
//done --
941 940
void recv_pkg(int fd, short event, void *arg)
942 941
{
943
	debug("ML: recv_pkg called");
942
	debug("ML: recv_pkg called\n");
944 943

  
945 944
	struct msg_header *msg_h;
946 945
	char msgbuf[MAX];
......
961 960
	unsigned short stun_bind_response = 0x0101;
962 961
	unsigned short * msgspot = (unsigned short *) msgbuf;
963 962
	if (*msgspot == stun_bind_response) {
964
		debug("ML: recv_pkg: parse stun message called");
963
		debug("ML: recv_pkg: parse stun message called\n");
965 964
		recv_stun_msg(msgbuf, recvSize);
966 965
		return;
967 966
	}
......
981 980
			msginfNow.remote_socketID = &(c_msg->sock_id);
982 981
		}
983 982
		else if(connectbuf[msg_h->remote_con_id] == NULL) {
984
			error("ML: received pkg called with non existent connection");
983
			error("ML: received pkg called with non existent connection\n");
985 984
			return;
986 985
		} else
987 986
			msginfNow.remote_socketID = &(connectbuf[msg_h->remote_con_id]->external_socketID);
......
999 998

  
1000 999
	switch(msg_h->msg_type) {
1001 1000
		case ML_CON_MSG:
1002
			debug("ML: received conn pkg");
1001
			debug("ML: received conn pkg\n");
1003 1002
			recv_conn_msg(msg_h, bufptr, msg_size);
1004 1003
			break;
1005 1004
		default:
1006 1005
			if(msg_h->msg_type < 127) {
1007
				debug("ML: received data pkg");
1006
				debug("ML: received data pkg\n");
1008 1007
				recv_data_msg(msg_h, bufptr, msg_size);
1009 1008
				break;
1010 1009
			}
1011
			debug("ML: unrecognised msg_type");
1010
			debug("ML: unrecognised msg_type\n");
1012 1011
			break;
1013 1012
	}
1014 1013
}
......
1030 1029
void nat_traversal_timeout(int fd, short event, void *arg)
1031 1030
{
1032 1031
	if (NAT_traversal == false) {
1033
		debug("ML: NAT traversal request resend");
1032
		debug("ML: NAT traversal request re-send\n");
1034 1033
		send_stun_request(socketfd, &stun_server);
1035 1034

  
1036 1035
		/*
......
1049 1048
{
1050 1049
	struct hostent *h = gethostbyname(ipaddr);
1051 1050
	if (!h) {
1052
		error("Unable to resolve hostname %s\n", ipaddr);
1051
		error("Unable to resolve host name %s\n", ipaddr);
1053 1052
	exit(-1);
1054 1053
    }
1055 1054
    unsigned long *addr = (unsigned long *) (h->h_addr);
......
1139 1138
void mlRegisterGetRecvPktInf(get_recv_pkt_inf_cb recv_pkt_inf_cb){
1140 1139

  
1141 1140
	if (recv_pkt_inf_cb == NULL)
1142
		printf("Register get_recv_pkt_inf_cb failed: NULL ptr  \n");
1141
		error("Register get_recv_pkt_inf_cb failed: NULL ptr  \n");
1143 1142
	else
1144 1143
		get_Recv_pkt_inf_cb = recv_pkt_inf_cb;
1145 1144

  
......
1148 1147
void mlRegisterGetSendPktInf(get_send_pkt_inf_cb  send_pkt_inf_cb){
1149 1148

  
1150 1149
	if (send_pkt_inf_cb == NULL)
1151
		printf("Register get_send_pkt_inf_cb: NULL ptr  \n");
1150
		error("Register get_send_pkt_inf_cb: NULL ptr  \n");
1152 1151
	else
1153 1152
		get_Send_pkt_inf_cb = send_pkt_inf_cb;
1154 1153

  
......
1158 1157
void mlRegisterSetMonitoringHeaderPktCb(set_monitoring_header_pkt_cb monitoring_header_pkt_cb ){
1159 1158

  
1160 1159
	if (monitoring_header_pkt_cb == NULL)
1161
		printf("Register set_monitoring_header_pkt_cb: NULL ptr  \n");
1160
		error("Register set_monitoring_header_pkt_cb: NULL ptr  \n");
1162 1161
	else
1163 1162
		set_Monitoring_header_pkt_cb = monitoring_header_pkt_cb;
1164 1163

  
......
1167 1166
void mlRegisterGetRecvDataInf(get_recv_data_inf_cb recv_data_inf_cb){
1168 1167

  
1169 1168
	if (recv_data_inf_cb == NULL)
1170
		printf("Register get_recv_data_inf_cb: NULL ptr  \n");
1169
		error("Register get_recv_data_inf_cb: NULL ptr  \n");
1171 1170
	else
1172 1171
		get_Recv_data_inf_cb = recv_data_inf_cb;
1173 1172

  
......
1176 1175
void mlRegisterGetSendDataInf(get_send_data_inf_cb  send_data_inf_cb){
1177 1176

  
1178 1177
	if (send_data_inf_cb == NULL)
1179
		printf("Register get_send_data_inf_cb: NULL ptr  \n");
1178
		error("Register get_send_data_inf_cb: NULL ptr  \n");
1180 1179
	else
1181 1180
		get_Send_data_inf_cb = send_data_inf_cb;
1182 1181

  
......
1185 1184
void mlRegisterSetMonitoringHeaderDataCb(set_monitoring_header_data_cb monitoring_header_data_cb){
1186 1185

  
1187 1186
	if (monitoring_header_data_cb == NULL)
1188
		printf("Register set_monitoring_header_data_cb : NULL ptr  \n");
1187
		error("Register set_monitoring_header_data_cb : NULL ptr  \n");
1189 1188
	else
1190 1189
	set_Monitoring_header_data_cb = monitoring_header_data_cb;
1191 1190

  
......
1194 1193
void mlRegisterRecvConnectionCb(receive_connection_cb recv_conn_cb){
1195 1194

  
1196 1195
	if (recv_conn_cb == NULL)
1197
		printf("Register receive_connection_cb: NULL ptr  \n");
1196
		error("Register receive_connection_cb: NULL ptr  \n");
1198 1197
	else
1199 1198
		receive_Connection_cb = recv_conn_cb;
1200 1199

  
......
1203 1202
void mlRegisterErrorConnectionCb(connection_failed_cb conn_failed){
1204 1203

  
1205 1204
	if (conn_failed == NULL)
1206
		printf("Register connection_failed_cb: NULL ptr  \n");
1205
		error("Register connection_failed_cb: NULL ptr  \n");
1207 1206
	else
1208 1207
	failed_Connection_cb = conn_failed;
1209 1208

  
......
1213 1212

  
1214 1213
    if (msgtype > 126) {
1215 1214

  
1216
	printf
1217
	    ("transmissionHandler: Could not register recv_data callback. Msgtype is greater then 126 \n");
1215
    	error
1216
	    ("ML: Could not register recv_data callback. Msgtype is greater then 126 \n");
1218 1217

  
1219 1218
    }
1220 1219

  
1221 1220
    if (data_cb == NULL) {
1222 1221

  
1223
	printf("Register receive data callback: NUll ptr \n ");
1222
    	error("ML: Register receive data callback: NUll ptr \n ");
1224 1223

  
1225 1224
    } else {
1226 1225

  
......
1277 1276

  
1278 1277
	int con_id;
1279 1278
	if (external_socketID == NULL) {
1280
		error("ML: cannot open connection: one of the socketIDs is NULL");
1279
		error("ML: cannot open connection: one of the socketIDs is NULL\n");
1281 1280
		return -1;
1282 1281
	}
1283 1282
	if (NAT_traversal == false) {
1284
		error("ML: cannot open connection: NAT traversal for socketID still in progress");
1283
		error("ML: cannot open connection: NAT traversal for socketID still in progress\n");
1285 1284
		return -1;
1286 1285
	}
1287 1286
	if (connection_cb == NULL) {
1288
		error("ML: cannot open connection: connection_cb is NULL");
1287
		error("ML: cannot open connection: connection_cb is NULL\n");
1289 1288
		return -1;
1290 1289
	}
1291 1290

  
......
1350 1349
	} //end of for
1351 1350

  
1352 1351
	if (con_id == CONNECTBUFSIZE) {
1353
		error("ML: Could not open connection: connbuffer full");
1352
		error("ML: Could not open connection: connection buffer full\n");
1354 1353
		return -1;
1355 1354
	}
1356 1355

  
......
1380 1379
void mlSendData(const int connectionID,char *sendbuf,int bufsize,unsigned char msgtype,send_params *sParams){
1381 1380

  
1382 1381
	if (connectionID < 0) {
1383
		error("ML: send data failed: connectionID does not exist");
1382
		error("ML: send data failed: connectionID does not exist\n");
1384 1383
		return;
1385 1384
	}
1386 1385

  
1387 1386
	if (connectbuf[connectionID] == NULL) {
1388
		error("ML: send data failed: connectionID does not exist");
1387
		error("ML: send data failed: connectionID does not exist\n");
1389 1388
		return;
1390 1389
	}
1391 1390
	if (connectbuf[connectionID]->status != READY) {
1392
	    error("ML: send data failed: connection is not active");
1391
	    error("ML: send data failed: connection is not active\n");
1393 1392
	    return;
1394 1393
	}
1395 1394

  
......
1406 1405

  
1407 1406
    if (nr_entries < 1 || nr_entries > 5) {
1408 1407

  
1409
	printf
1410
	    ("send_all_data ERROR: nr_enties is not between 1 and 5 \n ");
1408
	error
1409
	    ("ML : sendALlData : nr_enties is not between 1 and 5 \n ");
1411 1410
	return 0;
1412 1411

  
1413 1412
    } else {
......
1494 1493
	return 0;
1495 1494
#if 0
1496 1495
	if (rParams == NULL) {
1497
		error("ML: recv_data failed: recv_params is a NULL ptr");
1496
		error("ML: recv_data failed: recv_params is a NULL ptr\n");
1498 1497
		return 0;
1499 1498
    } else {
1500 1499

  
1501
	printf("transmissionhandler: recv data called \n");
1500
	info("ML: recv data called \n");
1502 1501

  
1503 1502
	int i = 0;
1504 1503
	int returnValue = 0;
......
1511 1510

  
1512 1511
		if (recvdatabuf[i]->connectionID == connectionID) {
1513 1512

  
1514
		    printf("transmissionhandler: recv data has entry  \n");
1513
		    info("ML: recv data has entry  \n");
1515 1514

  
1516 1515
		    double timepass = difftime(endtime, recvdatabuf[i]->starttime);
1517 1516

  
......
1596 1595

  
1597 1596
			if (timepass > timeout) {
1598 1597

  
1599
			    printf("transmissionHandler: recv_data timeout called  \n");
1598
			    info("ML: recv_data timeout called  \n");
1600 1599

  
1601 1600
			    // some data about the missing chunks should
1602 1601
			    // be added here
......
1809 1808

  
1810 1809
//Added by Robert Birke as comodity functions
1811 1810

  
1812
int mlPrintSocketID(socketID_handle socketID) {
1813
	char str[SOCKETID_STRING_SIZE];
1814
	mlSocketIDToString(socketID, str, sizeof(str));
1815
	printf("int->%s<-ext\n",str);
1816
}
1811
//int mlPrintSocketID(socketID_handle socketID) {
1812
//	char str[SOCKETID_STRING_SIZE];
1813
//	mlSocketIDToString(socketID, str, sizeof(str));
1814
//	printf(stderr,"int->%s<-ext\n",str);
1815
//}
1817 1816

  
1818 1817
/*
1819 1818
 * hash code of a socketID
ml_log.h
3 3

  
4 4
#include <stdlib.h>
5 5
#include <stdio.h>
6
#include "grapes_log.h"
6
//#include "grapes_log.h"
7 7

  
8 8
#ifndef _GRAPES_LOG_H
9 9

  
10
#define debug(format, ... ) printf(format, ##__VA_ARGS__ )
10
#define debug(format, ... ) fprintf(stderr, format, ##__VA_ARGS__ )
11 11
/** Convenience macro to log LOG_INFO messages */
12
#define info(format, ... )  printf(format, ##__VA_ARGS__ )
12
#define info(format, ... )  fprintf(stderr, format, ##__VA_ARGS__ )
13 13
/** Convenience macro to log LOG_WARN messages */
14
#define warn(format, ... )  printf(format, ##__VA_ARGS__ )
14
#define warn(format, ... )  fprintf(stderr, format, ##__VA_ARGS__ )
15 15
/** Convenience macro to log LOG_ERROR messages */
16
#define error(format, ... )  printf(format, ##__VA_ARGS__ )
16
#define error(format, ... )  fprintf(stderr, format, ##__VA_ARGS__ )
17 17
/**  Convenience macro to log LOG_CRITICAL messages and crash the program */
18
#define fatal(format, ... )  { printf(format, ##__VA_ARGS__ ); exit(-1); }
18
#define fatal(format, ... )  { fprintf(stderr, format, ##__VA_ARGS__ ); exit(-1); }
19 19

  
20 20
#endif
21 21
#endif
util/stun.c
54 54
//#include <resolv.h>
55 55
#include <net/if.h>
56 56

  
57
#include "ml_log.h"
57 58
#include "stun.h"
58 59
#include "udpSocket.h"
59 60

  
......
179 180
  if ( verbose )
180 181
  {
181 182

  
182
      printf( "\t mappedAddr= ipv4 %s port %d \n \t changedAddr= ipv4 %s port %d \n",
183
      info( "\t mappedAddr= ipv4 %s port %d \n \t changedAddr= ipv4 %s port %d \n",
183 184
              mapped_addr ,
184 185
              response->mappedAddress.ipv4.port,
185 186
              changed_addr,
......
200 201
{
201 202
   if ( hdrLen != 8 )
202 203
   {
203
      printf("hdrlen is not 8 \n ");
204
      error("hdrlen is not 8 \n ");
204 205
      return false;
205 206
   }
206 207
   result->pad = *body++;
......
212 213
      UInt16 nport;
213 214
      memcpy(&nport, body, 2); body+=2;
214 215
      
215
      if (verbose) printf("port %i \n",ntohs(nport));
216
      if (verbose) info("port %i \n",ntohs(nport));
216 217

  
217 218
      result->ipv4.port = ntohs(nport);
218 219

  
......
228 229

  
229 230
      sprintf(str_p,"%d.%d.%d.%d",(ip_addr >> 24) & 0xff,(ip_addr >> 16) & 0xff,(ip_addr >> 8) & 0xff,ip_addr & 0xff);          
230 231

  
231
      printf(" ipv4 as str %s \n  ",str_p);
232
      info(" ipv4 as str %s \n  ",str_p);
232 233
	}
233 234

  
234 235
      result->ipv4.addr = ntohl(naddr);
......
239 240
   else if (result->family == IPv6Family)
240 241

  
241 242
   {
242
      printf("ipv6 not supported  \n");
243
      warn("ipv6 not supported  \n");
243 244
   }
244 245
   else
245 246
   {
246
      printf("bad address family: %i \n ",result->family );
247
      error("bad address family: %i \n ",result->family );
247 248
   }
248 249
	
249 250
   return false;
......
254 255
bool
255 256
stunParseMessage( char* buf, unsigned int bufLen, StunMessage *msg, bool verbose)
256 257
{
257
  if (verbose) printf("Received stun message: %d bytes \n",bufLen);
258
  if (verbose) info("Received stun message: %d bytes \n",bufLen);
258 259
   memset(msg, 0, sizeof(msg));
259 260
	
260 261
   if (sizeof(StunMsgHdr) > bufLen)
261 262
   {
262
     printf("Bad message \n");
263
     error("Bad message \n");
263 264
      return false;
264 265
   }
265 266
	
......
269 270
	
270 271
   if (msg->msgHdr.msgLength + sizeof(StunMsgHdr) != bufLen)
271 272
   {
272
     printf("Message header length doesn't match message size: %d - %d \n"
273
     error("Message header length doesn't match message size: %d - %d \n"
273 274
	    ,msg->msgHdr.msgLength,bufLen);
274 275
      return false;
275 276
   }
......
291 292
      //if (verbose) clog << "Found attribute type=" << AttrNames[atrType] << " length=" << attrLen << endl;
292 293
      if ( attrLen+4 > size ) 
293 294
      {
294
	printf( "claims attribute is larger than size of message " \
295
	debug( "claims attribute is larger than size of message " \
295 296
		"(attribute type= %d \n" ,atrType);
296 297
         return false;
297 298
      }
......
305 306
	//printf("has mapped address \n");
306 307
        if ( stunParseAtrAddress(body, attrLen, &msg->mappedAddress, verbose) == false)
307 308
            {
308
	      printf("problem parsing MappedAddress \n");
309
        	debug("problem parsing MappedAddress \n");
309 310
               return false;
310 311
            }
311 312
            else
312 313
            {
313
	      if (verbose) {printf("MappedAddress -------------------\n");}
314
	      if (verbose) {info("MappedAddress -------------------\n");}
314 315
            }
315 316
					
316 317
      }else 
......
319 320
            msg->hasResponseAddress = true;
320 321
            if ( stunParseAtrAddress(  body,  attrLen,  &msg->responseAddress, verbose )== false )
321 322
            {
322
	      printf("problem parsing ResponseAddress \n");
323
            	debug("problem parsing ResponseAddress \n");
323 324
              return false;
324 325
            }
325 326
            else
326 327
            {
327
	      if (verbose) {printf("ResponseAddress ---------------------\n");}
328
	      if (verbose) {info("ResponseAddress ---------------------\n");}
328 329
            }
329 330
             
330 331
	}else if(atrType == ChangeRequest)
......
332 333
            msg->hasChangeRequest = true;
333 334
            if (stunParseAtrChangeRequest( body, attrLen, &msg->changeRequest) == false)
334 335
            {
335
	      printf("problem parsing ChangeRequest \n");
336
            	debug("problem parsing ChangeRequest \n");
336 337
               return false;
337 338
            }
338 339
            else
339 340
            {
340
	      if (verbose) printf("ChangeRequest = %i \n",(int)&msg->changeRequest.value);
341
	      if (verbose) info("ChangeRequest = %i \n",(int)&msg->changeRequest.value);
341 342
            }
342 343
            
343 344
	} else if (atrType == SourceAddress)
......
345 346
            msg->hasSourceAddress = true;
346 347
            if ( stunParseAtrAddress(  body,  attrLen,  &msg->sourceAddress, verbose )== false )
347 348
            {
348
	      printf("problem parsing SourceAddress \n");
349
            	debug("problem parsing SourceAddress \n");
349 350
               return false;
350 351
            }
351 352
            else
352 353
            {
353
	      if (verbose) printf("SourceAddress ------------------\n");
354
	      if (verbose) info("SourceAddress ------------------\n");
354 355
            }
355 356
	} else if (atrType ==  ChangedAddress)
356 357
	{
357 358
            msg->hasChangedAddress = true;
358 359
            if ( stunParseAtrAddress(  body,  attrLen, &msg->changedAddress, verbose )== false )
359 360
            {
360
	      printf("problem parsing ChangedAddress \n");
361
            	debug("problem parsing ChangedAddress \n");
361 362
               return false;
362 363
            }
363 364
            else
364 365
            {
365
	      if (verbose) printf("ChangedAddress = ---------------------\n");
366
	      if (verbose) info("ChangedAddress = ---------------------\n");
366 367
            }
367 368
	} else if (atrType ==  Username) 
368 369
	{
369 370
            msg->hasUsername = true;
370 371
            if (stunParseAtrString( body, attrLen, &msg->username) == false)
371 372
            {
372
	      printf("problem parsing Username \n");
373
            	debug("problem parsing Username \n");
373 374
               return false;
374 375
            }
375 376
            else
376 377
            {
377
	      if (verbose) printf("Username = %s \n",msg->username.value);
378
	      if (verbose) info("Username = %s \n",msg->username.value);
378 379
            }
379 380
	}else if (atrType ==  Password) 
380 381
	 {
381 382
            msg->hasPassword = true;
382 383
            if (stunParseAtrString( body, attrLen, &msg->password) == false)
383 384
            {
384
	      printf("problem parsing Password \n");
385
	      debug("problem parsing Password \n");
385 386
               return false;
386 387
            }
387 388
            else
388 389
            {
389
	      if (verbose) printf("Password = %s \n",(char *)&msg->password.value);
390
	      if (verbose) info("Password = %s \n",(char *)&msg->password.value);
390 391
            }
391 392
	 }else if (atrType == MessageIntegrity)
392 393
	{
393 394
            msg->hasMessageIntegrity = true;
394 395
            if (stunParseAtrIntegrity( body, attrLen,&msg->messageIntegrity) == false)
395 396
            {
396
	      printf("problem parsing MessageIntegrity \n");
397
	      debug("problem parsing MessageIntegrity \n");
397 398
               return false;
398 399
            }
399 400
            else
......
411 412
            msg->hasErrorCode = true;
412 413
            if (stunParseAtrError(body, attrLen, &msg->errorCode) == false)
413 414
            {
414
	      printf("problem parsing ErrorCode \n");
415
	      debug("problem parsing ErrorCode \n");
415 416
               return false;
416 417
            }
417 418
            else
418 419
            {
419
	      if (verbose) printf("ErrorCode = %d %d %s \n",(int)(msg->errorCode.errorClass)                                 ,(int)(msg->errorCode.number) 
420
	      if (verbose) info("ErrorCode = %d %d %s \n",(int)(msg->errorCode.errorClass)                                 ,(int)(msg->errorCode.number)
420 421
				 ,msg->errorCode.reason);
421 422
            }
422 423
					
......
425 426
            msg->hasUnknownAttributes = true;
426 427
            if (stunParseAtrUnknown(body, attrLen,&msg->unknownAttributes) == false)
427 428
            {
428
	      printf("problem parsing UnknownAttribute \n");
429
	      debug("problem parsing UnknownAttribute \n");
429 430
               return false;
430 431
            }
431 432
	} else if (atrType == ReflectedFrom)
......
433 434
            msg->hasReflectedFrom = true;
434 435
            if ( stunParseAtrAddress(  body,  attrLen,  &msg->reflectedFrom, verbose ) == false )
435 436
            {
436
	      printf("problem parsing ReflectedFrom \n");
437
	      debug("problem parsing ReflectedFrom \n");
437 438
               return false;
438 439
            }
439 440
	} else if (atrType == XorMappedAddress)
......
441 442
            msg->hasXorMappedAddress = true;
442 443
            if ( stunParseAtrAddress(  body,  attrLen,  &msg->xorMappedAddress, verbose ) == false )
443 444
            {
444
	      printf("problem parsing XorMappedAddress \n");
445
	      debug("problem parsing XorMappedAddress \n");
445 446
               return false;
446 447
            }
447 448
            else
448 449
            {
449
	      if (verbose) printf("XorMappedAddress ------------------- \n");
450
	      if (verbose) info("XorMappedAddress ------------------- \n");
450 451
            }
451 452
	} else if (atrType == XorOnly)
452 453
	{
453 454
            msg->xorOnly = true;
454 455
            if (verbose) 
455 456
            {
456
	      printf("xorOnly = true \n");
457
	      debug("xorOnly = true \n");
457 458
            }
458 459
	} else if (atrType == ServerName) 
459 460
	{			
460 461
            msg->hasServerName = true;
461 462
            if (stunParseAtrString( body, attrLen, &msg->serverName) == false)
462 463
            {
463
	      printf("problem parsing ServerName \n");
464
	      debug("problem parsing ServerName \n");
464 465
               return false;
465 466
            }
466 467
            else
467 468
            {
468
	      if (verbose) printf("ServerName = %s \n",(char *)&msg->serverName.value);
469
	      if (verbose) info("ServerName = %s \n",(char *)&msg->serverName.value);
469 470
            }
470 471
	} else if (atrType == SecondaryAddress)
471 472
	{
472 473
            msg->hasSecondaryAddress = true;
473 474
            if ( stunParseAtrAddress(  body,  attrLen, &msg->secondaryAddress, verbose ) == false )
474 475
            {
475
	      printf("problem parsing secondaryAddress \n");
476
	      debug("problem parsing secondaryAddress \n");
476 477
               return false;
477 478
            }
478 479
            else
479 480
            {
480
	      if (verbose) printf("SecondaryAddress ---------------- \n");
481
	      if (verbose) info("SecondaryAddress ---------------- \n");
481 482
            }
482 483
	}  else 
483 484
	{				
484 485
         
485
	   if (verbose) printf("Unknown attribute: %i \n",atrType);
486
	   if (verbose) info("Unknown attribute: %i \n",atrType);
486 487
            if ( atrType <= 0x7FFF ) 
487 488
            {
488 489
               return false;
......
555 556

  
556 557
   if (msg.hasMappedAddress)
557 558
   {
558
     //if (verbose) printf("Encoding MappedAddress: %s \n",msg.mappedAddress.ipv4);
559
     //if (verbose) info("Encoding MappedAddress: %s \n",msg.mappedAddress.ipv4);
559 560
      ptr = encodeAtrAddress4 (ptr, MappedAddress, msg.mappedAddress);
560 561
   }
561 562
   if (msg.hasResponseAddress)
562 563
   {
563
     //if (verbose) printf("Encoding ResponseAddress: %s \n",msg.responseAddress.ipv4);
564
     //if (verbose) info("Encoding ResponseAddress: %s \n",msg.responseAddress.ipv4);
564 565
      ptr = encodeAtrAddress4(ptr, ResponseAddress, msg.responseAddress);
565 566
   }
566 567
   if (msg.hasChangeRequest)
567 568
   {
568
     //if (verbose) printf("Encoding ChangeRequest: %s \n",msg.changeRequest.value);
569
     //if (verbose) info("Encoding ChangeRequest: %s \n",msg.changeRequest.value);
569 570
      ptr = encodeAtrChangeRequest(ptr, msg.changeRequest);
570 571
   }
571 572
   if (msg.hasSourceAddress)
572 573
   {
573
     //if (verbose) printf("Encoding SourceAddress: %s \n ",msg.sourceAddress.ipv4);
574
     //if (verbose) info("Encoding SourceAddress: %s \n ",msg.sourceAddress.ipv4);
574 575
      ptr = encodeAtrAddress4(ptr, SourceAddress, msg.sourceAddress);
575 576
   }
576 577
   if (msg.hasChangedAddress)
577 578
   {
578
     //if (verbose) printf("Encoding ChangedAddress: %s \n ",msg.changedAddress.ipv4);
579
     //if (verbose) info("Encoding ChangedAddress: %s \n ",msg.changedAddress.ipv4);
579 580
      ptr = encodeAtrAddress4(ptr, ChangedAddress, msg.changedAddress);
580 581
   }
581 582
   if (msg.hasUsername)
582 583
   {
583
     if (verbose) printf("Encoding Username: %s \n", msg.username.value);
584
     if (verbose) info("Encoding Username: %s \n", msg.username.value);
584 585
      ptr = encodeAtrString(ptr, Username, msg.username);
585 586
   }
586 587
   if (msg.hasPassword)
587 588
   {
588
     if (verbose) printf("Encoding Password: %s \n ",msg.password.value);
589
     if (verbose) info("Encoding Password: %s \n ",msg.password.value);
589 590
      ptr = encodeAtrString(ptr, Password, msg.password);
590 591
   }
591 592
   if (msg.hasErrorCode)
592 593
   {
593
     if (verbose) printf("Encoding ErrorCode: class= %d number= %d reason= %s \n" 
594
     if (verbose) info("Encoding ErrorCode: class= %d number= %d reason= %s \n"
594 595
			 ,(int)msg.errorCode.errorClass  
595 596
			 ,(int)msg.errorCode.number 
596 597
		         ,msg.errorCode.reason 
......
600 601
   }
601 602
   if (msg.hasUnknownAttributes)
602 603
   {
603
     if (verbose) printf("Encoding UnknownAttribute: ??? \n");
604
     if (verbose) info("Encoding UnknownAttribute: ??? \n");
604 605
      ptr = encodeAtrUnknown(ptr, msg.unknownAttributes);
605 606
   }
606 607
   if (msg.hasReflectedFrom)
607 608
   {
608
     //if (verbose) printf("Encoding ReflectedFrom: %s \n ",msg.reflectedFrom.ipv4);
609
     //if (verbose) info("Encoding ReflectedFrom: %s \n ",msg.reflectedFrom.ipv4);
609 610
      ptr = encodeAtrAddress4(ptr, ReflectedFrom, msg.reflectedFrom);
610 611
   }
611 612
   if (msg.hasXorMappedAddress)
612 613
   {
613
     //if (verbose) printf("Encoding XorMappedAddress: %s \n ",msg.xorMappedAddress.ipv4 );
614
     //if (verbose) info("Encoding XorMappedAddress: %s \n ",msg.xorMappedAddress.ipv4 );
614 615
      ptr = encodeAtrAddress4 (ptr, XorMappedAddress, msg.xorMappedAddress);
615 616
   }
616 617
   if (msg.xorOnly)
617 618
   {
618
     if (verbose) printf("Encoding xorOnly: \n");
619
     if (verbose) info("Encoding xorOnly: \n");
619 620
      ptr = encodeXorOnly( ptr );
620 621
   }
621 622
   if (msg.hasServerName)
622 623
   {
623
     if (verbose) printf("Encoding ServerName: %s \n ",msg.serverName.value);
624
     if (verbose) info("Encoding ServerName: %s \n ",msg.serverName.value);
624 625
      ptr = encodeAtrString(ptr, ServerName, msg.serverName);
625 626
   }
626 627
   if (msg.hasSecondaryAddress)
627 628
   {
628
     //if (verbose) printf("Encoding SecondaryAddress: %s \n", msg.secondaryAddress.ipv4);
629
     //if (verbose) info("Encoding SecondaryAddress: %s \n", msg.secondaryAddress.ipv4);
629 630
      ptr = encodeAtrAddress4 (ptr, SecondaryAddress, msg.secondaryAddress);
630 631
   }
631 632

  
632 633
   if (password.sizeValue > 0)
633 634
   {
634
     if (verbose) printf("HMAC with password: %s \n ",password.value);
635
     if (verbose) info("HMAC with password: %s \n ",password.value);
635 636
		
636 637
      StunAtrIntegrity integrity;
637 638
      //computeHmac(integrity.hash, buf, (int)(ptr-buf) , password.value, password.sizeValue);
......
767 768
   if ( h == NULL )
768 769
   {
769 770
     //int err = getErrno();
770
      printf("error was %d \n",errno);
771
      error("error was %d \n",errno);
771 772
      ip = ntohl( 0x7F000001L );
772 773
      return false;
773 774
   }
......
790 791
{
791 792
   if ( hdrLen != 4 )
792 793
   {
793
      printf("hdr length = %d excepcting %d \n ",hdrLen,sizeof(result));
794
      error("hdr length = %d excepcting %d \n ",hdrLen,sizeof(result));
794 795

  
795
      printf("Incorrect size for ChangeRequest \n ");
796
      error("Incorrect size for ChangeRequest \n ");
796 797

  
797 798
      return false;
798 799
   }
......
835 836
{
836 837
   if ( hdrLen >= STUN_MAX_STRING )
837 838
   {
838
     printf( "String is too large \n");
839
     debug( "String is too large \n");
839 840
      return false;
840 841
   }
841 842
   else
842 843
   {
843 844
      if (hdrLen % 4 != 0)
844 845
      {
845
	printf("Bad length string %d \n ",hdrLen);
846
	debug("Bad length string %d \n ",hdrLen);
846 847
         return false;
847 848
      }
848 849
		
......
859 860
{
860 861
   if ( hdrLen != 20)
861 862
   {
862
     printf("MessageIntegrity must be 20 bytes \n");
863
     debug("MessageIntegrity must be 20 bytes \n");
863 864
      return false;
864 865
   }
865 866
   else
......
885 886
{
886 887
   if ( hdrLen >= sizeof(StunAtrError) )
887 888
   {
888
      printf("head on Error too large \n  ");
889
      debug("head on Error too large \n  ");
889 890
      return false;
890 891
   }
891 892
   else
util/stun.h
55 55
#include <stdbool.h>
56 56

  
57 57
#define LOG_MODULE "[ml] "
58
#include "grapes_log.h"
58
#include "ml_log.h"
59 59

  
60 60
/**
61 61
 * The maximum size of a STUN string 
util/udpSocket.c
68 68

  
69 69
#include "udpSocket.h"
70 70
#define LOG_MODULE "[ml] "
71
#include "grapes_log.h"
71
#include "ml_log.h"
72 72

  
73 73
/* debug varible: set to 1 if you want debug output  */
74 74
int verbose = 0;
......
93 93
  //This is debug code that checks if the socket was created 
94 94
  if (udpSocket == -1)
95 95
    {
96
      fatal("Could not create an UDP socket!");
96
      fatal("Could not create an UDP socket!\n");
97 97
      exit(1);
98 98
    }
99 99

  
......
121 121

  
122 122
  /* This is debug code */
123 123
  if (returnStatus) {
124
    fatal("Could not bind socketID to address!");
124
    fatal("Could not bind socketID to address!\n");
125 125
  }
126 126
#ifdef IP_MTU_DISCOVER
127 127

  
......
133 133
   * This sets the DON'T FRAGMENT bit on the IP HEADER
134 134
   */
135 135
  if(setsockopt(udpSocket,IPPROTO_IP,IP_MTU_DISCOVER,&pmtuopt ,size) == -1){
136
    error("setsockopt: set IP_DONTFRAG did not work. ERRNO %d",errno);
136
    error("setsockopt: set IP_DONTFRAG did not work. ERRNO %d\n",errno);
137 137
    
138 138
  }
139 139
  
140 140
  /* This option writes the IP_TTL field into ancillary data */
141 141
  if(setsockopt(udpSocket,IPPROTO_IP, IP_RECVTTL, &yes,size) < 0)
142 142
    {
143
      error("setsockopt: cannot set RECV_TTL. ERRNO %d",errno);
143
      error("setsockopt: cannot set RECV_TTL. ERRNO %d\n",errno);
144 144
    }
145 145

  
146 146
  /* This option writes received internal and external(icmp) error messages into ancillary data */
147 147
  
148 148
  if(setsockopt(udpSocket,IPPROTO_IP, IP_RECVERR, &yes,size) < 0) { 
149
	error("setsockopt: cannot set RECV_ERROR. ERRNO %d",errno);
149
	error("setsockopt: cannot set RECV_ERROR. ERRNO %d\n",errno);
150 150
    }
151 151
  
152 152
#endif
......
161 161
	unsigned int size = sizeof(value);
162 162

  
163 163
	if(getsockopt(udpSocket,SOL_IP,IP_TTL,&value,&size) == -1){
164
		error("get TTL did not work");
164
		error("get TTL did not work\n");
165 165
		return 0;
166 166
	}
167 167

  
168 168
	*ttl = value;
169
	if(verbose == 1) debug("TTL is %i",value);
169
	if(verbose == 1) debug("TTL is %i\n",value);
170 170

  
171 171
	return 1;
172 172
}
......
190 190
	ret = sendmsg(udpSocket,&msgh,0);
191 191
	if (ret  < 0){
192 192
		error = errno;
193
		debug("ML: sendmsg failed errno %d: %s", error, strerror(error));
193
		debug("ML: sendmsg failed errno %d: %s\n", error, strerror(error));
194 194
		switch(error) {
195 195
			case EMSGSIZE:
196 196
				return MSGLEN;
......
212 212
int handleSocketError(const int udpSocket,const int iofunc,char *buf,int *bufsize,struct sockaddr_in *addr,icmp_error_cb icmpcb_value,int *ttl){
213 213

  
214 214

  
215
	if(verbose == 1) debug("handle Socket error is called");
215
	if(verbose == 1) debug("handle Socket error is called\n");
216 216

  
217 217
	/* variables  */
218 218
	struct msghdr msgh;
......
256 256
			if (errptr->ee_origin == SO_EE_ORIGIN_LOCAL){
257 257
				if (errptr->ee_errno != EMSGSIZE) {
258 258
					if(verbose == 1)
259
						printf("local error: %s \n", strerror(errptr->ee_errno));
259
						error("local error: %s \n", strerror(errptr->ee_errno));
260 260
				}
261 261
			}
262 262
			/* check if the error originated from an icmp message  */
263 263
			if (errptr->ee_origin == SO_EE_ORIGIN_ICMP){
264 264
				if(verbose == 1)
265
					debug("icmp error message received");
265
					debug("icmp error message received\n");
266 266

  
267 267
				int type = errptr->ee_type;
268 268
				int code = errptr->ee_code;
269 269
				icmp = 1;
270
				warn("icmp error message is type: %d code %d",
270
				warn("icmp error message is type: %d code %d\n",
271 271
					errptr->ee_type,errptr->ee_code);
272 272

  
273 273
				/* raise the pmtu callback when an pmtu error occurred 
......
276 276

  
277 277
				if (type == 3 && code == 4){
278 278
					if(verbose == 1)
279
						debug("pmtu error message received");
279
						debug("pmtu error message received\n");
280 280

  
281 281
					int mtusize = *bufsize;
282 282
					(icmpcb_value)(buf,mtusize);
......
290 290
	* has to be carried out
291 291
	*/
292 292

  
293
	//printf("socketErrorHandle: before iofunc loop \n");
293
	//error("socketErrorHandle: before iofunc loop \n");
294 294
	int transbuf;
295 295
	memcpy(&transbuf,bufsize,4);
296 296
	
......
300 300
	if(iofunc == 1) {
301 301
		sendPacket(udpSocket,buf,transbuf,addr,icmpcb_value);
302 302
		if(verbose == 1)
303
			printf("handle socket error: packetsize %i \n ",*bufsize );
303
			error("handle socket error: packetsize %i \n ",*bufsize );
304 304
	} else {
305 305
		if(iofunc == 2 && icmp == 1){
306 306
			if(verbose == 1)
307
				printf("handleSOcketError: recvPacket called \n ");
307
				error("handleSOcketError: recvPacket called \n ");
308 308
			recvPacket(udpSocket,buf,bufsize,addr,icmpcb_value,ttl);
309 309
		} else {
310 310
		/* this is the case the socket has just an error message not related to anything of the messaging layer */
311 311
			if(verbose == 1)
312
				printf("handleSocketError: unrelated error \n");
312
				error("handleSocketError: unrelated error \n");
313 313
			*ttl = -1;
314 314
		}
315 315
	}
......
359 359
	/* receive the message */
360 360
	if (returnStatus < 0) {
361 361
		if(verbose == 1) {
362
			printf("udpSocket:recvPacket: Read the error queue \n ");
363
			printf("recvmsg failed. errno %d \n",errno);
362
			error("udpSocket:recvPacket: Read the error queue \n ");
363
			error("recvmsg failed. errno %d \n",errno);
364 364
		}
365 365
		// TODO debug code: delete afterwards start
366 366
		if(errno == 11) {
......
372 372
	} else {
373 373
		/* debug code  */
374 374
		if(verbose == 1)
375
			printf("udpSocket_recvPacket: Message received.\n");
375
			debug("udpSocket_recvPacket: Message received.\n");
376 376

  
377 377
		for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(&msgh,cmsg)) {
378 378
			if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_TTL) {
......
380 380
				received_ttl = *ttlptr;
381 381
				memcpy(ttl,ttlptr,4);
382 382
				if(verbose == 1)
383
					printf("received ttl true: %i  \n ",received_ttl);
383
					debug("received ttl true: %i  \n ",received_ttl);
384 384
				break;
385 385
			}
386 386
		}

Also available in: Unified diff