Revision 11fce711 util/udpSocket.c

View differences:

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