From owner-freebsd-net@FreeBSD.ORG Wed Jul 18 09:44:33 2012 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A4D2B106566B for ; Wed, 18 Jul 2012 09:44:33 +0000 (UTC) (envelope-from dk311990@gmail.com) Received: from mail-ey0-f182.google.com (mail-ey0-f182.google.com [209.85.215.182]) by mx1.freebsd.org (Postfix) with ESMTP id 35CFD8FC16 for ; Wed, 18 Jul 2012 09:44:33 +0000 (UTC) Received: by eabm6 with SMTP id m6so501603eab.13 for ; Wed, 18 Jul 2012 02:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=cG41OCBECCxiMSOXUWgmhSh0X3eWetBeSl5rKu9mPR4=; b=i/4SASbKkDpgGwbLoBsQQejVjW2bqWwq9UDXsure5JAr5+kFK8ARV8Zq5qnCrFDKra M9VeSsUrY76179LyDGRSzm4GP0Z55R4t6lj7A3EUCXtED0W0yUyCCegiv+tVJQYjlI+j kWpC/XWsV0V6OzLgHyKRS8BjNunoCcPbtOv7Hzsf5zApmTi0NR6/sLdiPoriHeBTkyq3 vQXN5ww81AwRTgWae3nveU0t3hm0ahMPEKjNPOAByK8ESnXz3KWEIq8NX3c5a625w2Ge F/2yJ7CY08ro5txyedOU2PzOANSP80kojTUwt6aQG6lIcMRtwO1LiJ5ru0dZf2jBfkgJ uT+w== MIME-Version: 1.0 Received: by 10.14.175.5 with SMTP id y5mr2817132eel.40.1342604668184; Wed, 18 Jul 2012 02:44:28 -0700 (PDT) Received: by 10.14.99.14 with HTTP; Wed, 18 Jul 2012 02:44:28 -0700 (PDT) In-Reply-To: References: Date: Wed, 18 Jul 2012 15:14:28 +0530 Message-ID: From: Deepak Kumar To: freebsd-net@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: determine the nic pairs X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jul 2012 09:44:33 -0000 Hi Enthusiast, I have a server which has around 20 nic interfaces. Some are connected port to port via cross cable and some are connected via a switch and few are not connected. (Let consider all are connected port to port) I want to find out the way so that I can determine the pairs efficiently. I assigned ip starting from 172.x.x.30 with netmask 255.255.255.0 I created as many sockets as there are interfaces with socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) then I bind the all but one interfaces to the ip I gave using bind(sockfd, (struct sockaddr *)&in, sizeof(in)); where in is something like bzero(&in, sizeof(in)); in.sin_family = AF_INET; in.sin_port = htons(2074); in.sin_addr.s_addr = inet_addr("172.x.x.30+interfaceno"); and one left socket I did socket creation and using setsockopt I did int option = 1; setsockopt(sockfd[counter], SOL_SOCKET, SO_BROADCAST, &option, sizeof(option)); and do sendto(sockfd, arr, sizeof(arr), 0, (struct sockaddr *)&in, len); where in is bzero(&in, sizeof(in)); in.sin_family = AF_INET; in.sin_port = htons(2074); in.sin_addr.s_addr = inet_addr(172.x.x.255); Now I want to send the packet from one interface and who ever receive should be its partner. But when I do recvfrom for one socket it blocks and I am not able to implement timeout for it. select is not working as it need file discripter and socket call is returning struct socket. So how should I implement timeout in recvfrom or use there exist some equivalent of select for struct socket or any other way to implement this. PS: Ping is working fine in determining the pair but taking to much time.