libosmocore/include/osmocom/core
Neels Hofmeyr 0145751a97 add to osmo_sock_get_name*() API
Basically, I am applying code review that I would have given had I not been on
vacation when the last osmo_sock_get_name* stuff was merged.

osmo_sock_get_name2() is so far a static internal function. However, it is
nothing like osmo_sock_get_name(), so instead rename it to
osmo_sock_get_ip_and_port(). Also make it public API, no need to hide it.  I'm
adding an "and" in the name to hopefully clarify: "ip_port" vs. "ip_and_port"
-- there already are _get_X_ip_port() functions that only return the port
string, despite "ip" in the name.

Add new public osmo_sock_get_name2(), which is like osmo_sock_get_name(),
except it uses a static string instead of talloc, and omits the braces. This
is most convenient for log statement formats, avoiding dyn allocations.

Add new osmo_sock_get_name_buf(), which is like osmo_sock_get_name2() but
writes to a caller provided char buffer.

Use osmo_sock_get_name_buf() in the implementation of osmo_sock_get_name(),
but use another (non-static) local string buffer, because adding braces is too
complex without talloc_snprintf().

Rationale:

I want to improve the logging of socket errors, e.g. change

  DLMGCP ERROR Failed to read: 111/Connection refused (mgcp_client.c:720)

to

  DLMGCP ERROR Failed to read: r=10.0.99.2:2427<->l=10.0.99.2:2728: 111='Connection refused' (mgcp_client.c:721)

but it is just not handy to compose logging with the current API:

- osmo_sock_get_name() requires a talloc_free().
- all the others require output buffers.
- the only way to conveniently compose a logging string and,
- notably, the only trivial way to skip the string composition if the logging
  level is currently muted, is to have a function that returns a static string:
  the new osmo_sock_get_name2().
- (I think the osmo_sock_get_{local,remote}_* convenience wrappers should never
  have been added, because they encourage the caller to invoke the same code
  twice, for IP addr and port, and throw away one half each time.)

Related: Iae728192f499330d16836d9435648f6b8ed213b6 (osmo-mgw)
Change-Id: I8ad89ac447c9c582742e70d082072bdd40a5a398
2018-12-19 03:25:55 +01:00
..
application.h fix logging talloc ctx: add osmo_init_logging2() 2018-03-28 19:06:16 +02:00
backtrace.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
bitXXgen.h.tpl doxygen: enable AUTOBRIEF, drop \brief 2017-06-23 00:18:22 +00:00
bitcomp.h Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
bits.h [doc] bits.c: Better / more Doxygen documentation 2017-10-16 14:19:12 +02:00
bitvec.h Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
byteswap.h fix issue on big endian architecture 2018-04-09 17:32:11 +00:00
conv.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
counter.h counters: add osmo_counters_count() returns the amount of counters 2017-12-05 16:06:27 +01:00
crc16.h [doc] Put CRC-16 and generic CRC code in one Doxygen module 2017-10-16 14:29:26 +02:00
crcXXgen.h.tpl [doc] Put CRC-16 and generic CRC code in one Doxygen module 2017-10-16 14:29:26 +02:00
crcgen.h [doc] Put CRC-16 and generic CRC code in one Doxygen module 2017-10-16 14:29:26 +02:00
defs.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
endian.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
fsm.h use __FILE__, not __BASE_FILE__ 2018-08-20 20:23:18 +00:00
gsmtap.h GSMTAP: fix typos in comments 2018-10-07 20:25:06 +02:00
gsmtap_util.h gsmtap: Add value_strings for GSMTAP_TYPE and GSMTAP_CHANNEL 2017-07-13 00:03:29 +02:00
isdnhdlc.h isdnhdlc: Port from kernel to userspace 2018-05-11 21:57:46 +02:00
linuxlist.h Constify llist_count() parameter 2018-12-10 13:42:08 +00:00
linuxrbtree.h fix FSF address in sources/headers 2015-11-12 13:46:05 +01:00
logging.h logging vty: rewrite 'logging level' vty cmd generation 2018-09-13 15:46:55 +00:00
logging_internal.h logging vty: write: check logging levels validity 2018-09-13 15:46:55 +00:00
loggingrb.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
macaddr.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
msgb.h msgb: add test helpers 2018-12-12 09:34:12 +00:00
msgfile.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
panic.h osmo_panic(): Annotate as __attribute__ ((noreturn)) 2018-06-29 20:32:57 +02:00
plugin.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
prbs.h Add pseudo-random bit sequence generator to libosmcoore 2017-07-10 23:42:02 +02:00
prim.h [doc] Expand Doxuygen documentation for osmo_prim 2017-10-16 14:52:37 +02:00
process.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
rate_ctr.h rate_ctr: Add rate_ctr_inc2() as convenience wrapper 2018-02-24 14:46:35 +01:00
select.h Add osmo_timerfd_* functions for osmo_fd-wrapped timerfd 2018-05-10 10:33:54 +02:00
sercomm.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
serial.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
signal.h signal: Introduce API osmo_signal_talloc_ctx_init 2018-08-16 21:03:32 +02:00
socket.h add to osmo_sock_get_name*() API 2018-12-19 03:25:55 +01:00
stat_item.h [doc] stat_item: Complete doxygen documentation for API 2017-10-16 14:18:50 +02:00
statistics.h Rename 'statistics.c' to 'counter.c' 2017-10-15 19:51:35 +02:00
stats.h stats.h: Fix build on MacOS 2018-12-13 13:01:28 +00:00
strrb.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
talloc.h doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
timer.h timer: Fix clockid_t undefined on MacOS < 10.12 2018-12-10 11:02:16 +01:00
timer_compat.h timer: Fix clockid_t undefined on MacOS < 10.12 2018-12-10 11:02:16 +01:00
utils.h add osmo_bcd2str() 2018-12-10 17:06:30 +00:00
write_queue.h control_if: Avoid heap-use-after-free in osmo_wqueue_bfd_cb 2018-05-04 18:29:26 +02:00