@@ -73,7 +73,7 @@ void Core::dhcpServer(DhcpPacket *message) {
7373 0 ,
7474 message->xid ,
7575 0 ,
76- DHCP_FLAGS_BROADCAST ,
76+ this -> options . serverFlags ,
7777 nullptr ,
7878 &slot->clientIp ,
7979 &this ->socket .netinfo .ipAddr ,
@@ -82,11 +82,19 @@ void Core::dhcpServer(DhcpPacket *message) {
8282 nullptr );
8383 memcpy (response.chaddr , message->chaddr , ETHHWASIZE);
8484 this ->addDhcpDefaultOpt (&response, slot, DHCP_OFFER);
85+
8586 // INFO
8687 pktInfo.ipSrc = this ->socket .netinfo .ipAddr ;
87- pktInfo.ipDst .ip = 0xFFFFFFFF ;
88- eth_bcast (&pktInfo.phisAddr );
8988 pktInfo.toServer = false ;
89+
90+ if (this ->options .serverFlags & DHCP_FLAGS_BROADCAST) {
91+ pktInfo.ipDst .ip = 0xFFFFFFFF ;
92+ eth_bcast (&pktInfo.phisAddr );
93+ } else {
94+ pktInfo.ipDst .ip = slot->clientIp .ip ;
95+ memcpy (pktInfo.phisAddr .mac , message->chaddr , ETHHWASIZE);
96+ }
97+
9098 if ((tmp = this ->socket .sendDhcpMsg (&response, DHCPPKTSIZE, &pktInfo)) < 0 )
9199 std::cerr << " DHCP server err: " << spark_strerror (tmp) << std::endl;
92100 } else if (dhcp_type_equals (message, DHCP_REQUEST)) {
@@ -112,7 +120,7 @@ void Core::dhcpServer(DhcpPacket *message) {
112120 0 ,
113121 message->xid ,
114122 0 ,
115- DHCP_FLAGS_BROADCAST ,
123+ this -> options . serverFlags ,
116124 nullptr ,
117125 &slot->clientIp ,
118126 &this ->socket .netinfo .ipAddr ,
@@ -121,11 +129,17 @@ void Core::dhcpServer(DhcpPacket *message) {
121129 nullptr );
122130 memcpy (response.chaddr , message->chaddr , ETHHWASIZE);
123131 this ->addDhcpDefaultOpt (&response, slot, DHCP_ACK);
132+
124133 // INFO
125134 pktInfo.ipSrc = this ->socket .netinfo .ipAddr ;
126- pktInfo.ipDst .ip = 0xFFFFFFFF ;
127- eth_bcast (&pktInfo.phisAddr );
128135 pktInfo.toServer = false ;
136+ if (this ->options .serverFlags & DHCP_FLAGS_BROADCAST) {
137+ pktInfo.ipDst .ip = 0xFFFFFFFF ;
138+ eth_bcast (&pktInfo.phisAddr );
139+ } else {
140+ pktInfo.ipDst .ip = slot->clientIp .ip ;
141+ memcpy (pktInfo.phisAddr .mac , message->chaddr , ETHHWASIZE);
142+ }
129143 if ((tmp = this ->socket .sendDhcpMsg (&response, DHCPPKTSIZE, &pktInfo)) < 0 )
130144 std::cerr << " DHCP server err: " << spark_strerror (tmp) << std::endl;
131145 } else if (dhcp_type_equals (message, DHCP_RELEASE))
0 commit comments