aboutsummaryrefslogtreecommitdiffstats
path: root/library/MSLookup_mDNS_Emulation.ttcn
blob: 029091deb944d4379bbb1b3201e25ada16f50b13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module MSLookup_mDNS_Emulation {

/* (C) 2020 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

import from DNS_Types all;
import from UDPasp_Types all;
import from MSLookup_mDNS_Types all;

/* Transcode between mDNS and UDP:
   Wait for DNS packets on the mDNS port, encode them as UDP and forward them to the mDNS_UDP port.
   Wait for UDP packets on mDNS_UDP port, decode them as DNS and forward them to the mDNS port. */
function f_main() runs on MSLookup_mDNS_Emulation_CT
{
	var MSLookup_mDNS vl_dnsmsg;
	var ASP_UDP vl_udpmsg;
	map(self:mDNS_UDP, system:UDP);
	alt {
	[] mDNS_UDP.receive(ASP_UDP:?) -> value vl_udpmsg {
		mDNS.send(MSLookup_mDNS: {
			  dec_PDU_DNS(vl_udpmsg.data),
			  vl_udpmsg.addressf,
			  vl_udpmsg.portf
		});
		repeat;
		}
	[] mDNS.receive(MSLookup_mDNS:?) -> value vl_dnsmsg {
		mDNS_UDP.send(ASP_UDP: {
			 enc_PDU_DNS(vl_dnsmsg.dnsMessage, false, true),
			 vl_dnsmsg.udpAddress,
			 vl_dnsmsg.udpPort
		});
		repeat;
		}
	}
	unmap(self:mDNS_UDP, system:UDP);
}

}