iPXE
portmap.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
3 *
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.
8 *
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.
13 *
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
17 * 02110-1301, USA.
18 */
19
20FILE_SECBOOT ( FORBIDDEN );
21
22#include <stdint.h>
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26#include <assert.h>
27#include <errno.h>
28#include <byteswap.h>
29#include <ipxe/socket.h>
30#include <ipxe/tcpip.h>
31#include <ipxe/in.h>
32#include <ipxe/iobuf.h>
33#include <ipxe/xfer.h>
34#include <ipxe/open.h>
35#include <ipxe/uri.h>
36#include <ipxe/features.h>
37#include <ipxe/timer.h>
38#include <ipxe/oncrpc.h>
39#include <ipxe/oncrpc_iob.h>
40#include <ipxe/portmap.h>
41
42/** @file
43 *
44 * PORTMAPPER protocol.
45 *
46 */
47
48/** PORTMAP GETPORT procedure. */
49#define PORTMAP_GETPORT 3
50
51/**
52 * Send a GETPORT request
53 *
54 * @v intf Interface to send the request on
55 * @v session ONC RPC session
56 * @v prog ONC RPC program number
57 * @v vers ONC RPC rogram version number
58 * @v proto Protocol (TCP or UDP)
59 * @ret rc Return status code
60 */
61int portmap_getport ( struct interface *intf, struct oncrpc_session *session,
62 uint32_t prog, uint32_t vers, uint32_t proto ) {
63 struct oncrpc_field fields[] = {
64 ONCRPC_FIELD ( int32, prog ),
65 ONCRPC_FIELD ( int32, vers ),
66 ONCRPC_FIELD ( int32, proto ),
67 ONCRPC_FIELD ( int32, 0 ), /* The port field is only meaningful
68 in GETPORT reply */
70 };
71
72 return oncrpc_call ( intf, session, PORTMAP_GETPORT, fields );
73}
74
75/**
76 * Parse a GETPORT reply
77 *
78 * @v getport_reply A structure where the data will be saved
79 * @v reply The ONC RPC reply to get data from
80 * @ret rc Return status code
81 */
83 struct oncrpc_reply *reply ) {
84 if ( ! getport_reply || ! reply )
85 return -EINVAL;
86
87 getport_reply->port = oncrpc_iob_get_int ( reply->data );
88 if ( getport_reply == 0 || getport_reply->port >= 65536 )
89 return -EINVAL;
90
91 return 0;
92}
unsigned int uint32_t
Definition stdint.h:12
Assertions.
Error codes.
#define EINVAL
Invalid argument.
Definition errno.h:429
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
Transport-network layer interface.
iPXE timers
int32_t int32
Definition stdint.h:32
String functions.
I/O buffers.
Feature list.
int oncrpc_call(struct interface *intf, struct oncrpc_session *session, uint32_t proc_name, const struct oncrpc_field fields[])
Definition oncrpc.c:129
SUN ONC RPC protocol.
#define ONCRPC_FIELD_END
Definition oncrpc.h:32
#define ONCRPC_FIELD(type, value)
Definition oncrpc.h:28
SUN ONC RPC protocol.
#define oncrpc_iob_get_int(buf)
Get a 32 bits integer from the beginning of an I/O buffer.
Definition oncrpc_iob.h:38
Data transfer interface opening.
#define PORTMAP_GETPORT
PORTMAP GETPORT procedure.
Definition portmap.c:49
int portmap_getport(struct interface *intf, struct oncrpc_session *session, uint32_t prog, uint32_t vers, uint32_t proto)
Send a GETPORT request.
Definition portmap.c:61
int portmap_get_getport_reply(struct portmap_getport_reply *getport_reply, struct oncrpc_reply *reply)
Parse a GETPORT reply.
Definition portmap.c:82
SUN ONC RPC protocol.
Socket addresses.
An object interface.
Definition interface.h:125
struct io_buffer * data
Definition oncrpc.h:68
A PORTMAP GETPORT reply.
Definition portmap.h:35
uint32_t port
Port returned.
Definition portmap.h:37
Uniform Resource Identifiers.
Data transfer interfaces.