/
ndbootd.h
192 lines (164 loc) · 5.54 KB
/
ndbootd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* $NetBSD: ndbootd.h,v 1.5 2004/01/06 23:02:55 wiz Exp $ */
/* ndbootd.h - header file for the Sun Network Disk (nd) daemon: */
/*
* Copyright (c) 2001 Matthew Fredette. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Matthew Fredette.
* 4. The name of Matthew Fredette may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* <<Header: /data/home/fredette/project/THE-WEIGHT-CVS/ndbootd/ndbootd.h,v 1.3 2001/05/22 13:13:20 fredette Exp >> */
/*
* <<Log: ndbootd.h,v >>
* Revision 1.3 2001/05/22 13:13:20 fredette
* Ran indent(1) with NetBSD's KNF-approximating profile.
*
* Revision 1.2 2001/01/31 17:35:16 fredette
* Now include param.h.
*
* Revision 1.1 2001/01/29 15:12:13 fredette
* Added.
*
*/
#ifndef _NDBOOTD_H
#define _NDBOOTD_H
#if 0
static const char _ndbootd_h_rcsid[] = "<<Id: ndbootd.h,v 1.3 2001/05/22 13:13:20 fredette Exp >>";
#endif
/* includes: */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <net/if.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#if defined(HAVE_SYS_SOCKIO_H)
#include <sys/sockio.h>
#elif defined(HAVE_SYS_SOCKETIO_H) /* HAVE_SYS_SOCKIO_H,
* HAVE_SYS_SOCKETIO_H */
#include <sys/socketio.h>
#endif /* HAVE_SYS_SOCKETIO_H */
#include <sys/ioctl.h>
#ifdef HAVE_IOCTLS_H
#include <ioctls.h>
#endif /* HAVE_IOCTLS_H */
#ifdef HAVE_NET_IF_ETHER_H
#include <net/if_ether.h>
#endif /* HAVE_NET_IF_ETHER_H */
#ifdef HAVE_NET_ETHERNET_H
#include <net/ethernet.h>
#endif /* HAVE_NET_ETHERNET_H */
#include <netinet/ip.h>
#ifdef HAVE_NET_IF_DL_H
#include <net/if_dl.h>
#endif /* HAVE_NET_IF_DL_H */
#include <arpa/inet.h>
#include <ifaddrs.h>
/* macros: */
#ifdef __STDC__
#define _NDBOOTD_P(x) x
#else /* !__STDC__ */
#define _NDBOOTD_P(x)
#endif /* !__STDC__ */
#undef FALSE
#undef TRUE
#define FALSE (0)
#define TRUE (!FALSE)
#ifndef HAVE_STRERROR
#define strerror(e) ((e) < sys_nerr ? sys_errlist[e] : "unknown error")
#endif /* !HAVE_STRERROR */
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif /* !MAX */
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif /* !MIN */
#if 1
#define _NDBOOTD_DO_DEBUG
#endif
#ifdef _NDBOOTD_DO_DEBUG
#define _NDBOOTD_DEBUG(x) do { if (_ndbootd_debug) { FILE *fp; int saved_errno; fp = stderr; saved_errno = errno; fprintf(fp, "%s: ", _ndbootd_argv0); errno = saved_errno; fprintf x ; fputc('\n', fp); errno = saved_errno; } } while(0)
#else /* !_NDBOOTD_DO_DEBUG */
#define _NDBOOTD_DEBUG(x)
#endif /* !_NDBOOTD_DO_DEBUG */
#define NDBOOTD_PID_FILE "/var/run/ndbootd.pid"
#define NDBOOTD_OFFSETOF(t, m) (((char *) &(((t *) NULL)-> m)) - ((char *) ((t *) NULL)))
#define NDBOOT_OP_READ (0x01)
#define NDBOOT_OP_WRITE (0x02)
#define NDBOOT_OP_ERROR (0x03)
#define NDBOOT_OP_MASK (0x07)
#define NDBOOT_OP_FLAG_WAIT (1 << 3)
#define NDBOOT_OP_FLAG_DONE (1 << 4)
#define NDBOOT_MAX_PACKET_DATA (1024)
#define NDBOOT_MAX_BYTE_COUNT (63 * 1024)
#define NDBOOT_WINDOW_SIZE_DEFAULT (6)
#define NDBOOT_BSIZE (512)
#define NDBOOT_MINOR_NDP0 (0x40)
#undef IPPROTO_ND
#define IPPROTO_ND 77
/* structures: */
/* our network interface: */
struct ndbootd_interface {
/* the interface: */
struct ifreq *ndbootd_interface_ifreq;
/* our Ethernet address: */
u_int8_t ndbootd_interface_ether[ETHER_ADDR_LEN];
/* the socket for the interface: */
int ndbootd_interface_fd;
/* private data for the raw interface: */
void *_ndbootd_interface_raw_private;
};
/* the Sun Network Disk (nd) packet format: */
struct ndboot_packet {
/* the operation code: */
u_int8_t ndboot_packet_op;
/* the minor device: */
u_int8_t ndboot_packet_minor;
/* any error: */
int8_t ndboot_packet_error;
/* the disk version number: */
int8_t ndboot_packet_disk_version;
/* the sequence number: */
int32_t ndboot_packet_sequence;
/* the disk block number: */
int32_t ndboot_packet_block_number;
/* the byte count: */
int32_t ndboot_packet_byte_count;
/* the residual byte count: */
int32_t ndboot_packet_residual_byte_count;
/* the current byte offset: */
int32_t ndboot_packet_current_byte_offset;
/* the current byte count: */
int32_t ndboot_packet_current_byte_count;
};
/* prototypes: */
int ndbootd_raw_open _NDBOOTD_P((struct ndbootd_interface *));
int ndbootd_raw_read _NDBOOTD_P((struct ndbootd_interface *, void *, size_t));
int ndbootd_raw_write _NDBOOTD_P((struct ndbootd_interface *, void *, size_t));
#endif /* !_NDBOOTD_H */