1 /* $NetBSD: ndbootd.h,v 1.4 2003/08/17 22:34:17 itojun Exp $ */
3 /* ndbootd.h - header file for the Sun Network Disk (nd) daemon: */
6 * Copyright (c) 2001 Matthew Fredette. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Matthew Fredette.
19 * 4. The name of Matthew Fredette may not be used to endorse or promote
20 * products derived from this software without specific prior written
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28 /* <<Header: /data/home/fredette/project/THE-WEIGHT-CVS/ndbootd/ndbootd.h,v 1.3 2001/05/22 13:13:20 fredette Exp >> */
31 * <<Log: ndbootd.h,v >>
32 * Revision 1.3 2001/05/22 13:13:20 fredette
33 * Ran indent(1) with NetBSD's KNF-approximating profile.
35 * Revision 1.2 2001/01/31 17:35:16 fredette
36 * Now include param.h.
38 * Revision 1.1 2001/01/29 15:12:13 fredette
47 static const char _ndbootd_h_rcsid
[] = "<<Id: ndbootd.h,v 1.3 2001/05/22 13:13:20 fredette Exp >>";
53 #endif /* HAVE_CONFIG_H */
62 #include <sys/param.h>
63 #include <sys/socket.h>
66 #include <netinet/in_systm.h>
67 #include <netinet/in.h>
68 #if defined(HAVE_SYS_SOCKIO_H)
69 #include <sys/sockio.h>
70 #elif defined(HAVE_SYS_SOCKETIO_H) /* HAVE_SYS_SOCKIO_H,
71 * HAVE_SYS_SOCKETIO_H */
72 #include <sys/socketio.h>
73 #endif /* HAVE_SYS_SOCKETIO_H */
74 #include <sys/ioctl.h>
77 #endif /* HAVE_IOCTLS_H */
78 #ifdef HAVE_NET_IF_ETHER_H
79 #include <net/if_ether.h>
80 #endif /* HAVE_NET_IF_ETHER_H */
81 #ifdef HAVE_NET_ETHERNET_H
82 #include <net/ethernet.h>
83 #endif /* HAVE_NET_ETHERNET_H */
84 #include <netinet/ip.h>
85 #ifdef HAVE_NET_IF_DL_H
86 #include <net/if_dl.h>
87 #endif /* HAVE_NET_IF_DL_H */
88 #include <arpa/inet.h>
93 #define _NDBOOTD_P(x) x
96 #endif /* !__STDC__ */
100 #define TRUE (!FALSE)
101 #ifndef HAVE_STRERROR
102 #define strerror(e) ((e) < sys_nerr ? sys_errlist[e] : "unknown error")
103 #endif /* !HAVE_STRERROR */
105 #define MAX(a, b) ((a) > (b) ? (a) : (b))
108 #define MIN(a, b) ((a) < (b) ? (a) : (b))
111 #define _NDBOOTD_DO_DEBUG
113 #ifdef _NDBOOTD_DO_DEBUG
114 #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)
115 #else /* !_NDBOOTD_DO_DEBUG */
116 #define _NDBOOTD_DEBUG(x)
117 #endif /* !_NDBOOTD_DO_DEBUG */
118 #define NDBOOTD_PID_FILE "/var/run/ndbootd.pid"
120 #define NDBOOTD_OFFSETOF(t, m) (((char *) &(((t *) NULL)-> m)) - ((char *) ((t *) NULL)))
122 #define NDBOOT_OP_READ (0x01)
123 #define NDBOOT_OP_WRITE (0x02)
124 #define NDBOOT_OP_ERROR (0x03)
125 #define NDBOOT_OP_MASK (0x07)
126 #define NDBOOT_OP_FLAG_WAIT (1 << 3)
127 #define NDBOOT_OP_FLAG_DONE (1 << 4)
128 #define NDBOOT_MAX_PACKET_DATA (1024)
129 #define NDBOOT_MAX_BYTE_COUNT (63 * 1024)
130 #define NDBOOT_WINDOW_SIZE_DEFAULT (6)
131 #define NDBOOT_BSIZE (512)
132 #define NDBOOT_MINOR_NDP0 (0x40)
134 #define IPPROTO_ND 77
138 /* our network interface: */
139 struct ndbootd_interface
{
142 struct ifreq
*ndbootd_interface_ifreq
;
144 /* our Ethernet address: */
145 u_int8_t ndbootd_interface_ether
[ETHER_ADDR_LEN
];
147 /* the socket for the interface: */
148 int ndbootd_interface_fd
;
150 /* private data for the raw interface: */
151 void *_ndbootd_interface_raw_private
;
153 /* the Sun Network Disk (nd) packet format: */
154 struct ndboot_packet
{
156 /* the operation code: */
157 u_int8_t ndboot_packet_op
;
159 /* the minor device: */
160 u_int8_t ndboot_packet_minor
;
163 int8_t ndboot_packet_error
;
165 /* the disk version number: */
166 int8_t ndboot_packet_disk_version
;
168 /* the sequence number: */
169 int32_t ndboot_packet_sequence
;
171 /* the disk block number: */
172 int32_t ndboot_packet_block_number
;
174 /* the byte count: */
175 int32_t ndboot_packet_byte_count
;
177 /* the residual byte count: */
178 int32_t ndboot_packet_residual_byte_count
;
180 /* the current byte offset: */
181 int32_t ndboot_packet_current_byte_offset
;
183 /* the current byte count: */
184 int32_t ndboot_packet_current_byte_count
;
188 int ndbootd_raw_open
_NDBOOTD_P((struct ndbootd_interface
*));
189 int ndbootd_raw_read
_NDBOOTD_P((struct ndbootd_interface
*, void *, size_t));
190 int ndbootd_raw_write
_NDBOOTD_P((struct ndbootd_interface
*, void *, size_t));
192 #endif /* !_NDBOOTD_H */