2 * Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 #include <ipxe/socket.h>
28 #include <ipxe/tcpip.h>
30 #include <ipxe/iobuf.h>
31 #include <ipxe/xfer.h>
32 #include <ipxe/open.h>
34 #include <ipxe/features.h>
35 #include <ipxe/timer.h>
36 #include <ipxe/oncrpc.h>
37 #include <ipxe/oncrpc_iob.h>
38 #include <ipxe/portmap.h>
42 * PORTMAPPER protocol.
46 /** PORTMAP GETPORT procedure. */
47 #define PORTMAP_GETPORT 3
50 * Send a GETPORT request
52 * @v intf Interface to send the request on
53 * @v session ONC RPC session
54 * @v prog ONC RPC program number
55 * @v vers ONC RPC rogram version number
56 * @v proto Protocol (TCP or UDP)
57 * @ret rc Return status code
59 int portmap_getport ( struct interface *intf, struct oncrpc_session *session,
60 uint32_t prog, uint32_t vers, uint32_t proto ) {
61 struct oncrpc_field fields[] = {
62 ONCRPC_FIELD ( int32, prog ),
63 ONCRPC_FIELD ( int32, vers ),
64 ONCRPC_FIELD ( int32, proto ),
65 ONCRPC_FIELD ( int32, 0 ), /* The port field is only meaningful
70 return oncrpc_call ( intf, session, PORTMAP_GETPORT, fields );
74 * Parse a GETPORT reply
76 * @v getport_reply A structure where the data will be saved
77 * @v reply The ONC RPC reply to get data from
78 * @ret rc Return status code
80 int portmap_get_getport_reply ( struct portmap_getport_reply *getport_reply,
81 struct oncrpc_reply *reply ) {
82 if ( ! getport_reply || ! reply )
85 getport_reply->port = oncrpc_iob_get_int ( reply->data );
86 if ( getport_reply == 0 || getport_reply->port >= 65536 )