2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 1989, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * Portions of this source code were derived from Berkeley 2N/A * 4.3 BSD under license from the Regents of the University of 2N/A * Client interface to broadcast service. 2N/A * The following is kludged-up support for simple rpc broadcasts. 2N/A * Someday a large, complicated system will replace these routines. 2N/A#
define MAXBCAST 20 /* Max no of broadcasting transports */ 2N/Aint lowvers =
1;
/* by default, broadcast only version 2 over UDP */ 2N/A * If nettype is NULL, it broadcasts on all the available 2N/A * datagram_n transports. May potentially lead to broadacst storms 2N/A * and hence should be used with caution, care and courage. 2N/A * The current parameter xdr packet size is limited by the max tsdu 2N/A * size of the transport. If the max tsdu size of any transport is 2N/A * smaller than the parameter xdr packet, then broadcast is not 2N/A * sent on that transport. 2N/A * Also, the packet size should be less the packet size of 2N/A * the data link layer (for ethernet it is 1400 bytes). There is 2N/A * no easy way to find out the max size of the data link layer and 2N/A * we are assuming that the args would be smaller than that. 2N/A * The result size has to be smaller than the transport tsdu size. 2N/A * If PORTMAP has been defined, we send two packets for UDP, one for 2N/A * rpcbind and one for portmap. For those machines which support 2N/A * both rpcbind and portmap, it will cause them to reply twice, and 2N/A * also here it will get two responses ... inefficient and clumsy. 2N/A /* An array of all the suitable broadcast transports */ 2N/A int fd;
/* File descriptor */ 2N/A * initialization: create a fd, a broadcast address, and send the 2N/A * request on the broadcast transport. 2N/A * Listen on all of them and on replies, call the user supplied 2N/A break;
/* No more slots available */ 2N/A /* Do protocol specific negotiating for broadcast */ 2N/A /* Serialize all the arguments which have to be sent */ 2N/A /* XXX Should have set opt to its legal maxlen. */ 2N/A /* Prepare the packet for version 2 PORTMAP */ 2N/A * Basic loop: broadcast the packets to transports which 2N/A * support data packets of size such that one can encode 2N/A * all the arguments. 2N/A * Wait a while for response(s). 2N/A * The response timeout grows larger per iteration. 2N/A /* Broadcast all the packets now */ 2N/A /* fill in the multicast address */ 2N/A /* now send rpcbind message */ 2N/A "Cannot send broadcast\ 2N/A * Only use version 3 if lowvers 2N/A * is not set or transport is not UDP. 2N/A "Cannot send broadcast\ 2N/A * Send the version 2 packet also 2N/A"Cannot send broadcast packet: %m");
2N/A /* End for sending all packets on this transport */ 2N/A }
/* end non-IPv6 */ 2N/A }
/* End for sending on all transports */ 2N/A * Get all the replies from these broadcast requests 2N/A case 0:
/* timed out */ 2N/A case -
1:
/* some kind of error - we ignore it */ 2N/A }
/* end of poll results switch */ 2N/A * Something bad has happened to this descri- 2N/A * ptor. We can cause poll() to ignore 2N/A * it simply by using a negative fd. We do that 2N/A * rather than compacting the pfd[] and fdlist[] 2N/A * Ignore any T_UDERR look errors. 2N/A * We should never see any ICMP port 2N/A * unreachables when broadcasting but it has 2N/A * been observed with broken IP 2N/A "Cannot receive reply to \ 2N/A * Not taking care of flag for T_MORE. 2N/A * We are assuming that 2N/A * such calls should not take more than one 2N/A continue;
/* Drop that and go ahead */ 2N/A continue;
/* Drop that and go ahead */ 2N/A * see if reply transaction id matches sent id. 2N/A * If so, decode the results. If return id is xid + 1 2N/A * it was a PORTMAP reply 2N/A /* LINTED pointer cast */ 2N/A /* LINTED pointer cast */ 2N/A /* LINTED pointer cast */ 2N/A /* convert port to taddr */ 2N/A }
else /* Convert the uaddr to taddr */ 2N/A /* otherwise, we just ignore the errors ... */ 2N/A /* else some kind of deserialization problem ... */ 2N/A }
/* The recv for loop */ 2N/A }
/* The giant for loop */