]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/RTPSInfoREPLY.c
f117f034f22172fc8996730077e156d7775128c7
[orte.git] / orte / liborte / RTPSInfoREPLY.c
1 /*
2  *  $Id: RTPSInfoREPLY.c,v 0.0.0.1      2003/09/1
3  *
4  *  DEBUG:  section 43                  message INFO REPLY
5  *  AUTHOR: Petr Smolik                 petr.smolik@wo.cz
6  *
7  *  ORTE - OCERA Real-Time Ethernet     http://www.ocera.org/
8  *  --------------------------------------------------------------------
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  */ 
21
22 #include "orte.h"
23
24 /**********************************************************************************/
25 int32_t 
26 RTPSInfoREPLYCreate(u_int8_t *rtps_msg,u_int32_t max_msg_len,
27     IPAddress ipaddress,Port port) {
28
29   if (max_msg_len<12) return -1;
30   rtps_msg[0]=(u_int8_t)INFO_REPLY;
31   rtps_msg[1]=ORTE_MY_MBO;
32   *((ParameterLength*)(rtps_msg+2))=8;
33   *((ObjectId*)(rtps_msg+4))=ipaddress;
34   *((ObjectId*)(rtps_msg+8))=port;
35   return 12;
36
37
38 /**********************************************************************************/
39 void 
40 RTPSInfoREPLY(u_int8_t *rtps_msg,MessageInterpret *mi) {
41   IPAddress          ipa;
42   Port               port;
43   int8_t             e_bit;
44
45   //Parsing
46   e_bit=rtps_msg[1] & 0x01;
47   ipa=*((IPAddress*)(rtps_msg+4));              /* unicastReplyIPAddress */
48   conv_u32(&ipa,e_bit);
49   port=*((Port*)(rtps_msg+8));                  /* unicastReplyPort */
50   conv_u32(&ipa,e_bit);
51   
52   debug(43,3) ("recv: RTPS InfoREPLY from 0x%x-0x%x\n",
53                 mi->sourceHostId,mi->sourceAppId);
54
55   if (ipa!=IPADDRESS_INVALID) {
56     mi->unicastReplyIPAddress=ipa;
57   }
58   mi->unicastReplyPort=port;
59   if (rtps_msg[1] & 0x02) {
60     ipa=*((u_int32_t*)(rtps_msg+12));           /* multicastReplyIPAddress */
61     conv_u32(&ipa,e_bit);
62     port=*((u_int32_t*)(rtps_msg+16));          /* multicastReplyPort */
63     conv_u32(&port,e_bit);
64     mi->multicastReplyIPAddress=ipa;
65     mi->multicastReplyPort=port;
66   } else {
67     mi->multicastReplyIPAddress=IPADDRESS_INVALID;
68     mi->multicastReplyPort     =PORT_INVALID;
69   }
70 }
71