1 /*
2  * Copyright (C) 2002-2009, Edmundo Albuquerque de Souza e Silva.
3  *
4  * This file may be distributed under the terms of the Q Public License
5  * as defined by Trolltech AS of Norway and appearing in the file
6  * LICENSE.QPL included in the packaging of this file.
7  *
8  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
9  * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
10  * PURPOSE.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
11  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
12  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
13  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
14  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  *
16  */
17 
18 /***************************************************************************
19                              rmmsgpckt.c
20                              -------------------
21     begin                : May 2001
22     Authors              : Jorge Allyson Azevedo
23                            Milena Scanferla
24                            Daniel Sadoc
25     email                : {allyson,milena,sadoc}@land.ufrj.br
26  ***************************************************************************/
27 
28 #ifndef RMMSGPCKT_C
29 
30 #define RMMSGPCKT_C
31 
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 
36 #include <ctype.h>
37 
38 #include "rmstruct.h"
39 #include "rmmsgpckt.h"
40 
41 #define MIN(a,b)  ((a<b)?a:b)
42 
43 #define get(dest, org, bytes) { bzero(dest,bytes); memcpy(dest,org, bytes); org+=bytes; }
44 
45 #define getPCKInfo(dest, org,bytes) { bzero(dest,bytes); memcpy(dest,org, bytes); dest+=bytes; packet_size+=bytes; }
46 
47 #define get_member_id(member_id, message)			\
48 {													\
49 	fprintf(stderr,"\tMember id:\n");				\
50 	get(&member_id,message,sizeof(MEMBER_ID));		\
51 	fprintf(stderr,"\t\tip: "); 					\
52 	for (k=0; k<IP_STRING_SIZE; k++)			\
53 	{												\
54 	if ((int)(member_id.ip[k])==0) break;			\
55 	fprintf(stderr,"%c",member_id.ip[k]);			\
56 	}												\
57 	fprintf(stderr,"\n");							\
58 	fprintf(stderr,"\t\tpid: %d\n",member_id.pid);	\
59 }													\
60 
61 extern int rmcast_listening_tcp_port;
62 
63 char *MESSAGE_TYPE_NAME[NUMBER_OF_MESSAGE_TYPES] = {
64                                 "UN", /* "UNKNOWN PACKET TYPE" */
65                                 "DT", /* "DATA PACKET        ", */
66                                 "RT", /* "RETRANSMISSION PACKET ", */
67                                 "NK", /* "NAK PACKET         ", */
68                                 "RF", /*"REFRESH PACKET     " */
69                                 "JR", /*"JOIN REQUEST PACKET     " */
70                                 "JA", /*"JOIN ACCEPT PACKET     " */
71                                 "LG" /* "LEAVE GROUP PACKET" */
72                                 };
73 
74 
75 #define EXCHANGE_BYTE_ORDER(in_var)                                             \
76     {                                                                           \
77         int i = 0, j=sizeof(in_var)-1;                                          \
78         unsigned char * var = (unsigned char*)&in_var;                          \
79         char temp = 0;                                                          \
80         for (i=0;i<j;i++, j--)                                                  \
81         {                                                                       \
82             temp       = var[ i ];                                              \
83             var[ i ]   = var[ j ];                                              \
84             var[ j ] = temp;                                                    \
85         }                                                                       \
86     }
87 
88 
89 
90 /*******************************************************************************************************
91  *
92  * void msgPcktShowMessage(BYTE *message)
93  *
94  * Shows the message on the screen.
95  *
96  ******************************************************************************************************/
97 
98 // #define DEBUG_SHOW
99 // #define DEBUG_MSG_CONTENTS
100 
msgPcktShowMessage(BYTE * message)101 void msgPcktShowMessage(BYTE *message)
102 {
103 
104 #ifdef DEBUG_SHOW
105 
106 	char type;
107     BYTE flags;
108 
109 	MEMBER_ID member_id;  char string[1001];
110 
111 	int sn, pckt_size, data_size, k, port;
112 
113 #ifdef DEBUG_MSG_CONTENTS
114     int i;
115 #endif
116 
117 	get(&type,message,sizeof(char));
118 
119 	fprintf(stderr,"DEBUG_SHOW msgPcktShowMessage BEGIN -------------------\n");
120     fprintf(stderr,"\ntype: %d\n",type);
121 
122     get(&flags,message,sizeof(BYTE));
123     fprintf(stderr,"\nflags: %d\n",flags);
124     fprintf(stderr,"member info: \n");
125 
126 	get_member_id(member_id, message);
127 
128 #ifdef SOLARIS
129     EXCHANGE_BYTE_ORDER(member_id.pid);
130 
131     fprintf(stderr,"SOLARIS byte order pid #: %d\n",member_id.pid);
132 #endif
133 
134 
135 	get(&pckt_size,message,sizeof(int));
136 
137 
138 #ifdef SOLARIS
139     EXCHANGE_BYTE_ORDER(pckt_size);
140 #endif
141 
142 
143     fprintf(stderr,"packet size: %d\n",pckt_size);
144 
145 
146 	switch (type)
147 	{
148 
149 	case DATA_PACKET_TYPE:
150 
151 		fprintf(stderr,"data packet: \n");
152 
153 		get(&sn,message,sizeof(int));
154 
155 #ifdef SOLARIS
156         EXCHANGE_BYTE_ORDER(sn);
157 #endif
158 
159         fprintf(stderr,"\tsn: %d\n",sn);
160 
161 		get(&data_size,message,sizeof(int));
162 
163 #ifdef SOLARIS
164         EXCHANGE_BYTE_ORDER(data_size);
165 #endif
166 
167         fprintf(stderr,"\tdata size: %d\n",data_size);
168 
169 		memcpy(string,message, MIN((sizeof(BYTE)*data_size),1000)); string[MIN(data_size,1000)]='\0';
170 
171 		fprintf(stderr,"\tdata: ");
172 
173 #ifdef DEBUG_MSG_CONTENTS
174 		for(i=0; i<data_size; i++)
175 		{
176      		fprintf(stderr,"%c",string[i]);
177 		}
178 #endif
179 		break;
180 
181 	case RETRANSM_PACKET_TYPE:
182 
183 		get_member_id(member_id, message);
184 
185 #ifdef SOLARIS
186         EXCHANGE_BYTE_ORDER(member_id.pid);
187 
188         fprintf(stderr,"SOLARIS byte order pid #: %d\n",member_id.pid);
189 #endif
190 
191         get(&sn,message,sizeof(int));
192 		get(&data_size,message,sizeof(int));
193 		memcpy(string,message, sizeof(BYTE)*data_size);
194         string[data_size]='\0';
195 
196         fprintf(stderr,"retransmition packet: \n");
197 		fprintf(stderr,"\tdata packet: \n");
198 
199 #ifdef SOLARIS
200         EXCHANGE_BYTE_ORDER(sn);
201         EXCHANGE_BYTE_ORDER(data_size);
202 #endif
203 
204         fprintf(stderr,"\t\tsn: %d\n",sn);
205         fprintf(stderr,"\t\tdata size: %d\n",data_size);
206  		fprintf(stderr,"\tdata: %s\n",string);
207 
208 
209 #ifdef DEBUG_MSG_CONTENTS
210 		for(i=0; i<data_size; i++)
211 		{
212      		fprintf(stderr,"%c",string[i]);
213 		}
214 #endif
215 
216 		fprintf(stderr,"\n\n");
217 
218 
219 	break;
220 
221 	case NAK_PACKET_TYPE:
222 
223 		get_member_id(member_id, message);
224 
225 #ifdef SOLARIS
226         EXCHANGE_BYTE_ORDER(member_id.pid);
227 
228         fprintf(stderr,"SOLARIS byte order pid #: %d\n",member_id.pid);
229 #endif
230 
231 
232 		get(&sn,message,sizeof(int));
233 
234         fprintf(stderr,"nak packet: \n");
235 
236         fprintf(stderr,"\tsn: %d\n",sn);
237 
238 #ifdef SOLARIS
239         EXCHANGE_BYTE_ORDER(sn);
240 #endif
241 
242 #ifdef  SINGLE_NACK
243 
244         {
245             int base_sn, window_size, hmask, lmask;
246 
247     		get(&(base_sn), message, sizeof(int));
248 	    	get(&(window_size),message, sizeof(int));
249 		    get(&(hmask), message, sizeof(int));
250     		get(&(lmask), message, sizeof(int));
251 
252 #ifdef SOLARIS
253             EXCHANGE_BYTE_ORDER(base_sn);
254             EXCHANGE_BYTE_ORDER(window_size);
255             EXCHANGE_BYTE_ORDER(hmask);
256             EXCHANGE_BYTE_ORDER(lmask);
257 #endif
258 
259             fprintf(stderr,"\tbase sn: %d window size: %d \n\thigher part of the mask: %d lower part of the mask: %d\n",
260                 base_sn, window_size, hmask, lmask);
261         }
262 
263 #endif        // single nack
264 
265 
266     break;
267 
268 
269 	case LEAVE_GROUP_PACKET_TYPE:
270 
271 		fprintf(stderr,"leave group packet: \n");
272 
273 		break;
274 
275     case REFRESH_PACKET_TYPE:
276 
277 		get(&sn,message,sizeof(int));
278 
279 #ifdef SOLARIS
280         EXCHANGE_BYTE_ORDER(sn);
281 #endif
282 
283 
284         fprintf(stderr, "\tsequence number of last message sent: %d\n", sn);
285 
286 		break;
287 
288 	case JOIN_ACCEPT_PACKET_TYPE:
289 
290   		get(&port,message,sizeof(int));
291 
292 #ifdef SOLARIS
293         EXCHANGE_BYTE_ORDER(port);
294 #endif
295 
296 
297   		fprintf(stderr,"join accept packet (port: %d). \n",port);
298 
299         break;
300 
301 	case JOIN_REQUEST_PACKET_TYPE:
302 
303         break;
304 
305     default:
306 
307         fprintf(stderr,"Unknown packet type: %d\n",type);
308 
309 
310 	}
311 
312 	fprintf(stderr,"DEBUG_SHOW msgPcktShowMessage END -------------------\n");
313 #endif
314 
315 	return;
316 }
317 
318 
319 /*******************************************************************************************************
320  *
321  * void msgPcktExchangeByteOrder(PACKET_INFO *pckt_info)
322  *
323  * Exchange byte order in message (Linux versus Solaris).
324  *
325  * Arguments:	pckt_info,	a pointer to the strucutre holding the message.
326  *
327  ******************************************************************************************************/
328 
329 #ifdef SOLARIS
330 
msgPcktExchangeByteOrder(PACKET_INFO * pckt_info)331 void msgPcktExchangeByteOrder(PACKET_INFO *pckt_info)
332 {
333     EXCHANGE_BYTE_ORDER(pckt_info->sender_id.pid);
334     EXCHANGE_BYTE_ORDER(pckt_info->packet_size);
335     switch (pckt_info->type)
336     {
337     case DATA_PACKET_TYPE:
338 
339         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.data_packet.sn);
340         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.data_packet.data_size);
341         break;
342 
343 
344 	case RETRANSM_PACKET_TYPE:
345 
346 
347         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.retransm_packet.original_sender_id.pid);
348         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.retransm_packet.data_packet.sn);
349         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.retransm_packet.data_packet.data_size);
350         break;
351 
352 
353 	case NAK_PACKET_TYPE:
354 
355         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.nak_packet.requested_member_id.pid);
356         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.nak_packet.sn);
357 
358 #ifdef  SINGLE_NACK
359 
360         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.nak_packet.base_sn);
361         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.nak_packet.window_size);
362         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.nak_packet.hmask);
363         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.nak_packet.lmask);
364 
365 #endif
366 
367         break;
368 
369     case REFRESH_PACKET_TYPE:
370 
371         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.refresh_packet.sn_of_last_msg_sent);
372         break;
373 
374 	case LEAVE_GROUP_PACKET_TYPE:
375         break;
376 
377 	case JOIN_ACCEPT_PACKET_TYPE:
378         EXCHANGE_BYTE_ORDER(pckt_info->packet_data.join_accept_packet.port);
379         break;
380 
381 	case JOIN_REQUEST_PACKET_TYPE:
382         break;
383     }
384 }
385 
386 #endif
387 
388 /*******************************************************************************************************
389  *
390  * void msgPcktUnmountMessage(PACKET_INFO *pckt_info, BYTE *message)
391  *
392  * Unmount the message come from the network, filling PACKET_INFO structure with the apropriate values.
393  *
394  * Arguments:	message,	a pointer to the message to be unmounted (source of information);
395  *				pckt_info,	a pointer to the target strucutre, which will hold the message info.
396  *							(this structure must have been previously allocated).
397  *
398  ******************************************************************************************************/
399 
400 
msgPcktUnmountMessage(PACKET_INFO * pckt_info,BYTE * message)401 void msgPcktUnmountMessage(PACKET_INFO *pckt_info, BYTE *message)
402 {
403 #ifdef DEBUG_PCKT
404     fprintf(stderr,"DEBUG_PCKT msgPcktUnmountMessage: [char: %d flag: %d MEMBER_ID: %d int: %d]\n",
405         sizeof(char),
406         sizeof(BYTE),     /* Flags related */
407         sizeof(MEMBER_ID),
408         sizeof(int));
409 #endif
410 
411 	get(&(pckt_info->type),message,sizeof(char));
412 
413     /* Flags related */
414     get(&(pckt_info->flags),message,sizeof(BYTE));
415 
416     get(&(pckt_info->sender_id),message,sizeof(MEMBER_ID));
417 	get(&(pckt_info->packet_size),message,sizeof(int));
418 
419 	switch (pckt_info->type)
420 	{
421 	case DATA_PACKET_TYPE:
422 
423 		get(&(pckt_info->packet_data.data_packet.sn),message,sizeof(int));
424 
425     	get(&(pckt_info->packet_data.data_packet.data_size),message,sizeof(int));
426 		(pckt_info->packet_data.data_packet.data)=(BYTE*)message;
427 		break;
428 
429 	case RETRANSM_PACKET_TYPE:
430 
431 		get(&(pckt_info->packet_data.retransm_packet.original_sender_id),message,sizeof(MEMBER_ID));
432 		get(&(pckt_info->packet_data.retransm_packet.data_packet.sn),message,sizeof(int));
433 		get(&(pckt_info->packet_data.retransm_packet.data_packet.data_size),message,sizeof(int));
434 		(pckt_info->packet_data.retransm_packet.data_packet.data) = (BYTE*)message;
435 		break;
436 
437 	case NAK_PACKET_TYPE:
438 
439 		get(&(pckt_info->packet_data.nak_packet.requested_member_id),message,sizeof(MEMBER_ID));
440         get(&(pckt_info->packet_data.nak_packet.sn),message,sizeof(int));
441 
442 #ifdef  SINGLE_NACK
443 
444 		get(&(pckt_info->packet_data.nak_packet.base_sn), message, sizeof(int));
445 		get(&(pckt_info->packet_data.nak_packet.window_size),message, sizeof(int));
446 		get(&(pckt_info->packet_data.nak_packet.hmask), message, sizeof(int));
447 		get(&(pckt_info->packet_data.nak_packet.lmask), message, sizeof(int));
448 
449 #endif
450 
451 		break;
452 
453 #ifdef REFRESH
454 
455     case REFRESH_PACKET_TYPE:
456 
457     	get(&(pckt_info->packet_data.refresh_packet.sn_of_last_msg_sent), message, sizeof(int));
458         break;
459 #endif
460 
461 	case LEAVE_GROUP_PACKET_TYPE:
462 
463 		/* do nothing. We already have the sender id*/
464 
465 		break;
466 
467 	case JOIN_ACCEPT_PACKET_TYPE:
468 
469        	get(&(pckt_info->packet_data.join_accept_packet.port), message, sizeof(int));
470 		break;
471 
472 	case JOIN_REQUEST_PACKET_TYPE:
473 
474         break;
475 
476     default:
477 
478         fprintf(stderr,"Unknown packet type: %d\n",pckt_info->type);
479 
480 
481         break;
482 
483 	}
484 #ifdef SOLARIS
485 
486     fprintf(stderr,"SOLARIS msgPcktUnmountMessage: That's SOLARIS so, excanching by order:\n[sender pid] ");
487     fprintf(stderr,"%d %x\n",pckt_info->sender_id.pid,pckt_info->sender_id.pid);
488 
489     msgPcktExchangeByteOrder(pckt_info);
490 
491     fprintf(stderr,"SOLARIS msgPcktUnmountMessage: [sender pid]: %d %x\n",pckt_info->sender_id.pid,pckt_info->sender_id.pid);
492 
493 #endif
494 
495 #ifdef DEBUG_PCKT
496     fprintf(stderr,"DEBUG_PCKT msgPcktUnmountMessage: returning\n");
497 #endif
498 
499 	return;
500 
501 }
502 
503 /*******************************************************************************************************
504  *
505  * void msgPcktMountMessage(PACKET_INFO *pckt_info, BYTE **message, int *msgsize)
506  *
507  * Mount the message to be sent over the network, getting data from the PACKET_INFO structure.
508  *
509  * Arguments:	pckt_info,	a pointer to the source structure, from which data will be retrieved;
510  *				message,	a pointer to the message to be mounted -
511  *							(the space needed to store the message will be allocated as necessary);
512  *				msgsize,	a pointer to an integer which will return the effective size of the message.
513  *
514  ******************************************************************************************************/
515 
msgPcktMountMessage(PACKET_INFO * pckt_info,BYTE ** message,int * msgsize)516 void msgPcktMountMessage(PACKET_INFO *pckt_info, BYTE **message, int *msgsize)
517 {
518 	BYTE *aux_message_pt;
519 	BYTE *common_header;
520 
521 	int *sn_pointer;
522 	int common_header_size;
523 	int msg_specific = 0, data_size = 0;
524 	int packet_size = 0;
525 
526 #ifdef DEBUG_PCKT
527 	fprintf(stderr,"DEBUG_PCKT msgPcktMountMessage: mounting packet\n");
528 #endif
529 
530 #ifdef SOLARIS
531     fprintf(stderr,"That's SOLARIS so, excanching by order:\n[sender pid] ");
532     fprintf(stderr,"%d %x\n",pckt_info->sender_id.pid,pckt_info->sender_id.pid);
533 
534     msgPcktExchangeByteOrder(pckt_info);
535 
536 #endif
537 
538 #ifdef DEBUG_PCKT
539     fprintf(stderr,"DEBUG_PCKT msgPcktMountMessage: [sender pid] ");
540     fprintf(stderr,"%d %x\n",pckt_info->sender_id.pid,pckt_info->sender_id.pid);
541 #endif
542 
543 
544 	/* info about type of the message, sender_id and packet_size */
545     common_header_size= sizeof(char)+sizeof(BYTE)+sizeof(MEMBER_ID)+sizeof(int);     /* sizeof(BYTE) is Flags related */
546 	common_header = (BYTE*)malloc(common_header_size);
547 
548 	aux_message_pt = common_header;
549 
550 #ifdef DEBUG_PCKT
551 	fprintf(stderr,"DEBUG_PCKT msgPcktMountMessage:common_header allocated at: %p\n", common_header);
552 #endif
553 
554     /* Flags are not used by now, so we just set it to zero */
555     pckt_info->flags='0';
556 
557 	getPCKInfo(aux_message_pt, &(pckt_info->type), sizeof(char));
558 
559     /* Flags related */
560 	getPCKInfo(aux_message_pt, &(pckt_info->flags), sizeof(BYTE));
561 
562     getPCKInfo(aux_message_pt, &(pckt_info->sender_id), sizeof(MEMBER_ID));
563 	getPCKInfo(aux_message_pt, &(pckt_info->packet_size), sizeof(int));
564 
565 	packet_size = 0;
566 
567 	/* specific info plus data */
568 
569 	switch(pckt_info->type)
570 	{
571 
572 	    case DATA_PACKET_TYPE:
573 
574 		    msg_specific = sizeof(DATA_PACKET)-sizeof(BYTE*);
575 		    data_size = (pckt_info)->packet_data.data_packet.data_size;
576 
577 		    (*message) = (BYTE*)malloc(common_header_size+msg_specific+data_size);
578 		    aux_message_pt = *message;
579 		    getPCKInfo(aux_message_pt,common_header,common_header_size);
580 
581 		    sn_pointer = (int*)aux_message_pt;
582 
583 		    getPCKInfo(aux_message_pt,&(pckt_info->packet_data.data_packet.sn), sizeof(int));
584 
585 		    getPCKInfo(aux_message_pt,&(pckt_info->packet_data.data_packet.data_size), sizeof(int));
586 		    getPCKInfo(aux_message_pt, (pckt_info->packet_data.data_packet.data), data_size);
587 
588 
589 		    break;
590 
591 	    case RETRANSM_PACKET_TYPE:
592 
593 		    msg_specific = sizeof(RETRANSM_PACKET)-sizeof(BYTE*);
594 
595 
596 		    data_size = sizeof(BYTE)*(pckt_info)->packet_data.retransm_packet.data_packet.data_size;
597 
598 
599 		    (*message) = (BYTE*)malloc(common_header_size+msg_specific+data_size);
600 		    aux_message_pt = *message;
601 		    getPCKInfo(aux_message_pt,common_header,common_header_size);
602 
603 
604 		    getPCKInfo(aux_message_pt,(void*)(&(pckt_info->packet_data.retransm_packet)), msg_specific);
605 		    getPCKInfo(aux_message_pt,(pckt_info->packet_data.retransm_packet.data_packet.data), data_size);
606 
607 		    break;
608 
609 	    case NAK_PACKET_TYPE:
610 
611 		    (*message) = (BYTE*)malloc(common_header_size+sizeof(NAK_PACKET));
612 		    aux_message_pt = *message;
613 		    getPCKInfo(aux_message_pt,common_header,common_header_size);
614 		    getPCKInfo(aux_message_pt, &(pckt_info->packet_data.nak_packet.requested_member_id), sizeof(MEMBER_ID));
615 		    getPCKInfo(aux_message_pt, &(pckt_info->packet_data.nak_packet.sn), sizeof(int));
616 
617     #ifdef  SINGLE_NACK
618 
619 		    getPCKInfo(aux_message_pt, &(pckt_info->packet_data.nak_packet.base_sn), sizeof(int));
620 		    getPCKInfo(aux_message_pt, &(pckt_info->packet_data.nak_packet.window_size), sizeof(int));
621 		    getPCKInfo(aux_message_pt, &(pckt_info->packet_data.nak_packet.hmask), sizeof(int));
622 		    getPCKInfo(aux_message_pt, &(pckt_info->packet_data.nak_packet.lmask), sizeof(int));
623 
624     #endif
625 
626 		    break;
627 
628 
629     #ifdef REFRESH
630 
631         case REFRESH_PACKET_TYPE:
632 
633 		    (*message) = (BYTE*)malloc(common_header_size+sizeof(int));
634 		    aux_message_pt = *message;
635 		    getPCKInfo(aux_message_pt,common_header,common_header_size);
636 
637             getPCKInfo(aux_message_pt, &(pckt_info->packet_data.refresh_packet.sn_of_last_msg_sent), sizeof(int));
638 
639 		    break;
640 
641     #endif
642 
643 	    case LEAVE_GROUP_PACKET_TYPE:
644 
645 
646 
647    		    (*message) = (BYTE*)malloc(common_header_size);
648 		    aux_message_pt = *message;
649 		    getPCKInfo(aux_message_pt,common_header,common_header_size);
650 
651 
652 		    /* do nothing. The packet is already built */
653 
654 		    break;
655 
656 	    case JOIN_ACCEPT_PACKET_TYPE:
657 
658 		    (*message) = (BYTE*)malloc(common_header_size+sizeof(int));
659 		    aux_message_pt = *message;
660 		    getPCKInfo(aux_message_pt,common_header,common_header_size);
661 
662             getPCKInfo(aux_message_pt, &(pckt_info->packet_data.join_accept_packet.port), sizeof(int));
663 
664             break;
665 
666         case JOIN_REQUEST_PACKET_TYPE:
667             (*message) = (BYTE*)malloc(common_header_size);
668             aux_message_pt = *message;
669 
670 		    getPCKInfo(aux_message_pt,common_header,common_header_size);
671 
672             break;
673 
674         default:
675 
676             fprintf(stderr,"DEBUG_PCKT msgPcktMountMessage: Unknown packet type: %d\n",pckt_info->type);
677 	}
678 
679 
680 	packet_size++;
681 
682 	aux_message_pt =  *message + sizeof(char) + sizeof(BYTE) + sizeof(MEMBER_ID);
683 	memcpy(aux_message_pt, &packet_size,sizeof(int));
684 
685 	*msgsize = packet_size;
686 
687 
688 #ifdef DEBUG_PCKT
689     {
690         int cont;
691         fprintf(stderr,"DEBUG_PCKT msgPcktMountMessage: Mounted message: \n");
692         for (cont = 0; cont < packet_size; cont++)
693         {
694             fprintf(stderr,"%d ", ((signed char*)(*message))[cont]);
695         }
696 
697     }
698     fprintf(stderr,"\nhere\n");
699 
700     msgPcktShowMessage((BYTE*)*message) ;
701 #endif
702 
703 
704     free (common_header);
705 
706 }
707 #endif
708 
709 
710