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 
20 #include <stdint.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <assert.h>
25 #include <errno.h>
26 #include <byteswap.h>
27 #include <ipxe/socket.h>
28 #include <ipxe/tcpip.h>
29 #include <ipxe/in.h>
30 #include <ipxe/iobuf.h>
31 #include <ipxe/xfer.h>
32 #include <ipxe/open.h>
33 #include <ipxe/uri.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>
39 
40 /** @file
41  *
42  * PORTMAPPER protocol.
43  *
44  */
45 
46 /** PORTMAP GETPORT procedure. */
47 #define PORTMAP_GETPORT 3
48 
49 /**
50  * Send a GETPORT request
51  *
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
58  */
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
66  in GETPORT reply */
68  };
69 
70  return oncrpc_call ( intf, session, PORTMAP_GETPORT, fields );
71 }
72 
73 /**
74  * Parse a GETPORT reply
75  *
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
79  */
81  struct oncrpc_reply *reply ) {
82  if ( ! getport_reply || ! reply )
83  return -EINVAL;
84 
85  getport_reply->port = oncrpc_iob_get_int ( reply->data );
86  if ( getport_reply == 0 || getport_reply->port >= 65536 )
87  return -EINVAL;
88 
89  return 0;
90 }
#define ONCRPC_FIELD(type, value)
Definition: oncrpc.h:28
#define EINVAL
Invalid argument.
Definition: errno.h:428
#define PORTMAP_GETPORT
PORTMAP GETPORT procedure.
Definition: portmap.c:47
Error codes.
I/O buffers.
iPXE timers
Uniform Resource Identifiers.
int oncrpc_call(struct interface *intf, struct oncrpc_session *session, uint32_t proc_name, const struct oncrpc_field fields[])
Definition: oncrpc.c:129
Data transfer interfaces.
#define oncrpc_iob_get_int(buf)
Get a 32 bits integer from the beginning of an I/O buffer.
Definition: oncrpc_iob.h:38
int32_t int32
Definition: stdint.h:31
Assertions.
An object interface.
Definition: interface.h:109
struct ntlm_data session
Session key.
Definition: ntlm.h:24
int portmap_get_getport_reply(struct portmap_getport_reply *getport_reply, struct oncrpc_reply *reply)
Parse a GETPORT reply.
Definition: portmap.c:80
Transport-network layer interface.
Feature list.
SUN ONC RPC protocol.
Data transfer interface opening.
unsigned int uint32_t
Definition: stdint.h:12
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:59
#define ONCRPC_FIELD_END
Definition: oncrpc.h:32
SUN ONC RPC protocol.
Socket addresses.
SUN ONC RPC protocol.
String functions.
uint32_t port
Port returned.
Definition: portmap.h:37
struct io_buffer * data
Definition: oncrpc.h:68
A PORTMAP GETPORT reply.
Definition: portmap.h:35