blob: 60bebaaebeaccc0e47b4962ebdfc8514c4966179 [file] [log] [blame]
Neels Hofmeyr996ec1d2015-12-02 15:43:10 +01001/* GTP Hub Implementation */
2
3/* (C) 2015 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
4 * All Rights Reserved
5 *
6 * gtphub_sock.c.
7 *
8 * This file is kept separate so that these functions can be wrapped for
9 * gtphub_test.c. When a function and its callers are in the same compilational
10 * unit, the wrappability may be optimized away.
11 *
12 * Author: Neels Hofmeyr
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Affero General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Affero General Public License for more details.
23 *
24 * You should have received a copy of the GNU Affero General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#include <openbsc/gtphub.h>
29#include <openbsc/debug.h>
30
31/* Convenience makro, note: only within this C file. */
32#define LOG(level, fmt, args...) \
33 LOGP(DGTPHUB, level, fmt, ##args)
34
35int gtphub_write(const struct osmo_fd *to,
36 const struct osmo_sockaddr *to_addr,
37 const uint8_t *buf, size_t buf_len)
38{
39 errno = 0;
40 ssize_t sent = sendto(to->fd, buf, buf_len, 0,
41 (struct sockaddr*)&to_addr->a, to_addr->l);
42 LOG(LOGL_DEBUG, "to %s\n", osmo_sockaddr_to_str(to_addr));
43
44 if (sent == -1) {
45 LOG(LOGL_ERROR, "error: %s\n", strerror(errno));
46 return -EINVAL;
47 }
48
49 if (sent != buf_len)
50 LOG(LOGL_ERROR, "sent(%d) != data_len(%d)\n",
51 (int)sent, (int)buf_len);
52 else
Neels Hofmeyr36948bf2015-12-07 13:36:47 +010053 LOG(LOGL_DEBUG, "Sent %d: %s%s\n",
54 (int)sent,
55 osmo_hexdump(buf, sent > 1000? 1000 : sent),
56 sent > 1000 ? "..." : "");
Neels Hofmeyr996ec1d2015-12-02 15:43:10 +010057
58 return 0;
59}
60