determine the nic pairs

Deepak Kumar dk311990 at
Wed Jul 18 07:11:09 UTC 2012

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
I created as many sockets as there are interfaces with
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,
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.

More information about the freebsd-questions mailing list