From owner-freebsd-questions@FreeBSD.ORG Wed Jul 18 07:11:08 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E8E8D1065672 for ; Wed, 18 Jul 2012 07:11:08 +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 7392E8FC14 for ; Wed, 18 Jul 2012 07:11:08 +0000 (UTC) Received: by eabm6 with SMTP id m6so444663eab.13 for ; Wed, 18 Jul 2012 00:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=GOaxpnXvyLVE6Fjsqe62PqRq8eMTCWXdSpRwu0/+aUw=; b=gUvUc6pdLPJ4skrp+3rrNGQ4rT5oE6vlZyYKwjJQKFDQ4DDT1+vXc+F91LH425yOnH X/iyjyJ7wrh8pvS8kBkeH/pnleAHsVmzBP5WfBDDoxiinQ9SGqqsjtCDS+CTJAbCONAh ps1xwPVPYP4PA5Wo3aF72A6VypSIf2supOorkko6ZGOzFw6QWV/NuByIm6q/eGkjX3U8 7yd3uHqxDUVVxLr+DCAI3xg9hsMFIh8T1tYqu7XXRKGcJB9o3SbaA1BHf+mRbujacJht bSKjlHa1NJqUsiIS0dlJBxvuRKcdX0nHVO3cN+6YcETqodKv0pzlbafqeW2qlhO5jW2g OK6A== MIME-Version: 1.0 Received: by 10.14.0.130 with SMTP id 2mr2387220eeb.22.1342595467395; Wed, 18 Jul 2012 00:11:07 -0700 (PDT) Received: by 10.14.99.14 with HTTP; Wed, 18 Jul 2012 00:11:07 -0700 (PDT) Date: Wed, 18 Jul 2012 12:41:07 +0530 Message-ID: From: Deepak Kumar To: freebsd-questions@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-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jul 2012 07:11:09 -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.