diff options
author | Max <msuraev@sysmocom.de> | 2017-10-13 15:30:54 +0200 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2017-10-13 18:13:14 +0200 |
commit | 8440357d4cc88479921350344e435ee9c5e4e0f1 (patch) | |
tree | 9f168c3fc7d5d3595f7428745120bf674fed5e68 /examples/udp-test-server.c | |
parent | fae8559ff5ce825a874eeb33b2f1053430c07dc3 (diff) |
examples: add simple UDP client/server
In addition to showing basic UDP send/receive example, it helps to test
corner-case when dealing with 0-length UDP packets.
Change-Id: I08c0adf1cf9b6a6f1f7090b237d0497c2ec13cdf
Related: OS#2219
Diffstat (limited to 'examples/udp-test-server.c')
-rw-r--r-- | examples/udp-test-server.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/udp-test-server.c b/examples/udp-test-server.c new file mode 100644 index 0000000..444843a --- /dev/null +++ b/examples/udp-test-server.c @@ -0,0 +1,35 @@ +#include "udp-test.h" + +int read_cb(struct osmo_dgram *conn) +{ + int bytes; + struct msgb *msg = print_recv(conn); + + if (!msg) + return -1; + + /* build reply: */ + bytes = msgb_length(msg); + + if (!mtrim(msg, 0, bytes)) + return -1; + + /* sent reply: */ + osmo_dgram_send(conn, msg); + + /* end test: */ + if (bytes > NUM_MSG - 1) + please_dont_die = false; + + return 0; +} + +int main(int argc, char **argv) +{ + if (!dgram_init(THOST, SPORT, CPORT, read_cb)) + return EXIT_FAILURE; + + main_loop(THOST, SPORT, CPORT); + + return 0; +} |