pespin submitted this change.

View Change



3 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.

Approvals: daniel: Looks good to me, but someone else must approve laforge: Looks good to me, approved Jenkins Builder: Verified
stream: srv cb: Use osmo_sockaddr and improve logging when cli connects

Specially important is the change where we now print the remote port
which connected to us, not our local port (which is already printed as
part of LOGSLNK).

Change-Id: I6e556f8263496ded41bb221ccc8e193c5361697f
---
M src/stream.c
1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/stream.c b/src/stream.c
index b646c3d..fdc1cc1 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -1155,36 +1155,27 @@
{
int ret;
int sock_fd;
- char addrstr[128];
- bool is_ipv6 = false;
- struct sockaddr_storage sa;
- socklen_t sa_len = sizeof(sa);
+ struct osmo_sockaddr osa;
+ socklen_t sa_len = sizeof(osa.u.sas);
struct osmo_stream_srv_link *link = ofd->data;

- ret = accept(ofd->fd, (struct sockaddr *)&sa, &sa_len);
+ ret = accept(ofd->fd, &osa.u.sa, &sa_len);
if (ret < 0) {
- LOGP(DLINP, LOGL_ERROR, "failed to accept from origin "
- "peer, reason=`%s'\n", strerror(errno));
+ LOGP(DLINP, LOGL_ERROR, "failed to accept from origin peer, reason=`%s'\n",
+ strerror(errno));
return ret;
}
sock_fd = ret;

- is_ipv6 = false;
- switch (((struct sockaddr *)&sa)->sa_family) {
+ switch (osa.u.sa.sa_family) {
case AF_UNIX:
LOGSLNK(link, LOGL_DEBUG, "accept()ed new link on fd %d\n",
sock_fd);
break;
case AF_INET6:
- is_ipv6 = true;
- /* fall through */
case AF_INET:
- LOGSLNK(link, LOGL_DEBUG, "accept()ed new link from %s to port %u\n",
- inet_ntop(is_ipv6 ? AF_INET6 : AF_INET,
- is_ipv6 ? (void *)&(((struct sockaddr_in6 *)&sa)->sin6_addr) :
- (void *)&(((struct sockaddr_in *)&sa)->sin_addr),
- addrstr, sizeof(addrstr)),
- link->port);
+ LOGSLNK(link, LOGL_DEBUG, "accept()ed new link from %s\n",
+ osmo_sockaddr_to_str(&osa));

if (link->proto == IPPROTO_SCTP) {
ret = sctp_sock_activate_events(sock_fd);
@@ -1194,7 +1185,7 @@
break;
default:
LOGSLNK(link, LOGL_DEBUG, "accept()ed unexpected address family %d\n",
- ((struct sockaddr *)&sa)->sa_family);
+ osa.u.sa.sa_family);
goto error_close_socket;
}


To view, visit change 33338. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I6e556f8263496ded41bb221ccc8e193c5361697f
Gerrit-Change-Number: 33338
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-MessageType: merged