Neels Hofmeyr | 996ec1d | 2015-12-02 15:43:10 +0100 | [diff] [blame] | 1 | /* 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 | |
Pau Espin Pedrol | 6aad14c | 2023-01-09 13:27:24 +0100 | [diff] [blame] | 28 | #include <errno.h> |
| 29 | #include <string.h> |
| 30 | |
| 31 | #include <osmocom/core/utils.h> |
| 32 | |
Pau Espin Pedrol | f2307c4 | 2023-01-09 11:55:18 +0100 | [diff] [blame] | 33 | #include <osmocom/gtphub/gtphub.h> |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 34 | #include <osmocom/sgsn/debug.h> |
Neels Hofmeyr | 996ec1d | 2015-12-02 15:43:10 +0100 | [diff] [blame] | 35 | |
| 36 | /* Convenience makro, note: only within this C file. */ |
| 37 | #define LOG(level, fmt, args...) \ |
| 38 | LOGP(DGTPHUB, level, fmt, ##args) |
| 39 | |
| 40 | int gtphub_write(const struct osmo_fd *to, |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 41 | const struct sgsn_sockaddr *to_addr, |
Neels Hofmeyr | 996ec1d | 2015-12-02 15:43:10 +0100 | [diff] [blame] | 42 | const uint8_t *buf, size_t buf_len) |
| 43 | { |
| 44 | errno = 0; |
| 45 | ssize_t sent = sendto(to->fd, buf, buf_len, 0, |
| 46 | (struct sockaddr*)&to_addr->a, to_addr->l); |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 47 | LOG(LOGL_DEBUG, "to %s\n", sgsn_sockaddr_to_str(to_addr)); |
Neels Hofmeyr | 996ec1d | 2015-12-02 15:43:10 +0100 | [diff] [blame] | 48 | |
| 49 | if (sent == -1) { |
| 50 | LOG(LOGL_ERROR, "error: %s\n", strerror(errno)); |
| 51 | return -EINVAL; |
| 52 | } |
| 53 | |
| 54 | if (sent != buf_len) |
| 55 | LOG(LOGL_ERROR, "sent(%d) != data_len(%d)\n", |
| 56 | (int)sent, (int)buf_len); |
| 57 | else |
Neels Hofmeyr | 36948bf | 2015-12-07 13:36:47 +0100 | [diff] [blame] | 58 | LOG(LOGL_DEBUG, "Sent %d: %s%s\n", |
| 59 | (int)sent, |
| 60 | osmo_hexdump(buf, sent > 1000? 1000 : sent), |
| 61 | sent > 1000 ? "..." : ""); |
Neels Hofmeyr | 996ec1d | 2015-12-02 15:43:10 +0100 | [diff] [blame] | 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |