b8543e49b9
repect to non-allowable zero appletalk zone range. from maintainer
308 lines
8.2 KiB
Plaintext
308 lines
8.2 KiB
Plaintext
$OpenBSD: patch-etcatalkd-mainc,v 1.2 2001/03/19 13:50:01 wilfried Exp $
|
|
--- etc/atalkd/main.c.orig Mon Oct 6 01:50:47 1997
|
|
+++ etc/atalkd/main.c Thu Mar 15 19:26:37 2001
|
|
@@ -23,10 +23,11 @@
|
|
#include <syslog.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
-#include <strings.h>
|
|
+#include <string.h>
|
|
#include <netdb.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
+#include <stdlib.h>
|
|
|
|
#include <netatalk/endian.h>
|
|
#include <netatalk/at.h>
|
|
@@ -60,6 +61,10 @@ extern int rtmp_packet();
|
|
extern int nbp_packet();
|
|
extern int aep_packet();
|
|
extern int zip_packet();
|
|
+extern int readconf(), writeconf(), getifconf();
|
|
+
|
|
+void bootaddr(), setaddr(), dumpconfig();
|
|
+int ifconfig();
|
|
|
|
int rtfd;
|
|
|
|
@@ -100,9 +105,9 @@ as_timer()
|
|
struct ziptab *zt;
|
|
char *data, *end, packet[ 587 ];
|
|
int sentzipq = 0;
|
|
- int n, cc, i;
|
|
+ int n, cc;
|
|
|
|
- bzero( (caddr_t)&sat, sizeof( struct sockaddr_at ));
|
|
+ memset( (caddr_t)&sat, 0, sizeof( struct sockaddr_at ));
|
|
|
|
for ( iface = interfaces; iface; iface = iface->i_next ) {
|
|
if ( iface->i_flags & IFACE_LOOPBACK ) {
|
|
@@ -190,12 +195,12 @@ as_timer()
|
|
*/
|
|
syslog( LOG_INFO, "config for no router" );
|
|
if ( iface->i_flags & IFACE_PHASE2 ) {
|
|
- iface->i_rt->rt_firstnet = 0;
|
|
+ iface->i_rt->rt_firstnet = htons(1);
|
|
iface->i_rt->rt_lastnet = htons( STARTUP_LASTNET );
|
|
setaddr( iface, IFACE_PHASE2,
|
|
iface->i_addr.sat_addr.s_net,
|
|
iface->i_addr.sat_addr.s_node,
|
|
- 0, htons( STARTUP_LASTNET ));
|
|
+ htons(1), htons( STARTUP_LASTNET ));
|
|
}
|
|
if ( looproute( iface, RTMP_ADD ) < 0 ) {
|
|
syslog( LOG_ERR,
|
|
@@ -261,20 +266,21 @@ as_timer()
|
|
* as having no router, we will notice when a router
|
|
* comes back up.
|
|
*/
|
|
- if ( gate->g_iface->i_gate == 0 && ninterfaces == IFBASE ) {
|
|
+ if ( gate->g_iface->i_gate == 0 &&
|
|
+ ninterfaces == IFBASE) {
|
|
gate->g_iface->i_flags |= IFACE_NOROUTER;
|
|
gate->g_iface->i_flags &= ~IFACE_CONFIG;
|
|
syslog( LOG_INFO, "as_timer last gateway down" );
|
|
|
|
- /* Set netrange to 0-fffe. */
|
|
+ /* Set netrange to 1-fffe. */
|
|
if ( gate->g_iface->i_flags & IFACE_PHASE2 ) {
|
|
- gate->g_iface->i_rt->rt_firstnet = 0;
|
|
+ gate->g_iface->i_rt->rt_firstnet = htons(1);
|
|
gate->g_iface->i_rt->rt_lastnet =
|
|
htons( STARTUP_LASTNET );
|
|
setaddr( iface, IFACE_PHASE2,
|
|
iface->i_addr.sat_addr.s_net,
|
|
iface->i_addr.sat_addr.s_node,
|
|
- 0, htons( STARTUP_LASTNET ));
|
|
+ htons(1), htons( STARTUP_LASTNET ));
|
|
}
|
|
}
|
|
continue;
|
|
@@ -286,8 +292,8 @@ as_timer()
|
|
*/
|
|
if (( iface->i_rt->rt_flags & RTMPTAB_HASZONES ) == 0 ) {
|
|
iface->i_rt->rt_flags |= RTMPTAB_ZIPQUERY;
|
|
- bcopy( &iface->i_rt->rt_firstnet, data, sizeof( u_short ));
|
|
- data += sizeof( u_short );
|
|
+ memcpy( data, &iface->i_rt->rt_firstnet, sizeof( u_int16_t ));
|
|
+ data += sizeof( u_int16_t );
|
|
n++;
|
|
}
|
|
|
|
@@ -332,14 +338,14 @@ as_timer()
|
|
*/
|
|
if ( rtmp->rt_iprev &&
|
|
( rtmp->rt_flags & RTMPTAB_HASZONES ) == 0 ) {
|
|
- if ( data + sizeof( u_short ) > end || n == 255 ) {
|
|
+ if ( data + sizeof( u_int16_t ) > end || n == 255 ) {
|
|
/* send what we've got */
|
|
zh.zh_op = ZIPOP_QUERY;
|
|
zh.zh_count = n;
|
|
cc = data - packet;
|
|
data = packet;
|
|
*data++ = DDPTYPE_ZIP;
|
|
- bcopy( &zh, data, sizeof( struct ziphdr ));
|
|
+ memcpy( data, &zh, sizeof( struct ziphdr ));
|
|
|
|
if ( sendto( zap->ap_fd, packet, cc, 0,
|
|
(struct sockaddr *)&sat,
|
|
@@ -375,8 +381,8 @@ as_timer()
|
|
sentzipq = 1;
|
|
}
|
|
rtmp->rt_flags |= RTMPTAB_ZIPQUERY;
|
|
- bcopy( &rtmp->rt_firstnet, data, sizeof( u_short ));
|
|
- data += sizeof( u_short );
|
|
+ memcpy( data, &rtmp->rt_firstnet, sizeof( u_int16_t ));
|
|
+ data += sizeof( u_int16_t );
|
|
n++;
|
|
}
|
|
rtmp = rtmp->rt_next;
|
|
@@ -389,7 +395,7 @@ as_timer()
|
|
cc = data - packet;
|
|
data = packet;
|
|
*data++ = DDPTYPE_ZIP;
|
|
- bcopy( &zh, data, sizeof( struct ziphdr ));
|
|
+ memcpy( data, &zh, sizeof( struct ziphdr ));
|
|
|
|
if ( sendto( zap->ap_fd, packet, cc, 0, (struct sockaddr *)&sat,
|
|
sizeof( struct sockaddr_at )) < 0 ) {
|
|
@@ -420,7 +426,7 @@ as_timer()
|
|
rh.rh_net = iface->i_addr.sat_addr.s_net;
|
|
rh.rh_nodelen = 8;
|
|
rh.rh_node = iface->i_addr.sat_addr.s_node;
|
|
- bcopy( &rh, data, sizeof( struct rtmp_head ));
|
|
+ memcpy( data, &rh, sizeof( struct rtmp_head ));
|
|
data += sizeof( struct rtmp_head );
|
|
n = 0;
|
|
|
|
@@ -428,17 +434,17 @@ as_timer()
|
|
if ( iface->i_flags & IFACE_PHASE1 ) {
|
|
rt.rt_net = 0;
|
|
rt.rt_dist = 0x82;
|
|
- bcopy( &rt, data, SZ_RTMPTUPLE );
|
|
+ memcpy( data, &rt, SZ_RTMPTUPLE );
|
|
data += SZ_RTMPTUPLE;
|
|
} else {
|
|
rt.rt_net = iface->i_rt->rt_firstnet;
|
|
rt.rt_dist = 0x80;
|
|
- bcopy( &rt, data, SZ_RTMPTUPLE );
|
|
+ memcpy( data, &rt, SZ_RTMPTUPLE );
|
|
data += SZ_RTMPTUPLE;
|
|
|
|
rt.rt_net = iface->i_rt->rt_lastnet;
|
|
rt.rt_dist = 0x82;
|
|
- bcopy( &rt, data, SZ_RTMPTUPLE );
|
|
+ memcpy( data, &rt, SZ_RTMPTUPLE );
|
|
data += SZ_RTMPTUPLE;
|
|
}
|
|
|
|
@@ -488,13 +494,13 @@ as_timer()
|
|
if ( rtmp->rt_flags & RTMPTAB_EXTENDED ) {
|
|
rt.rt_dist |= 0x80;
|
|
}
|
|
- bcopy( &rt, data, SZ_RTMPTUPLE );
|
|
+ memcpy( data, &rt, SZ_RTMPTUPLE );
|
|
data += SZ_RTMPTUPLE;
|
|
|
|
if ( rtmp->rt_flags & RTMPTAB_EXTENDED ) {
|
|
rt.rt_net = rtmp->rt_lastnet;
|
|
rt.rt_dist = 0x82;
|
|
- bcopy( &rt, data, SZ_RTMPTUPLE );
|
|
+ memcpy( data, &rt, SZ_RTMPTUPLE );
|
|
data += SZ_RTMPTUPLE;
|
|
}
|
|
n++;
|
|
@@ -561,6 +567,7 @@ as_timer()
|
|
/*
|
|
* Consistency check...
|
|
*/
|
|
+void
|
|
consistency()
|
|
{
|
|
struct rtmptab *rtmp;
|
|
@@ -734,6 +741,7 @@ as_down()
|
|
exit( 0 );
|
|
}
|
|
|
|
+int
|
|
main( ac, av )
|
|
int ac;
|
|
char **av;
|
|
@@ -794,7 +802,7 @@ main( ac, av )
|
|
exit( 1 );
|
|
}
|
|
|
|
- if (( prog = rindex( av[ 0 ], '/' )) == NULL ) {
|
|
+ if (( prog = strrchr( av[ 0 ], '/' )) == NULL ) {
|
|
prog = av[ 0 ];
|
|
} else {
|
|
prog++;
|
|
@@ -1128,10 +1136,10 @@ main( ac, av )
|
|
* and rtmp_packet()) to set the initial "bootstrapping" address
|
|
* on an interface.
|
|
*/
|
|
+void
|
|
bootaddr( iface )
|
|
struct interface *iface;
|
|
{
|
|
- struct sockaddr sa;
|
|
|
|
if ( iface == 0 ) {
|
|
return;
|
|
@@ -1182,12 +1190,13 @@ bootaddr( iface )
|
|
* Change setaddr()
|
|
* to manage the i_ports field and the fds for select().
|
|
*/
|
|
+void
|
|
setaddr( iface, phase, net, node, first, last )
|
|
struct interface *iface;
|
|
- u_char phase;
|
|
- u_short net;
|
|
- u_char node;
|
|
- u_short first, last;
|
|
+ u_int8_t phase;
|
|
+ u_int16_t net;
|
|
+ u_int8_t node;
|
|
+ u_int16_t first, last;
|
|
{
|
|
int i;
|
|
struct atserv *as;
|
|
@@ -1232,7 +1241,7 @@ setaddr( iface, phase, net, node, first,
|
|
nr.nr_phase = phase;
|
|
nr.nr_firstnet = first;
|
|
nr.nr_lastnet = last;
|
|
- bcopy( &nr, iface->i_addr.sat_zero, sizeof( struct netrange ));
|
|
+ memcpy( iface->i_addr.sat_zero, &nr, sizeof( struct netrange ));
|
|
|
|
if ( ifconfig( iface->i_name, SIOCSIFADDR, &iface->i_addr )) {
|
|
syslog( LOG_ERR, "setifaddr: %s: %m", iface->i_name );
|
|
@@ -1250,7 +1259,7 @@ setaddr( iface, phase, net, node, first,
|
|
exit( 1 );
|
|
}
|
|
|
|
- bzero( &sat, sizeof( struct sockaddr_at ));
|
|
+ memset( &sat, 0, sizeof( struct sockaddr_at ));
|
|
#ifdef BSD4_4
|
|
sat.sat_len = sizeof( struct sockaddr_at );
|
|
#endif BSD4_4
|
|
@@ -1282,37 +1291,39 @@ setaddr( iface, phase, net, node, first,
|
|
return;
|
|
}
|
|
|
|
+int
|
|
ifconfig( iname, cmd, sa )
|
|
char *iname;
|
|
- long cmd;
|
|
+ int32_t cmd;
|
|
struct sockaddr_at *sa;
|
|
{
|
|
struct ifreq ifr;
|
|
int s;
|
|
|
|
- strcpy( ifr.ifr_name, iname );
|
|
+ (void)strlcpy( ifr.ifr_name, iname, sizeof( ifr.ifr_name ) );
|
|
ifr.ifr_addr = *(struct sockaddr *)sa;
|
|
|
|
if (( s = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
|
|
return( 1 );
|
|
}
|
|
if ( ioctl( s, cmd, &ifr ) < 0 ) {
|
|
+ close(s);
|
|
return( 1 );
|
|
}
|
|
- close( s );
|
|
if ( cmd == SIOCGIFADDR ) {
|
|
*(struct sockaddr *)sa = ifr.ifr_addr;
|
|
}
|
|
return( 0 );
|
|
}
|
|
|
|
+void
|
|
dumpconfig( iface )
|
|
struct interface *iface;
|
|
{
|
|
struct list *l;
|
|
|
|
printf( "%s", iface->i_name );
|
|
- if ( iface->i_flags & IFACE_SEED ) {
|
|
+ if ( iface->i_flags & IFACE_SEED ) {
|
|
printf( " -seed" );
|
|
}
|
|
printf( " -phase" );
|
|
@@ -1337,6 +1348,7 @@ dumpconfig( iface )
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
+void
|
|
dumproutes()
|
|
{
|
|
struct interface *iface;
|
|
@@ -1385,6 +1397,7 @@ dumproutes()
|
|
fflush( stdout );
|
|
}
|
|
|
|
+void
|
|
dumpzones()
|
|
{
|
|
struct interface *iface;
|