aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/socket.h
AgeCommit message (Collapse)AuthorFilesLines
2019-02-04socket.h: add missing includeMax1-2/+7
socket.h uses INET6_ADDRSTRLEN without including arpa/inet.h where it's defined which might break external users of socket.h Fix this by adding missing include. The error was introduced in 64b51eb68bd272b6b1f2cefa2b33e9dd74024d0c Change-Id: I2883addcb81cec038577e401e356e8f07a947d4c
2019-01-17socket: add define for socket name lengthPhilipp Maier1-0/+2
The function osmo_sock_get_name_buf() can be used to write a string representation to a user provided memory. Unfortunately the proper length for the user provided memory is not obvious. To make using osmo_sock_get_name_buf() more practical, add a define constant that defines the length of the required memory. Also use this define in socket.c. Change-Id: If8be8c2c0d4935da17ab13b2c2127b719ceefbcc
2018-12-19add to osmo_sock_get_name*() APINeels Hofmeyr1-0/+3
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-07Add osmo_sockaddr_in_to_str_and_uint()Max1-0/+3
It's similar to osmo_sockaddr_to_str_and_uint() but does not require odd typecasting for AF_INET case. Make osmo_sockaddr_to_str_and_uint() into wrapper around new function and make sure to check for address family before typecasting. Also use proper return type. Change-Id: Ie384483124d407a960ab6732e6a7fd90554389d2
2018-10-26add osmo_sock_get_{local,remote}_ip{,_port}()Oliver Smith1-0/+6
Return only the IP or port of either the local or remote connection, not the whole set of IP and port of both the local and remote connection like osmo_sock_get_name() does it. This is needed for OS#2841, where we only want to print the remote IP. Related: OS#2841 Change-Id: I6803c204771c59a2002bc6a0e6b79c83c35f87e1
2018-08-23socket: add flag to enforce SO_REUSEADDR on UDP socketsPhilipp Maier1-0/+2
When IPPROTO_UDP is used then SO_REUSEADDR omitted since UDP is connection less we do not have to wait until lingering connections time out. There were also negative effects such as that two applicatications could use the same UDP port, normally one of the two applications would get an error, but with SO_REUSEADDR this is supressed. However, there are applications (UDP MULTICAST) where two applications must be able to use the same port. In the osmocom project those are osmo-bts-virtual, virtphy and gsmtap in general. Lets introduce a flag that the API user can supply in order to have SO_REUSEADDR applied. - Add new flag OSMO_SOCK_F_UDP_REUSEADDR Change-Id: I94aaf6d5224ab23bde5ea5c4a83569b6145ab32b Related: OS#3497
2018-07-20add osmo_sockaddr_to_str_and_uint()Neels Hofmeyr1-0/+3
This came from osmo-bsc refactoring patch I82e3f918295daa83274a4cf803f046979f284366 https://gerrit.osmocom.org/#/c/osmo-bsc/+/9671/6/src/osmo-bsc/gsm_data.c@1708 Add regression test in utils_test.c. Change-Id: I1f2918418c38918c5ac70acaa51a47adfca12b5e
2017-10-23socket: add function osmo_sock_local_ip() to query local ipPhilipp Maier1-0/+2
In some cases it is required to know the ip-address of the interface through that a given remote IP-Address can be reached. Add function osmo_sock_local_ip() to determine the local ip-address for a given remote ip-address Change-Id: I2988cc52b196fc8476703d1287e24cb4a48491c2
2017-07-13socket: Add new OSMO_SOCK_F_NO_MCAST_ALL optionHarald Welte1-0/+2
Using this option at socket creation, the caller can request disabling the IP_MULTICAST_ALL socket option. Change-Id: I5ab5de45c0b64ceb3636ea98245a23defa24ffd4
2017-07-13socket: Allow disabling multicast loop on socket creationHarald Welte1-0/+2
This introduces a new flag OSMO_SOCK_F_NO_MCAST_LOOP, which can be used to disable the looping back of multicast packets transmitted throug this socket to other local sockets on the machine. As this looping-back is active by default, a single option to deviate from the default is deemed sufficient. Change-Id: I24a5b1ebc3f84d2d5d4734e54df50efaea26490b
2017-07-13socket.c: Add multicast related convenience functionsHarald Welte1-0/+6
Change-Id: Id703e7a7a1e065181a4c76c088b8dcc1b7fe15a2
2017-06-23doxygen: unify use of \file across the boardNeels Hofmeyr1-5/+4
Considering the various styles and implications found in the sources, edit scores of files to follow the same API doc guidelines around the doxygen grouping and the \file tag. Many files now show a short description in the generated API doc that was so far only available as C comment. The guidelines and reasoning behind it is documented at https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation In some instances, remove file comments and add to the corresponding group instead, to be shared among several files (e.g. bitvec). Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr1-1/+1
Especially for short descriptions, it is annoying to have to type \brief for every single API doc. Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes the first sentence of an API doc as the brief description. Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-05-26socket: Add osmo_sock_init2_ofd() functionPau Espin Pedrol1-0/+4
Will be used by osmo-bts-trx Change-Id: I3c655a4af64fb80497a5aaa811cce8005dba9cd9
2017-04-09Add osmo_sock_init2() function, allowing both BIND *and* CONNECTHarald Welte1-0/+4
The old osmo_sock_init() function allows only either a bind (for a server socket), or a connect (for a client socket), but not both together. So there's no way to have a client socket that is bound to a specific local IP and/or port, which is needed for some use cases. Change-Id: Idab124bcca47872f55311a82d6818aed590965e6
2017-01-27socket: Introduce function to obtain socket nameHarald Welte1-0/+2
Using this function, one can obtain a human-readable string identifying the host and port names of the socket. Change-Id: Ib5de5c7b9effe1b0a363e4473a7be7fa38ca6ef3
2016-05-05Update doxygen annotations in libosmocoreHarald Welte1-0/+3
This adds and improves doxygen API descriptions all over libosmocore, reducing the 'white spots' that don't have any documentation.
2014-06-16include: Switch to #pragma once patternSylvain Munaut1-4/+1
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2014-03-26src/socket: Adding unix domain socket supportÁlvaro Neira Ayuso1-0/+6
Added some function for adding the unix domain socket support. Signed-off-by: Alvaro Neira Ayuso <anayuso@sysmocom.de>
2012-04-18doc: Fix the Doxygen section endingsSylvain Munaut1-1/+1
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-03-16misc: Fix warning when compiling telnet_interface.cHolger Hans Peter Freyther1-0/+1
In file included from telnet_interface.c:30:0: osmocom/core/socket.h:25:4: warning: 'struct osmo_fd' declared inside parameter list [enabled by default] telnet_interface.c: In function 'telnet_init_dynif': telnet_interface.c:84:4: warning: passing argument 1 of 'osmo_sock_init_ofd' from incompatible pointer type [enabled by default] osmocom/core/socket.h:24:5: note: expected 'struct osmo_fd *' but argument is of type 'struct osmo_fd *'
2011-08-17some more doxygen work (include the notion of modules)Harald Welte1-38/+6
2011-08-16start to add doxygen documentation to libosmocore headersHarald Welte1-1/+42
2011-06-13socket: add OSMO_SOCK_F_[CONNECT|BIND|NON_BLOCK] flagsPablo Neira Ayuso1-3/+8
This extends the socket infrastructure in libosmocore to allow to create non-blocking sockets. Basically, it replaces the connect0_bind1 parameter by one flags parameter.
2011-05-22socket: use listen() and SO_REUSEADDR, new osmo_sock_init_ofd() functionHarald Welte1-0/+3
osmo_sock_init_ofd() is a wrapper around osmo_sock_init() which will take care of initializing and registering a 'struct osmo_fd' for the newly-created socket.
2011-05-22GSMTAP/socket code: Check for sys/socket.h and conditionally compileHarald Welte1-2/+3
2011-05-22gsmtap: rework GSMTAP API to be more future-proof0.3.1Harald Welte1-0/+16
* use write_queue where applicable * provide functions that work on raw FD and those with osmo_fd * add support for multiple gsmtap instances (no global variables)