title: Omnet++ : How to sent to multiple hosts in inet
body: <p>What if I want a host to send to several hosts but not all.</p>
  
  <pre><code>**.Host1.app1.destAddress = "6e:27:f5:71:ab:11"  
  **.Host1.app2.destAddress = "6e:27:f5:71:ac:12"  
  **.Host1.app3.destAddress = "6e:27:f5:71:ad:13"
  </code></pre>
  
  <p>I am trying out with a work around by editing the app module as per below</p>
  
  <p>The code was</p>
  
  <pre><code>//omnetpp.ini    
  **.Host1.app.destAddress = "6e:27:f5:71:ab:11"
  
  void EtherTrafGen::handleMessage(cMessage *msg)
  {
  if (!isNodeUp())
          throw cRuntimeError("Application is not running");
      if (msg-&gt;isSelfMessage())
      {
         if (msg-&gt;getKind() == START)
           {
              destMACAddress = resolveDestMACAddress();
              if (destMACAddress.isUnspecified())
              return;
            }
          sendBurstPackets();
          scheduleNextPacket(simTime());
          }
      }
      else
          receivePacket(check_and_cast&lt;cPacket *&gt;(msg));
      }
  }
  
  MACAddress EtherTrafGen::resolveDestMACAddress()
  {
      MACAddress destMACAddress;
      destAddress = par("destAddress");
      if (destAddress[0]) {
          if (!destMACAddress.tryParse(destAddress)) {
              cModule *destStation = getModuleByPath(destAddress);
              if (!destStation)
                  throw cRuntimeError("...");
              cModule *destMAC = destStation-&gt;getSubmodule("mac");
              if (!destMAC)
                  throw cRuntimeError("...", destAddress);
              destMACAddress.setAddress(destMAC-&gt;par("address"));
          }
      }
      return destMACAddress;
  }
  </code></pre>
  
  <p>The changes I have done as follows</p>
  
  <pre><code>//omnetpp.ini
  **.Host1.app.destAddresses = "6e:27:f5:71:ab:11,6e:27:f5:71:ac:12,6e:27:f5:71:ad:13"
  
  class INET_API EtherTrafGen : public cSimpleModule, public ILifecycle
  {
    public:
      const char *destAddress;
      bool multipacket;
      std::vector&lt;std::string&gt; v;
      unsigned int x;
  }
  
  void EtherTrafGen::handleMessage(cMessage *msg)
  {
      multipacket = true;
      if (!isNodeUp())
          throw cRuntimeError("Application is not running");
      if (msg-&gt;isSelfMessage())
      {
          const char *destAddresses = par("destAddresses");
          if(multipacket)
          {
              std::vector&lt;std::string&gt; v = cStringTokenizer(destAddresses).asVector();
              for (x = 0; x &lt;= v.size(); x++)
              {
                  if (msg-&gt;getKind() == START)
                          {
                              destMACAddress = resolveDestMACAddress();
                              // if no dest address given, nothing to do
                              if (destMACAddress.isUnspecified())
                                  return;
                          }
                          sendBurstPackets();
                          scheduleNextPacket(simTime());
              }
          }
  
          else if(!(multipacket))
          {
              if (msg-&gt;getKind() == START)
                      {
                          destMACAddress = resolveDestMACAddress();
                          // if no dest address given, nothing to do
                          if (destMACAddress.isUnspecified())
                              return;
                      }
                      sendBurstPackets();
                      scheduleNextPacket(simTime());
          }
      }
      else
          receivePacket(check_and_cast&lt;cPacket *&gt;(msg));
  }
  
  MACAddress EtherTrafGen::resolveDestMACAddress()
  {
      MACAddress destMACAddress;
  
      if (multipacket)
      {destAddress = v[x].c_str();}
      else if (!multipacket)
      { destAddress = par("destAddress");}
  
      if (destAddress[0]) {
          if (!destMACAddress.tryParse(destAddress)) {
              cModule *destStation = getModuleByPath(destAddress);
              if (!destStation)
                  throw cRuntimeError("...");
  
              cModule *destMAC = destStation-&gt;getSubmodule("mac");
              if (!destMAC)
                  throw cRuntimeError("...", destAddress);
              destMACAddress.setAddress(destMAC-&gt;par("address"));
          }
      }
      return destMACAddress;
  }
  </code></pre>
  
  <p>The result is that it works fine if the bool multiaddress is false as the previous case but doesn't work if it is true but no error as well. As if it is overridden with an empty address.</p>
  
  <p>"I am so sorry for the long code, but I am afraid to miss function that might be related to what I am doing and I am not noticing"</p>