X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=dccp_send.c;h=6248ae80ef784d5739298b61b9494e76d2e769e5;hp=d2f81dd9168023df27a1fefdb883e3234382c1cc;hb=f7feafeef70ad8f4e8c6fff715a2287f3240e759;hpb=bae94d3ba972bb91626e5f15e2d5ac44da6b041d diff --git a/dccp_send.c b/dccp_send.c index d2f81dd9..6248ae80 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2009 Andre Noll + * Copyright (C) 2006-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -44,15 +44,44 @@ static void dccp_pre_select(int *max_fileno, fd_set *rfds, para_fd_set(dss->listen_fd, rfds, max_fileno); } +/** + * Query the TX CCID used on the sender-client half connection. + * \param sockfd Server socket descriptor to query (after accept(2)). + * \return CCID number > 0, -1 on error/incompatibility. + * + * NB: This feature is only available on Linux > 2.6.30; on older kernels + * ENOPROTOOPT ("Protocol not available") will be returned. + */ +static int dccp_get_tx_ccid(int sockfd) +{ + int tx_ccid; + socklen_t len = sizeof(tx_ccid); + + if (getsockopt(sockfd, SOL_DCCP, + DCCP_SOCKOPT_TX_CCID, &tx_ccid, &len) < 0) { + PARA_WARNING_LOG("DCCP_SOCKOPT_TX_CCID: %s\n", strerror(errno)); + return -1; + } + return tx_ccid; +} + static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds) { struct sender_client *sc; + int tx_ccid; - if (dss->listen_fd < 0 || !FD_ISSET(dss->listen_fd, rfds)) - return; - sc = accept_sender_client(dss); + sc = accept_sender_client(dss, rfds); if (!sc) return; + + /* If CCID identifiable, present client as #~ */ + tx_ccid = dccp_get_tx_ccid(sc->fd); + if (tx_ccid != -1) { + char *tmp = make_message("%s~%d", sc->name, tx_ccid); + + free(sc->name); + sc->name = tmp; + } /* * Bypass unused CCID paths: the sender does not receive application data * from the client; by shutting down this unused communication path we can @@ -104,9 +133,34 @@ static int dccp_com_allow(struct sender_command_data *scd) return 1; } +/** + * Return list of available CCIDs or warning, in static buffer. + */ +static const char *dccp_list_available_ccids(void) +{ + /* Worst case length: n * 3 digits + n-1 spaces + '\0' */ + static char list[DCCP_MAX_HOST_CCIDS * 4]; + uint8_t *ccids; + int i, len, nccids; + + nccids = dccp_available_ccids(&ccids); + if (nccids < 0) { + snprintf(list, sizeof(list), "Unable to query available CCIDs"); + } else { + for (i = len = 0; i < nccids; i++) + len += snprintf(list + len, sizeof(list) - len, + "%s%d", i ? " " : "", ccids[i]); + } + return list; +} + static char *dccp_info(void) { - return get_sender_info(dss, "dccp"); + char *info = get_sender_info(dss, "dccp"); + char *ret = make_message("%s" "\tsupported ccids: %s\n", + info, dccp_list_available_ccids()); + free(info); + return ret; } /**