mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-07 11:50:24 +00:00
parent
3d0bde2147
commit
46463562f6
@ -12,7 +12,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
|
#include <base/attached_rom_dataspace.h>
|
||||||
#include <base/log.h>
|
#include <base/log.h>
|
||||||
|
#include <libc/component.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -21,22 +23,24 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <os/config.h>
|
|
||||||
|
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
|
||||||
int main(void)
|
|
||||||
|
struct Test_failed : Genode::Exception { };
|
||||||
|
|
||||||
|
|
||||||
|
static void server_loop(Genode::Xml_node config_node)
|
||||||
{
|
{
|
||||||
int s;
|
int s;
|
||||||
|
|
||||||
Genode::log("Create new socket ...");
|
Genode::log("Create new socket ...");
|
||||||
if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||||
Genode::error("no socket available!");
|
Genode::error("no socket available!");
|
||||||
return -1;
|
throw Test_failed();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned port = 0;
|
unsigned port = 0;
|
||||||
Xml_node config_node = config()->xml_node();
|
|
||||||
try { config_node.attribute("port").value(&port); }
|
try { config_node.attribute("port").value(&port); }
|
||||||
catch (...) {
|
catch (...) {
|
||||||
error("Missing \"port\" attribute.");
|
error("Missing \"port\" attribute.");
|
||||||
@ -49,7 +53,7 @@ int main(void)
|
|||||||
in_addr.sin_addr.s_addr = INADDR_ANY;
|
in_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
if(bind(s, (struct sockaddr*)&in_addr, sizeof(in_addr))) {
|
if(bind(s, (struct sockaddr*)&in_addr, sizeof(in_addr))) {
|
||||||
Genode::error("bind failed!");
|
Genode::error("bind failed!");
|
||||||
return -1;
|
throw Test_failed();
|
||||||
}
|
}
|
||||||
|
|
||||||
Genode::log("Start the server loop ...");
|
Genode::log("Start the server loop ...");
|
||||||
@ -77,5 +81,20 @@ int main(void)
|
|||||||
n = sendto(s, buf, n, 0, (struct sockaddr*)&addr, len);
|
n = sendto(s, buf, n, 0, (struct sockaddr*)&addr, len);
|
||||||
Genode::log("Send ", n, " bytes back");
|
Genode::log("Send ", n, " bytes back");
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct Main
|
||||||
|
{
|
||||||
|
Main(Genode::Env &env)
|
||||||
|
{
|
||||||
|
Genode::Attached_rom_dataspace config_rom { env, "config" };
|
||||||
|
|
||||||
|
Libc::with_libc([&] () {
|
||||||
|
server_loop(config_rom.xml());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void Libc::Component::construct(Libc::Env &env) { static Main main(env); }
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
TARGET = test-lxip_udp_echo
|
TARGET = test-lxip_udp_echo
|
||||||
LIBS = posix libc_lxip config
|
LIBS = libc libc_lxip
|
||||||
SRC_CC = main.cc
|
SRC_CC = main.cc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user