From: Dante Date: Tue, 15 Sep 2009 15:44:34 +0000 (+0200) Subject: Allow the packet API to auto-discover TCP X-Git-Tag: release_3_0_0_beta0~1750 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fb1f664dc7e47a4071854f3be5f7c43055b7973;p=thirdparty%2Ffreeradius-server.git Allow the packet API to auto-discover TCP It will now call the udp/tcp "receive packet" function as appropriate, so that the callers do not need to be changed in order to handle TCP. Signed-off-by: Alan T. DeKok --- diff --git a/src/lib/packet.c b/src/lib/packet.c index 7937878e235..0898d19d0ca 100644 --- a/src/lib/packet.c +++ b/src/lib/packet.c @@ -271,6 +271,9 @@ typedef struct fr_packet_socket_t { int inaddr_any; fr_ipaddr_t ipaddr; int port; +#ifdef WITH_TCP + int type; +#endif } fr_packet_socket_t; @@ -343,7 +346,7 @@ int fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd) { int i, start; struct sockaddr_storage src; - socklen_t sizeof_src = sizeof(src); + socklen_t sizeof_src; fr_packet_socket_t *ps; if (!pl) return 0; @@ -368,6 +371,13 @@ int fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd) memset(ps, 0, sizeof(*ps)); ps->sockfd = sockfd; ps->offset = start; +#ifdef WITH_TCP + sizeof_src = sizeof(ps->type); + + if (getsockopt(sockfd, SOL_SOCKET, SO_TYPE, &ps->type, &sizeof_src) < 0) { + return 0; + } +#endif /* * Get address family, etc. first, so we know if we @@ -376,6 +386,7 @@ int fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd) * FIXME: udpfromto also does this, but it's not * a critical problem. */ + sizeof_src = sizeof(src); memset(&src, 0, sizeof_src); if (getsockname(sockfd, (struct sockaddr *) &src, &sizeof_src) < 0) { @@ -818,6 +829,11 @@ RADIUS_PACKET *fr_packet_list_recv(fr_packet_list_t *pl, fd_set *set) if (!FD_ISSET(pl->sockets[start].sockfd, set)) continue; +#ifdef WITH_TCP + if (pl->sockets[start].type == SOCK_STREAM) { + packet = fr_tcp_recv(pl->sockets[start].sockfd, 0); + } else +#endif packet = rad_recv(pl->sockets[start].sockfd, 0); if (!packet) continue;