nfsd.tproj nfsiod.tproj nfsstat.tproj ping.tproj rarpd.tproj\
rcp.tproj rexecd.tproj rlogin.tproj rlogind.tproj\
route.tproj routed.tproj rpcinfo.tproj rsh.tproj rshd.tproj\
- ruptime.tproj rwho.tproj rwhod.tproj slattach.tproj\
- spray.tproj syslogd.tproj\
+ ruptime.tproj rwho.tproj rwhod.tproj slattach.tproj spray.tproj\
talk.tproj talkd.tproj telnet.tproj telnetd.tproj tftp.tproj\
tftpd.tproj traceroute.tproj trpt.tproj wall.tproj\
ypbind.tproj ypcat.tproj ypmatch.tproj yppoll.tproj\
rwhod.tproj,
slattach.tproj,
spray.tproj,
- syslogd.tproj,
talk.tproj,
talkd.tproj,
telnet.tproj,
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
When this parameter is GET_ALIAS_PORT, it indicates to get a randomly
selected port number.
*/
-
if (alias_port_param == GET_ALIAS_PORT)
{
/*
port_sys += ALIAS_PORT_BASE;
port_net = htons(port_sys);
}
-
#ifdef DEBUG
fprintf(stderr, "PacketAlias/GetnewPort(): ");
fprintf(stderr, "could not find free port\n");
free(link);
return(NULL);
}
-
/* Link-type dependent initialization */
switch(link_type)
{
}
}
+/* FindAliasPortOut */
+/* external routine for NatPortMap */
+/* return alias port for the src_addr,dst_addr,src_port and proto */
+/* if one doesn't existed, create a mapping with providing pub_port if it's not 0 */
+/* delete mapping if addmapping is not true */
+int
+FindAliasPortOut(struct in_addr src_addr, struct in_addr dst_addr, u_short src_port, u_short pub_port, u_char proto, int lifetime, char addmapping)
+{
+ u_int i;
+ struct alias_link *link;
+ int link_type;
+
+ switch (proto)
+ {
+ case IPPROTO_UDP:
+ link_type = LINK_UDP;
+ break;
+ case IPPROTO_TCP:
+ link_type = LINK_TCP;
+ break;
+ default:
+ return NULL;
+ break;
+ }
+
+#ifdef DEBUG
+ {
+ int icount;
+
+ printf("PORTMAP::srcaddr = 0x%x.%d, dstaddr = 0x%x.%d link_type = %d, lifetime = %d\n",
+ src_addr.s_addr, src_port, dst_addr.s_addr, pub_port, link_type, lifetime);
+
+ for (i=0; i<LINK_TABLE_OUT_SIZE; i++)
+ {
+ link = LIST_FIRST(&linkTableOut[i]);
+ while (link != NULL)
+ {
+ struct alias_link *link_next;
+
+ printf("PORTMAP:: linksrcaddr = 0x%x.%d, linkdstaddr = 0x%x.%d, aliasaddr=0x%x.%d, linktype = %d\n",
+ link->src_addr.s_addr,link->src_port,link->dst_addr.s_addr,link->dst_port, link->alias_addr.s_addr,link->alias_port,
+ link->link_type);
+
+ link_next = LIST_NEXT(link, list_out);
+ icount++;
+ link = link_next;
+ }
+ }
+
+ }
+#endif
+
+ i = StartPointOut(src_addr, dst_addr, src_port, 0, link_type);
+#ifdef DEBUG
+ printf("PORTMAP::StartPointOut returns %d\n", i);
+#endif
+ LIST_FOREACH(link, &linkTableOut[i], list_out)
+ {
+ if (link->src_addr.s_addr == src_addr.s_addr &&
+ link->dst_addr.s_addr == dst_addr.s_addr &&
+ link->src_port == src_port && link->link_type == link_type)
+ break;
+ }
+
+ if ( link == NULL && addmapping)
+ {
+ struct in_addr alias_addr;
+#ifdef DEBUG
+ printf("PORTMAP:: cannot find mapping, adding mapping private port =%d, public port = %d\n",src_port, pub_port);
+#endif
+ /* address/port in not in list, create new mapping */
+
+ alias_addr = FindAliasAddress(src_addr);
+ /* create new mapping */
+ if ( !pub_port )
+ pub_port = GET_ALIAS_PORT;
+ link = AddLink(src_addr, dst_addr, alias_addr,
+ src_port, 0, pub_port,
+ link_type);
+ if ( link != NULL )
+ /* link was create, set new lifetime */
+ SetExpire(link, lifetime);
+ }
+ if ( link )
+ {
+ if ( addmapping )
+ return( GetAliasPort(link));
+ else
+ {
+ SetExpire(link, 0); /* delete mapping */
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
/* External routines for getting or changing link data
(external to alias_db.c, but internal to alias*.c)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
install -c -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} arp4.0 \
${DESTDIR}${MANDIR}4/arp.0
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 arp.8 $(DSTROOT)/usr/share/man/man8/arp.8
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
sin2 = (struct sockaddr_inarp *)(rtm + 1);
- (char *)sdl = (char *)sin2 + ROUNDUP(sin2->sin_len);
+ sdl = (struct sockaddr_dl*)((char*)sin2 + ROUNDUP(sin2->sin_len));
if (addr) {
if (addr != sin2->sin_addr.s_addr)
continue;
printf(" [firewire]");
break;
default:
+ break;
}
printf("\n");
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
-/* $KAME: crypto_openssl.c,v 1.69 2001/09/11 13:25:00 sakane Exp $ */
+/* $KAME: crypto_openssl.c,v 1.73 2003/04/24 02:21:22 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
#endif
#ifdef HAVE_OPENSSL_X509_H
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/x509_vfy.h>
#endif
#include <openssl/bn.h>
*/
#ifdef HAVE_SIGNING_C
-static int cb_check_cert __P((int, X509_STORE_CTX *));
+static int cb_check_cert_local __P((int, X509_STORE_CTX *));
+static int cb_check_cert_remote __P((int, X509_STORE_CTX *));
static void eay_setgentype __P((char *, int *));
static X509 *mem2x509 __P((vchar_t *));
#endif
i = X509_NAME_cmp(a, b);
- end:
+ end:
if (a)
X509_NAME_free(a);
if (b)
* this functions is derived from apps/verify.c in OpenSSL0.9.5
*/
int
-eay_check_x509cert(cert, CApath)
+eay_check_x509cert(cert, CApath, local)
vchar_t *cert;
char *CApath;
+ int local;
{
X509_STORE *cert_ctx = NULL;
X509_LOOKUP *lookup = NULL;
cert_ctx = X509_STORE_new();
if (cert_ctx == NULL)
goto end;
- X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert);
+
+ if (local)
+ X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert_local);
+ else
+ X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert_remote);
lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());
if (lookup == NULL)
if (csc == NULL)
goto end;
X509_STORE_CTX_init(csc, cert_ctx, x509, NULL);
+
+#if OPENSSL_VERSION_NUMBER >= 0x00907000L
+ X509_STORE_CTX_set_flags(csc, X509_V_FLAG_CRL_CHECK);
+ X509_STORE_CTX_set_flags(csc, X509_V_FLAG_CRL_CHECK_ALL);
+#endif
+
error = X509_verify_cert(csc);
X509_STORE_CTX_cleanup(csc);
#else
*/
error = error ? 0 : -1;
-end:
+ end:
if (error)
printf("%s\n", eay_strerror());
if (cert_ctx != NULL)
/*
* callback function for verifing certificate.
- * this function is derived from cb() in openssl/apps/s_server.c
+ * Derived from cb() in openssl/apps/s_server.c
+ *
+ * This one is called for certificates obtained from
+ * 'peers_certfile' directive.
*/
static int
-cb_check_cert(ok, ctx)
+cb_check_cert_local(ok, ctx)
int ok;
X509_STORE_CTX *ctx;
{
if (!ok) {
X509_NAME_oneline(
- X509_get_subject_name(ctx->current_cert),
+ X509_get_subject_name(ctx->current_cert),
buf,
256);
- /*
- * since we are just checking the certificates, it is
- * ok if they are self signed. But we should still warn
- * the user.
- */
- switch (ctx->error) {
- case X509_V_ERR_CERT_HAS_EXPIRED:
- case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
+ /*
+ * since we are just checking the certificates, it is
+ * ok if they are self signed. But we should still warn
+ * the user.
+ */
+ switch (ctx->error) {
+ case X509_V_ERR_CERT_HAS_EXPIRED:
+ case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
#if OPENSSL_VERSION_NUMBER >= 0x00905100L
- case X509_V_ERR_INVALID_CA:
- case X509_V_ERR_PATH_LENGTH_EXCEEDED:
- case X509_V_ERR_INVALID_PURPOSE:
+ case X509_V_ERR_INVALID_PURPOSE:
+ case X509_V_ERR_UNABLE_TO_GET_CRL:
#endif
- ok = 1;
- log_tag = LLV_WARNING;
- break;
- default:
- log_tag = LLV_ERROR;
- }
+ ok = 1;
+ log_tag = LLV_WARNING;
+ break;
+
+ default:
+ log_tag = LLV_ERROR;
+ }
+
+
#ifndef EAYDEBUG
- plog(log_tag, LOCATION, NULL,
- "%s(%d) at depth:%d SubjectName:%s\n",
- X509_verify_cert_error_string(ctx->error),
- ctx->error,
- ctx->error_depth,
- buf);
+ plog(log_tag, LOCATION, NULL,
+ "%s(%d) at depth:%d SubjectName:%s\n",
+ X509_verify_cert_error_string(ctx->error),
+ ctx->error,
+ ctx->error_depth,
+ buf);
#else
- printf("%d: %s(%d) at depth:%d SubjectName:%s\n",
- log_tag,
- X509_verify_cert_error_string(ctx->error),
- ctx->error,
- ctx->error_depth,
- buf);
+ printf("%d: %s(%d) at depth:%d SubjectName:%s\n",
+ log_tag,
+ X509_verify_cert_error_string(ctx->error),
+ ctx->error,
+ ctx->error_depth,
+ buf);
+#endif
+ }
+ ERR_clear_error();
+
+ return ok;
+}
+
+/*
+ * Similar to cb_check_cert_local() but this one is called
+ * for certificates obtained from the IKE payload.
+ */
+static int
+cb_check_cert_remote(ok, ctx)
+ int ok;
+ X509_STORE_CTX *ctx;
+{
+ char buf[256];
+ int log_tag;
+
+ if (!ok) {
+ X509_NAME_oneline(
+ X509_get_subject_name(ctx->current_cert),
+ buf,
+ 256);
+ switch (ctx->error) {
+ case X509_V_ERR_UNABLE_TO_GET_CRL:
+ ok = 1;
+ log_tag = LLV_WARNING;
+ break;
+ default:
+ log_tag = LLV_ERROR;
+ }
+#ifndef EAYDEBUG
+ plog(log_tag, LOCATION, NULL,
+ "%s(%d) at depth:%d SubjectName:%s\n",
+ X509_verify_cert_error_string(ctx->error),
+ ctx->error,
+ ctx->error_depth,
+ buf);
+#else
+ printf("%d: %s(%d) at depth:%d SubjectName:%s\n",
+ log_tag,
+ X509_verify_cert_error_string(ctx->error),
+ ctx->error,
+ ctx->error_depth,
+ buf);
#endif
}
ERR_clear_error();
sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
goto end;
}
- strcpy(*altname, cval->value);
+ strlcpy(*altname, cval->value, len);
/* set type of the name */
eay_setgentype(cval->name, type);
{
X509 *x509;
u_char *bp;
- vchar_t pubkey;
+ EVP_PKEY *evp;
bp = cert->v;
return -1;
}
- pubkey.v = x509->cert_info->key->public_key->data;
- pubkey.l = x509->cert_info->key->public_key->length;
-
- return eay_rsa_verify(source, sig, &pubkey);
+ evp = X509_get_pubkey(x509);
+ if (!evp) {
+#ifndef EAYDEBUG
+ plog(LLV_ERROR, LOCATION, NULL, "X509_get_pubkey: %s\n", eay_strerror());
+#endif
+ return -1;
+ }
+
+ return eay_rsa_verify(source, sig, evp);
}
/*
}
int
-eay_rsa_verify(src, sig, pubkey)
- vchar_t *src, *sig, *pubkey;
-{
+eay_rsa_verify(src, sig, evp)
+ vchar_t *src, *sig;
EVP_PKEY *evp;
- u_char *bp = pubkey->v;
+{
vchar_t *xbuf = NULL;
int pad = RSA_PKCS1_PADDING;
int len = 0;
int error;
- evp = d2i_PUBKEY(NULL, &bp, pubkey->l);
- if (evp == NULL)
-#ifndef EAYDEBUG
- return NULL;
-#endif
-
len = RSA_size(evp->pkey.rsa);
xbuf = vmalloc(len);
return 448;
if (len < 40 || len > 448)
return -1;
- return len + 7 / 8;
+ return (len + 7) / 8;
}
#ifdef HAVE_OPENSSL_RC5_H
return 128;
if (len < 40 || len > 2040)
return -1;
- return len + 7 / 8;
+ return (len + 7) / 8;
}
#endif
return 128;
if (len < 40 || len > 128)
return -1;
- return len + 7 / 8;
+ return (len + 7) / 8;
}
/*
return len;
}
+int
+eay_null_keylen(len)
+ int len;
+{
+ return 0;
+}
+
/*
* HMAC functions
*/
{
HMAC_CTX *c = racoon_malloc(sizeof(*c));
+ HMAC_CTX_init(c);
HMAC_Init(c, key->v, key->l, md);
return (caddr_t)c;
HMAC_Final((HMAC_CTX *)c, res->v, &l);
res->l = l;
+ HMAC_CTX_cleanup(c);
(void)racoon_free(c);
if (SHA512_DIGEST_LENGTH != res->l) {
HMAC_Final((HMAC_CTX *)c, res->v, &l);
res->l = l;
+ HMAC_CTX_cleanup(c);
(void)racoon_free(c);
if (SHA384_DIGEST_LENGTH != res->l) {
HMAC_Final((HMAC_CTX *)c, res->v, &l);
res->l = l;
+ HMAC_CTX_cleanup(c);
(void)racoon_free(c);
if (SHA256_DIGEST_LENGTH != res->l) {
HMAC_Final((HMAC_CTX *)c, res->v, &l);
res->l = l;
+ HMAC_CTX_cleanup(c);
(void)racoon_free(c);
if (SHA_DIGEST_LENGTH != res->l) {
HMAC_Final((HMAC_CTX *)c, res->v, &l);
res->l = l;
+ HMAC_CTX_cleanup(c);
(void)racoon_free(c);
if (MD5_DIGEST_LENGTH != res->l) {
-/* $KAME: crypto_openssl.h,v 1.23 2001/08/14 12:26:06 sakane Exp $ */
+/* $KAME: crypto_openssl.h,v 1.25 2002/04/25 09:48:32 sakane Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* SUCH DAMAGE.
*/
+#ifdef HAVE_OPENSSL_EVP_H
+#include <openssl/evp.h>
+#endif
+
#ifdef HAVE_SIGNING_C
/* X509 Certificate */
#define GENT_OTHERNAME 0
extern vchar_t *eay_str2asn1dn __P((char *, int));
extern int eay_cmp_asn1dn __P((vchar_t *, vchar_t *));
-extern int eay_check_x509cert __P((vchar_t *, char *));
+extern int eay_check_x509cert __P((vchar_t *, char *, int));
extern vchar_t *eay_get_x509asn1subjectname __P((vchar_t *));
extern int eay_get_x509subjectaltname __P((vchar_t *, char **, int *, int));
extern char *eay_get_x509text __P((vchar_t *));
/* RSA */
extern vchar_t *eay_rsa_sign __P((vchar_t *, vchar_t *));
-extern int eay_rsa_verify __P((vchar_t *, vchar_t *, vchar_t *));
+extern int eay_rsa_verify __P((vchar_t *, vchar_t *, EVP_PKEY *));
/* ASN.1 */
extern vchar_t *eay_get_pkcs1privkey __P((char *));
extern int eay_aes_keylen __P((int));
/* misc */
+extern int eay_null_keylen __P((int));
extern int eay_null_hashlen __P((void));
extern int eay_kpdk_hashlen __P((void));
extern int eay_twofish_keylen __P((int));
}
}
- error = eay_check_x509cert(&c, certpath);
+ error = eay_check_x509cert(&c, certpath, 1);
if (error)
printf("ERROR: cert is invalid.\n");
printf("\n");
HFILES = ifconfig.h
-CFILES = ifconfig.c ifmedia.c ifvlan.c
+CFILES = ifconfig.c ifmedia.c ifvlan.c ifbond.c
OTHERSRCS = Makefile.preamble Makefile Makefile.dist ifconfig.8\
Makefile.postamble
OTHER_GENERATED_OFILES = $(VERS_OFILE)
-include ../Makefile.include
-OTHER_CFLAGS += -DUSE_IF_MEDIA -DINET6 -DNO_IPX -DUSE_VLANS
+OTHER_CFLAGS += -DUSE_IF_MEDIA -DINET6 -DNO_IPX -DUSE_VLANS -DUSE_BONDS
H_FILES = (ifconfig.h);
M_FILES = ();
OTHER_LIBS = ();
- OTHER_LINKED = (ifconfig.c, ifmedia.c, ifvlan.c);
+ OTHER_LINKED = (ifconfig.c, ifmedia.c, ifvlan.c, ifbond.c);
OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.dist, ifconfig.8, Makefile.postamble);
PRECOMPILED_HEADERS = ();
PROJECT_HEADERS = ();
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * ifbond.c
+ * - add and remove interfaces from a bond interface
+ */
+
+/*
+ * Modification History:
+ *
+ * July 14, 2004 Dieter Siegmund (dieter@apple.com)
+ * - created
+ */
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_bond_var.h>
+
+#include <net/route.h>
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include <errno.h>
+
+#include "ifconfig.h"
+extern int bond_details;
+
+#define EA_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x"
+#define EA_CH(e, i) ((u_char)((u_char *)(e))[(i)])
+#define EA_LIST(ea) EA_CH(ea,0),EA_CH(ea,1),EA_CH(ea,2),EA_CH(ea,3),EA_CH(ea,4),EA_CH(ea,5)
+
+static __inline__ const char *
+selected_state_string(u_char s)
+{
+ static const char * names[] = { "unselected", "selected", "standby" };
+
+ if (s <= IF_BOND_STATUS_SELECTED_STATE_STANDBY) {
+ return (names[s]);
+ }
+ return ("<unknown>");
+}
+
+static void
+bond_print_details(struct if_bond_status * ibs_p, int count)
+
+{
+ int i;
+ struct if_bond_status * scan_p = ibs_p;
+
+ for (i = 0; i < count; i++, scan_p++) {
+ struct if_bond_partner_state * ps;
+ ps = &scan_p->ibs_partner_state;
+ printf("\tbond interface: %s priority: 0x%04x "
+ "state: 0x%02x partner system: 0x%04x,"
+ EA_FORMAT " "
+ "key: 0x%04x port: 0x%04x priority: 0x%04x "
+ "state: 0x%02x\n",
+ scan_p->ibs_if_name, scan_p->ibs_port_priority,
+ scan_p->ibs_state, ps->ibps_system_priority,
+ EA_LIST(&ps->ibps_system), ps->ibps_key,
+ ps->ibps_port, ps->ibps_port_priority,
+ ps->ibps_state);
+ }
+ return;
+}
+
+void
+bond_status(int s, struct rt_addrinfo * info __unused)
+{
+ int i;
+ struct if_bond_req ibr;
+ struct if_bond_status * ibs_p;
+ struct if_bond_status_req * ibsr_p;
+
+ bzero((char *)&ibr, sizeof(ibr));
+ ibr.ibr_op = IF_BOND_OP_GET_STATUS;
+ ibsr_p = &ibr.ibr_ibru.ibru_status;
+ ibsr_p->ibsr_version = IF_BOND_STATUS_REQ_VERSION;
+ ifr.ifr_data = (caddr_t)&ibr;
+
+ /* how many of them are there? */
+ if (ioctl(s, SIOCGIFBOND, (caddr_t)&ifr) < 0) {
+ return;
+ }
+ if (ibsr_p->ibsr_total == 0) {
+ if (bond_details) {
+ printf("\tbond key: 0x%04x interfaces: <none>\n",
+ ibsr_p->ibsr_key);
+ }
+ else {
+ printf("\tbond interfaces: <none>\n");
+ }
+ return;
+ }
+ ibsr_p->ibsr_buffer
+ = (char *)malloc(sizeof(struct if_bond_status)
+ * ibsr_p->ibsr_total);
+ ibsr_p->ibsr_count = ibsr_p->ibsr_total;
+
+ /* get the list */
+ if (ioctl(s, SIOCGIFBOND, (caddr_t)&ifr) < 0) {
+ goto done;
+ }
+ if (ibsr_p->ibsr_total > 0) {
+ if (bond_details) {
+ printf("\tbond key: 0x%04x interfaces:",
+ ibsr_p->ibsr_key);
+ }
+ else {
+ printf("\tbond interfaces:");
+ }
+ ibs_p = (struct if_bond_status *)ibsr_p->ibsr_buffer;
+ for (i = 0; i < ibsr_p->ibsr_total; i++, ibs_p++) {
+ printf(" %s", ibs_p->ibs_if_name);
+ if (bond_details) {
+ u_char s = ibs_p->ibs_selected_state;
+ printf(" (%s)", selected_state_string(s));
+ }
+ }
+ printf("\n");
+ if (bond_details) {
+ bond_print_details((struct if_bond_status *)
+ ibsr_p->ibsr_buffer,
+ ibsr_p->ibsr_total);
+ }
+ }
+ else if (bond_details) {
+ printf("\tbond key: 0x%04x interfaces: <none>\n",
+ ibsr_p->ibsr_key);
+ }
+ else {
+ printf("\tbond interfaces: <none>\n");
+ }
+
+ done:
+ free(ibsr_p->ibsr_buffer);
+ return;
+}
+
+void
+setbonddev(const char *val, int d, int s, const struct afswtch * afp)
+{
+ struct if_bond_req ibr;
+
+ bzero((char *)&ibr, sizeof(ibr));
+ if ((unsigned int)snprintf(ibr.ibr_ibru.ibru_if_name,
+ sizeof(ibr.ibr_ibru.ibru_if_name),
+ "%s", val) >= IFNAMSIZ) {
+ errx(1, "interface name too long");
+ }
+ ibr.ibr_op = IF_BOND_OP_ADD_INTERFACE;
+ ifr.ifr_data = (caddr_t)&ibr;
+ if (ioctl(s, SIOCSIFBOND, (caddr_t)&ifr) == -1)
+ err(1, "SIOCSIFBOND add interface");
+
+ return;
+}
+
+void
+unsetbonddev(const char *val, int d, int s, const struct afswtch * afp)
+{
+ struct if_bond_req ibr;
+
+ bzero((char *)&ibr, sizeof(ibr));
+ if ((unsigned int)snprintf(ibr.ibr_ibru.ibru_if_name,
+ sizeof(ibr.ibr_ibru.ibru_if_name),
+ "%s", val) >= IFNAMSIZ) {
+ errx(1, "interface name too long");
+ }
+ ibr.ibr_op = IF_BOND_OP_REMOVE_INTERFACE;
+ ifr.ifr_data = (caddr_t)&ibr;
+ if (ioctl(s, SIOCSIFBOND, (caddr_t)&ifr) == -1)
+ err(1, "SIOCSIFBOND remove interface");
+
+ return;
+}
+
.\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94
.\" $FreeBSD: src/sbin/ifconfig/ifconfig.8,v 1.27.2.14 2001/08/23 06:35:38 yar Exp $
.\"
-.Dd July 2, 2001
+.Dd July 15, 2004
.Dt IFCONFIG 8
.Os
.Sh NAME
.Op Ar address_family
.Nm
.Op Fl L
+.Op Fl b
.Op Fl d
.Op Fl m
.Op Fl u
+.Nm
+.Ar interface
+.Cm vlan
+.Ar vlan-tag
+.Cm vlandev
+.Ar iface
+.Nm
+.Ar interface
+.Cm -vlandev
+.Ar iface
+.Nm
+.Ar interface
+.Cm bonddev
+.Ar iface
+.Nm
+.Ar interface
+.Cm -bonddev
+.Ar iface
.Sh DESCRIPTION
.Nm Ifconfig
is used to assign an address
.Dq name unit ,
for example,
.Dq Li en0 .
+.It Ar iface
+This parameter has the same encoding as the
+.Ar interface
+parameter.
.El
.Pp
The following parameters may be set with
.It Fl arp
Disable the use of the Address Resolution Protocol
.Pq Xr arp 4 .
+.It Cm bonddev Ar iface
+If the interface is a bond pseudo device, associate physical interface
+.Ar iface
+with it. The bond pseudo device conforms
+to the IEEE 802.3ad Link Aggregation specification.
+.Pp
+If this is the first physical interface to be associated with the bond
+interface, the bond interface inherits the ethernet address from the
+physical interface. Physical interfaces that are added to the bond have
+their ethernet address re-programmed so that all members of the bond have
+the same ethernet address. If the physical interface is subsequently
+removed from the bond using
+.Fl bonddev ,
+a new ethernet address is chosen from the remaining interfaces, and all
+interfaces are re-programmed again with the new ethernet address. If no
+remaining interfaces exist, the bond interface's ethernet address is cleared.
+.Pp
+If the specified physical interface
+.Ar iface
+is not capable of having its ethernet address re-programmed, the
+.Cm bonddev
+command will fail.
+.Pp
+Once the physical interface
+.Ar iface
+is successfully associated with the bond interface, all received packets
+are diverted to the bond interface. The physical interface is no longer
+useable on its own, and remains that way until it is removed from the bond using
+.Fl bonddev .
+.Pp
+It is possible that the specified interface
+.Ar iface
+is not capable of aggregating, and may remain unused until the operating
+conditions change.
+.Pp
+The link status of the bond interface depends on the state of link aggregation.
+If no active partner is detected, the link status will remain inactive.
+.Pp
+To monitor the 802.3ad Link Aggregation state, use the
+.Fl b
+option.
+.Pp
+A physical interface that is associated with a vlan pseudo device cannot
+at the same time be associated with a bond pseudo device. A physical interface
+cannot be associated with more than one bond pseudo device at the same time.
+.Pp
+It is not possible to associate a bond with pseudo interfaces such as vlan.
+Only physical ethernet interfaces may be associated with a bond.
+.It Fl bonddev Ar iface
+If the interface is a bond pseudo device, disassociate the physical interface
+.Ar iface
+from it. Before the interface is removed from the bond, the bond device
+announces to the link partner that the interface is now individual and
+no longer aggregatable.
+If the physical
+.Ar iface
+is the last interface in the bond, the bond interface clears its link address.
.It Cm broadcast
(Inet only.)
Specify the address to use to represent broadcasts to the
Included for
.Tn Solaris
compatibility.
-.It Cm vlan Ar vlan_tag
-If the interface is a vlan pseudo interface, set the vlan tag value
-to
-.Ar vlan_tag .
-This value is a 16-bit number which is used to create an 802.1Q
-vlan header for packets sent from the vlan interface.
-Note that
-.Cm vlan
-and
-.Cm vlandev
-must both be set at the same time.
-.It Cm vlandev Ar iface
-If the interface is a vlan pseudo device, associate physical interface
-.Ar iface
-with it.
-Packets transmitted through the vlan interface will be
-diverted to the specified physical interface
-.Ar iface
-with 802.1Q vlan encapsulation.
-Packets with 802.1Q encapsulation received
-by the parent interface with the correct vlan tag will be diverted to
-the associated vlan pseudo-interface.
-The vlan interface is assigned a
-copy of the parent interface's flags and the parent's ethernet address.
-The
-.Cm vlandev
-and
-.Cm vlan
-must both be set at the same time.
-If the vlan interface already has
-a physical interface associated with it, this command will fail.
-To
-change the association to another physical interface, the existing
-association must be cleared first.
-.Pp
-Note: if the hardware tagging capability
-is set on the vlan interface, the vlan pseudo
-interface's behavior changes:
-the vlan interface recognizes that the
-parent interface supports insertion and extraction of vlan tags on its
-own (usually in firmware) and that it should pass packets to and from
-the parent unaltered.
-.It Fl vlandev Ar iface
-If the driver is a vlan pseudo device, disassociate the physical interface
-.Ar iface
-from it.
-This breaks the link between the vlan interface and its parent,
-clears its vlan tag, flags and its link address and shuts the interface down.
.It Cm metric Ar n
Set the routing metric of the interface to
.Ar n ,
It happens automatically when setting the first address on an interface.
If the interface was reset when previously marked down,
the hardware will be re-initialized.
+.It Cm vlan Ar vlan_tag Cm vlandev Ar iface
+If the interface is a vlan pseudo interface, set its vlan tag value
+to
+.Ar vlan_tag
+and associate it with the physical interface
+.Ar iface .
+.Pp
+The
+.Ar vlan_tag
+value is a 16-bit number that is used to create an 802.1Q
+vlan header for packets sent from the vlan interface.
+.Pp
+A packet that is transmitted through the vlan interface is sent
+using the specified physical interface
+.Ar iface
+with 802.1Q vlan encapsulation with the specified
+.Ar vlan_tag .
+A packet with 802.1Q encapsulation received by the physical interface
+is directed to the associated vlan interface with the matching
+.Ar vlan_tag .
+If there is no matching vlan interface, the packet is dropped.
+.Pp
+The vlan interface is assigned a
+copy of the parent interface's flags and the parent's ethernet address.
+If the vlan interface already has
+a physical interface associated with it, this command will fail.
+To
+change the association to another physical interface, the existing
+association must be cleared first using
+.Fl vlandev .
+.Pp
+If the physical interface supports 802.1Q VLAN tagging in hardware,
+the vlan pseudo interface does not itself insert or remove the 802.1Q
+encapsulation header. Instead, the
+.Ar vlan_tag
+is passed out of band from the packet data.
+.Pp
+A physical interface that is associated with a bond pseudo device cannot
+at the same time be associated with a vlan interface. However, a physical
+interface can be associated with multiple vlan interfaces at the same time,
+as long as each of the
+.Ar vlan_tag
+values are unique.
+.It Fl vlandev Ar iface
+If the driver is a vlan pseudo device, disassociate the physical interface
+.Ar iface
+from it.
+This breaks the link between the vlan interface and its parent,
+clears its vlan tag, flags and its link address.
.El
.Pp
.Nm Ifconfig
.Nm
will report only the details specific to that protocol family.
.Pp
-If the driver does supports the media selection system, the supported
-media list will be included in the output.
-.Pp
-If the
+If the driver supports the media selection system, the supported
+media list will be included in the output, regardless of whether the
.Fl m
-flag is passed before an interface name,
-.Nm
-will display all
-of the supported media for the specified interface.
+flag is passed or not.
+.Pp
+The
+.Fl b
+option passed before the interface name will print the link aggregation
+state for bond pseudo devices.
+.Pp
If
.Fl L
flag is supplied, address lifetime is displayed for IPv6 addresses,
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#endif
static const char rcsid[] =
- "$Id: ifconfig.c,v 1.6 2003/12/16 23:16:58 lindak Exp $";
+ "$Id: ifconfig.c,v 1.8 2004/08/26 23:55:21 lindak Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <string.h>
#include <unistd.h>
-struct ether_addr *ether_aton __P((const char *));
#include "ifconfig.h"
struct afswtch;
+int bond_details = 0;
int supmedia = 0;
int listcloners = 0;
{ "vlandev", NEXTARG, setvlandev },
{ "-vlandev", NEXTARG, unsetvlandev },
#endif
+#ifdef USE_BONDS
+ { "bonddev", NEXTARG, setbonddev },
+ { "-bonddev", NEXTARG, unsetbonddev },
+#endif
#if 0
/* XXX `create' special-cased below */
{"create", 0, clone_create },
#ifdef USE_VLANS
{ "vlan", AF_UNSPEC, vlan_status, NULL, NULL, }, /* XXX not real!! */
#endif
+#ifdef USE_BONDS
+ { "bond", AF_UNSPEC, bond_status, NULL, NULL, }, /* XXX not real!! */
+#endif
#ifdef USE_IEEE80211
{ "ieee80211", AF_UNSPEC, ieee80211_status, NULL, NULL, }, /* XXX not real!! */
#endif
/* Parse leading line options */
all = downonly = uponly = namesonly = 0;
- while ((c = getopt(argc, argv, "adlmu"
+ while ((c = getopt(argc, argv, "abdlmu"
#ifdef INET6
"L"
#endif
case 'a': /* scan all interfaces */
all++;
break;
+ case 'b': /* bond detailed output */
+ bond_details++;
+ break;
case 'd': /* restrict scan to "down" interfaces */
downonly++;
break;
argc -= optind;
argv += optind;
- /* -l cannot be used with -a or -m */
- if (namesonly && (all || supmedia))
+ /* -l cannot be used with -a or -m or -b */
+ if (namesonly && (all || supmedia || bond_details))
usage();
/* nonsense.. */
if (afp->af_ridreq == NULL || afp->af_difaddr == 0) {
warnx("interface %s cannot change %s addresses!",
name, afp->af_name);
- clearaddr = NULL;
+ clearaddr = 0;
}
}
if (clearaddr) {
if (afp->af_addreq == NULL || afp->af_aifaddr == 0) {
warnx("interface %s cannot change %s addresses!",
name, afp->af_name);
- newaddr = NULL;
+ newaddr = 0;
}
}
if (newaddr && (setaddr || setmask)) {
if (allfamilies || afp->af_status == vlan_status)
vlan_status(s, NULL);
#endif
+#ifdef USE_BONDS
+ if (allfamilies || afp->af_status == bond_status)
+ bond_status(s, NULL);
+#endif
#ifdef USE_IEEE80211
if (allfamilies || afp->af_status == ieee80211_status)
ieee80211_status(s, NULL);
*
* so there!
*
- * $Id: ifconfig.h,v 1.2 2003/12/16 23:16:58 lindak Exp $
+ * $Id: ifconfig.h,v 1.3 2004/07/20 05:29:46 lindak Exp $
*/
extern struct ifreq ifr;
extern void unsetvlandev(const char *, int, int, const struct afswtch *rafp);
extern void vlan_status(int s, struct rt_addrinfo *);
+extern void setbonddev(const char *, int, int,const struct afswtch * rafp);
+extern void unsetbonddev(const char *, int, int, const struct afswtch * rafp);
+extern void bond_status(int s, struct rt_addrinfo *);
static int lookup_media_word __P((struct ifmedia_description *, const char *));
static void print_media_word __P((int));
+extern int supmedia;
+
void
media_status(s, info)
int s;
return;
}
- media_list = (int *)malloc(ifmr.ifm_count * sizeof(int));
- if (media_list == NULL)
- err(1, "malloc");
- ifmr.ifm_ulist = media_list;
-
- if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
- err(1, "SIOCGIFMEDIA");
-
printf("\tmedia: ");
print_media_word(ifmr.ifm_current);
if (ifmr.ifm_active != ifmr.ifm_current) {
else
printf("inactive");
}
-
putchar('\n');
+#if 0
+ if (supmedia == 0) {
+ return;
+ }
+#endif 0
+ media_list = (int *)malloc(ifmr.ifm_count * sizeof(int));
+ if (media_list == NULL)
+ err(1, "malloc");
+ ifmr.ifm_ulist = media_list;
+
+ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
+ err(1, "SIOCGIFMEDIA");
+
if (ifmr.ifm_count > 0) {
printf("\tsupported media:");
for (i = 0; i < ifmr.ifm_count; i++) {
*
* @APPLE_LICENSE_HEADER_START@
*
-* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
-*
-* This file contains Original Code and/or Modifications of Original Code
-* as defined in and that are subject to the Apple Public Source License
-* Version 2.0 (the 'License'). You may not use this file except in
-* compliance with the License. Please obtain a copy of the License at
-* http://www.opensource.apple.com/apsl/ and read it before using this
-* file.
+* "Portions Copyright (c) 2002 Apple Computer, Inc. All Rights
+* Reserved. This file contains Original Code and/or Modifications of
+* Original Code as defined in and that are subject to the Apple Public
+* Source License Version 1.0 (the 'License'). You may not use this file
+* except in compliance with the License. Please obtain a copy of the
+* License at http://www.apple.com/publicsource and read it before using
+* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
-* Please see the License for the specific language governing rights and
-* limitations under the License.
+* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+* License for the specific language governing rights and limitations
+* under the License."
*
* @APPLE_LICENSE_HEADER_END@
*
PROF_LIBS = $(LIBS)
+HEADER_PATHS =\
+ -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/
NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
{ NULL, 0 }
};
+static struct _s_x exception_types[] = {
+ { "to", 1},
+ { "dst", 2},
+ { "in", 3},
+ { "out", 4},
+ { "xmit", 5},
+ { "recv", 6},
+ { "via", 7},
+ { "src", 8},
+ { NULL, 0}
+};
+
static void show_usage(void);
enum tokens {
buf[i++] = *p;
buf[i++] = '\0';
+ if ( match_token( exception_types, buf) != -1 ){
+ free(buf);
+ return 0;
+ }
+
if (proto == IPPROTO_ETHERTYPE) {
i = match_token(ether_types, buf);
free(buf);
#include <sys/param.h>
#include <sys/socket.h>
-#include <netkey/key_var.h>
#include <netinet/in.h>
#include <netinet6/ipsec.h>
#include <sys/socket.h>
#include <net/route.h>
#include <net/pfkeyv2.h>
-#include <netkey/keydb.h>
#include <netinet/in.h>
#include <netinet6/ipsec.h>
# derived files should go.
VPATH += :../kdumpd.tproj
+
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man8
+ install -c -m 644 kdumpd.8 $(DSTROOT)/usr/share/man/man8/kdumpd.8
OTHER_OFILES =
-include ../Makefile.include
+
+AFTER_INSTALL = after_install
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
#
# Note: on MS Windows, executables, have an extension, so rules and dependencies
# for generated tools should use $(EXECUTABLE_EXT) on the end.
+
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 logger.1 $(DSTROOT)/usr/share/man/man1/logger.1
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
.\" manual page [] for natd 1.4
-.\" $Id: natd.8,v 1.5 2003/02/07 01:19:25 mscopp Exp $
+.\" $Id: natd.8,v 1.6 2004/10/21 21:48:41 vazquez Exp $
.Dd June 27, 2000
.Os Darwin
.Dt NATD 8
.Xr divert 4
sockets under
.Fx .
-It is intended for use with NICs - if you want to do NAT on a PPP link,
-use the
-.Fl nat
-switch to
-.Xr ppp 8 .
.Pp
The
.Nm
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <sys/types.h>
#include <sys/socket.h>
+#include <net/if.h>
+#include <ifaddrs.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
+#include <mach/mach_time.h>
+#include <mach/clock_types.h>
#include "natd.h"
static int logDropped;
static int logFacility;
+#define NATPORTMAP 1
+
+#ifdef NATPORTMAP
+#define NATPMPORT 5351
+
+#define NATPMVERSION 0
+#define PUBLICADDRREQ 0
+#define MAPUDPREQ 1
+#define MAPTCPREQ 2
+#define MAPUDPTCPREQ 3
+#define SERVERREPLYOP 128
+#define PUBLICADDRRLY SERVERREPLYOP+PUBLICADDRREQ
+
+#define SUCCESS 0
+#define NOTSUPPORTEDVERSION 1
+#define NOTAUTHORIZED 2
+#define NETWORKFAILURE 3
+#define OUTOFRESOURCES 4
+#define UNSUPPORTEDOPCODE 5
+#define MAXRETRY 10
+#define TIMER_RATE 250
+
+#define FAILED -1
+
+typedef struct stdportmaprequest{
+ char version;
+ unsigned char opcode;
+ unsigned short result;
+ unsigned int epoch;
+ char data[4];
+ }stdportmaprequest;
+
+typedef struct publicaddrreply{
+ char version;
+ unsigned char opcode;
+ unsigned short result;
+ unsigned int epoch;
+ struct in_addr addr;
+ }publicaddrreply;
+typedef struct publicportreq{
+ char version;
+ unsigned char opcode;
+ unsigned short result;
+ unsigned int epoch;
+ unsigned short privateport;
+ unsigned short publicport;
+ int lifetime; /* in second */
+ }publicportreq;
+typedef struct stderrreply{
+ char version;
+ unsigned char opcode;
+ unsigned short result;
+ unsigned int epoch;
+ }stderrreply;
+
+
+static int enable_natportmap = 0;
+static struct in_addr lastassignaliasAddr;
+static int portmapSock = -1;
+static struct in_addr *forwardedinterfaceaddr;
+static char **forwardedinterfacename;
+static int numofinterfaces = 0; /* has to be at least one */
+static u_short natPMPport;
+static int numoftries=MAXRETRY;
+static struct itimerval itval;
+static int Natdtimerset = 0;
+static double secdivisor;
+
+
+static void HandlePortMap( int fd );
+static void SendPortMapResponse( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, unsigned char origopcode, unsigned short result);
+static void SendPublicAddress( int fd, struct sockaddr_in *clientaddr, int clientaddrlen );
+static void SendPublicPortResponse( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, publicportreq *reply, int publicport);
+static void Doubletime( struct timeval *tvp);
+static void Stoptimer();
+static void Natdtimer();
+static void SendPortMapMulti( );
+static void NotifyPublicAddress();
+static void DoPortMapping( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, publicportreq *req);
+static void NatPortMapPInit();
+static u_short get_natportmap_port(void);
+
+extern int FindAliasPortOut(struct in_addr src_addr, struct in_addr dst_addr, u_short src_port, u_short pub_port, u_char proto, int lifetime, char addmapping);
+
+#endif
+
int main (int argc, char** argv)
{
int divertIn;
running = 1;
assignAliasAddr = 0;
aliasAddr.s_addr = INADDR_NONE;
+#ifdef NATPORTMAP
+ lastassignaliasAddr.s_addr = INADDR_NONE;
+#endif
aliasOverhead = 12;
dynamicMode = 0;
logDropped = 0;
assignAliasAddr = 1;
}
- else
+ else{
SetAliasAddressFromIfName (ifName);
+ }
}
/*
* Create socket for sending ICMP messages.
*/
shutdown(icmpSock, SHUT_RD);
+
+#if NATPORTMAP
+ if ( enable_natportmap )
+ {
+ /* create socket to listen for port mapping */
+ portmapSock = socket( AF_INET, SOCK_DGRAM, 0);
+ if ( portmapSock != -1 )
+ {
+ natPMPport = get_natportmap_port();
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = INADDR_ANY;
+ addr.sin_port = NATPMPORT;
+
+ if (bind ( portmapSock,
+ (struct sockaddr*) &addr,
+ sizeof addr) == -1)
+ printf("Binding to NATPM port failed!\n");
+
+ /* NATPORTMAPP initial set up */
+ NatPortMapPInit();
+ }
+ if ( !Natdtimerset ){
+ Natdtimerset = 1;
+ signal(SIGALRM, Natdtimer);
+ }
+ }
+#endif
/*
* Become a daemon unless verbose mode was requested.
*/
* Set alias address if it has been given.
*/
if (aliasAddr.s_addr != INADDR_NONE)
+ {
PacketAliasSetAddress (aliasAddr);
+#ifdef NATPORTMAP
+ if ( (enable_natportmap) && (aliasAddr.s_addr != lastassignaliasAddr.s_addr) ){
+ lastassignaliasAddr.s_addr = aliasAddr.s_addr;
+ NotifyPublicAddress();
+ }
+#endif
+ }
/*
* We need largest descriptor number for select.
*/
if (routeSock > fdMax)
fdMax = routeSock;
+#ifdef NATPORTMAP
+ if ( portmapSock > fdMax )
+ fdMax = portmapSock;
+
+#endif
+
while (running) {
if (divertInOut != -1 && !ifName && packetSock == -1) {
*/
if (routeSock != -1)
FD_SET (routeSock, &readMask);
-
+#ifdef NATPORTMAP
+ if ( portmapSock != -1 )
+ FD_SET (portmapSock, &readMask);
+#endif
if (select (fdMax + 1,
&readMask,
&writeMask,
if (routeSock != -1)
if (FD_ISSET (routeSock, &readMask))
HandleRoutingInfo (routeSock);
+#ifdef NATPORTMAP
+ if ( portmapSock != -1)
+ if (FD_ISSET (portmapSock, &readMask))
+ HandlePortMap( portmapSock );
+#endif
}
if (background)
}
}
+#ifdef NATPORTMAP
+
+void getdivisor()
+{
+ struct mach_timebase_info info;
+
+ (void) mach_timebase_info (&info);
+
+ secdivisor = ( (double)info.denom / (double)info.numer) * 1000;
+
+}
+
+unsigned int getuptime()
+{
+ uint64_t now;
+ unsigned long epochtime;
+
+ now = mach_absolute_time();
+ epochtime = (now / secdivisor) /USEC_PER_SEC;
+ return( epochtime );
+
+}
+
+/* return NATPORTMAP port defined in /etc/servcies if there's one, else use NATPMPORT */
+static u_short get_natportmap_port(void)
+{
+ struct servent *ent;
+
+ ent = getservbyname( "natportmap", "udp" );
+ if (ent != NULL){
+ return( ent->s_port );
+ }
+ return( NATPMPORT );
+}
+
+/* set up neccessary info for doing NatPortMapP */
+static void NatPortMapPInit()
+{
+ int i;
+ struct ifaddrs *ifap, *ifa;
+
+ forwardedinterfaceaddr = (struct in_addr *)
+ malloc(numofinterfaces * sizeof(*forwardedinterfaceaddr));
+ bzero(forwardedinterfaceaddr,
+ numofinterfaces * sizeof(*forwardedinterfaceaddr));
+ /* interface address hasn't been set up, get interface address */
+ getifaddrs(&ifap);
+ for ( ifa= ifap; ifa; ifa=ifa->ifa_next)
+ {
+ struct sockaddr_in * a;
+ if (ifa->ifa_addr->sa_family != AF_INET)
+ {
+ continue;
+ }
+ a = (struct sockaddr_in *)ifa->ifa_addr;
+ for ( i = 0; i < numofinterfaces; i++ )
+ {
+ if (strcmp(ifa->ifa_name, forwardedinterfacename[i]))
+ {
+ continue;
+ }
+ if (forwardedinterfaceaddr[i].s_addr == 0)
+ {
+ /* copy the first IP address */
+ forwardedinterfaceaddr[i] = a->sin_addr;
+ }
+ break;
+ }
+ }
+ freeifaddrs( ifap );
+ getdivisor();
+}
+
+/* SendPortMapResponse */
+/* send generic reponses to NATPORTMAP requests */
+static void SendPortMapResponse( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, unsigned char origopcode, unsigned short result)
+{
+ stderrreply reply;
+ int bytes;
+
+ reply.version = NATPMVERSION;
+ reply.opcode = origopcode + SERVERREPLYOP;
+ reply.result = result;
+ reply.epoch = getuptime();
+ bytes = sendto( fd, (void*)&reply, sizeof(reply), 0, (struct sockaddr*)clientaddr, clientaddrlen );
+ if ( bytes != sizeof(reply) )
+ printf( "PORTMAP::problem sending portmap reply - opcode %d\n", reply.opcode );
+}
+
+/* SendPublicAddress */
+/* return public address to requestor */
+static void SendPublicAddress( int fd, struct sockaddr_in *clientaddr, int clientaddrlen )
+{
+
+ publicaddrreply reply;
+ int bytes;
+
+ reply.version = NATPMVERSION;
+ reply.opcode = SERVERREPLYOP + PUBLICADDRREQ;
+ reply.result = SUCCESS;
+ reply.addr = lastassignaliasAddr;
+ reply.epoch = getuptime();
+
+ bytes = sendto (fd, (void*)&reply, sizeof(reply), 0, (struct sockaddr*)clientaddr, clientaddrlen);
+ if ( bytes != sizeof(reply) )
+ printf( "PORTMAP::problem sending portmap reply - opcode %d\n", reply.opcode );
+}
+
+/* SendPublicPortResponse */
+/* response for portmap request and portmap removal request */
+/* publicport <= 0 means error */
+static void SendPublicPortResponse( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, publicportreq *reply, int publicport)
+{
+
+ int bytes;
+
+ reply->version = NATPMVERSION;
+ reply->opcode = SERVERREPLYOP + reply->opcode;
+ if ( publicport <= 0)
+ /* error in port mapping */
+ reply->result = OUTOFRESOURCES;
+ else
+ reply->result = SUCCESS;
+ reply->epoch = getuptime();
+
+ if ( reply->lifetime ) /* not delete mapping */
+ reply->publicport = publicport;
+ bytes = sendto (fd, (void*)reply, sizeof(publicportreq), 0, (struct sockaddr*)clientaddr, clientaddrlen);
+ if ( bytes != sizeof(publicportreq) )
+ printf( "PORTMAP::problem sending portmap reply - opcode %d\n", reply->opcode );
+}
+
+/* SendPortMapMulti */
+/* send multicast to local network for new alias address */
+static void SendPortMapMulti()
+{
+
+ publicaddrreply reply;
+ int bytes;
+ struct sockaddr_in multiaddr;
+ int multisock;
+ int i;
+
+#define LOCALGROUP "224.0.0.1"
+ numoftries++;
+ memset(&multiaddr,0,sizeof(struct sockaddr_in));
+ multiaddr.sin_family=AF_INET;
+ multiaddr.sin_addr.s_addr=inet_addr(LOCALGROUP);
+ multiaddr.sin_port=htons(NATPMPORT);
+ reply.version = NATPMVERSION;
+ reply.opcode = SERVERREPLYOP + PUBLICADDRREQ;
+ reply.result = SUCCESS;
+ reply.addr = lastassignaliasAddr;
+ reply.epoch = 0;
+
+ /* send multicast to all forwarded interfaces */
+ for ( i = 0; i < numofinterfaces; i++)
+ {
+ if (forwardedinterfaceaddr[i].s_addr == 0)
+ {
+ continue;
+ }
+ multisock = socket( AF_INET, SOCK_DGRAM, 0);
+
+ if ( multisock == -1 )
+ {
+ printf("cannot get socket for sending multicast\n");
+ return;
+ }
+ if (setsockopt(multisock, IPPROTO_IP, IP_MULTICAST_IF, &forwardedinterfaceaddr[i], sizeof(struct in_addr)) < 0)
+ {
+ printf("setsockopt failed\n");
+ close(multisock);
+ continue;
+ }
+ bytes = sendto (multisock, (void*)&reply, sizeof(reply), 0, (struct sockaddr*)&multiaddr, sizeof(multiaddr));
+ if ( bytes != sizeof(reply) )
+ printf( "PORTMAP::problem sending multicast alias address - opcode %d\n", reply.opcode );
+ close(multisock);
+ }
+
+}
+
+/* double the time value */
+static void Doubletime( struct timeval *tvp)
+{
+
+ if ( tvp->tv_sec )
+ tvp->tv_sec *= 2;
+ if ( tvp->tv_usec )
+ tvp->tv_usec *= 2;
+ if (tvp->tv_usec >= 1000000) {
+ tvp->tv_sec += tvp->tv_usec / 1000000;
+ tvp->tv_usec = tvp->tv_usec % 1000000;
+ }
+}
+
+/* stop running natd timer */
+static void Stoptimer()
+{
+ itval.it_value.tv_usec = 0;
+ if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0)
+ printf( "setitimer err: %d\n", errno);
+}
+
+/* natdtimer */
+/* timer routine to send new public IP address */
+static void Natdtimer()
+{
+ if ( !enable_natportmap )
+ return;
+
+ SendPortMapMulti();
+
+ if ( numoftries < MAXRETRY ){
+ Doubletime( &itval.it_value);
+ itval.it_interval = itval.it_value;
+ if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0)
+ printf( "setitimer err: %d\n", errno);
+ }
+ else
+ {
+ Stoptimer();
+ return;
+ }
+
+}
+
+/* NotifyPublicAddress */
+/* Advertise new public address */
+static void NotifyPublicAddress()
+{
+ if ( numoftries < MAXRETRY)
+ {
+ /* there is an old timer running, cancel it */
+ Stoptimer();
+ }
+ /* send up new timer */
+ numoftries = 0;
+ SendPortMapMulti();
+ itval.it_value.tv_sec = 0;
+ itval.it_value.tv_usec = TIMER_RATE;
+ itval.it_interval.tv_sec = 0;
+ itval.it_interval.tv_usec = TIMER_RATE;
+ if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0)
+ printf( "setitimer err: %d\n", errno);
+
+}
+
+/* DoPortMapping */
+/* find/add/remove port mapping from alias manager */
+void DoPortMapping( int fd, struct sockaddr_in *clientaddr, int clientaddrlen, publicportreq *req)
+{
+ u_char proto = IPPROTO_TCP;
+ int aliasport;
+
+ if ( req->opcode == MAPUDPREQ)
+ proto = IPPROTO_UDP;
+ if ( req->lifetime == 0)
+ {
+ /* remove port mapping */
+ if ( !FindAliasPortOut( clientaddr->sin_addr, lastassignaliasAddr, req->privateport, req->publicport, proto, req->lifetime, 0))
+ /* FindAliasPortOut returns no error, port successfully removed, return no error response to client */
+ SendPublicPortResponse( fd, clientaddr, clientaddrlen, req, 1 );
+ else
+ /* deleting port fails, return error */
+ SendPublicPortResponse( fd, clientaddr, clientaddrlen, req, -1 );
+ }
+ else
+ {
+ /* look for port mapping - public port is ignored in this case */
+ /* create port mapping - map provided public port to private port if public port is not 0 */
+ aliasport = FindAliasPortOut( clientaddr->sin_addr, lastassignaliasAddr, req->privateport, req->publicport, proto, req->lifetime, 1);
+ /* aliasport should be non zero if mapping is successfully, else -1 is returned, alias port shouldn't be zero???? */
+ SendPublicPortResponse( fd, clientaddr, clientaddrlen, req, aliasport );
+
+ }
+}
+
+/* HandlePortMap */
+/* handle all packets sent to NATPORTMAP port */
+static void HandlePortMap( int fd )
+{
+#define MAXBUFFERSIZE 100
+
+ struct sockaddr_in clientaddr;
+ int clientaddrlen;
+ unsigned char buffer[MAXBUFFERSIZE];
+ int bytes;
+ unsigned short result = SUCCESS;
+ struct stdportmaprequest *req;
+
+ clientaddrlen = sizeof( clientaddr );
+ bytes = recvfrom( fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&clientaddr, &clientaddrlen);
+ if ( bytes == -1 )
+ {
+ printf( "Read NATPM port error\n");
+ return;
+ }
+ req = (struct stdportmaprequest*)buffer;
+
+#ifdef DEBUG
+ {
+ int i;
+
+ for ( i = 0; i<bytes; i++)
+ {
+ printf("%d", buffer[i]);
+ }
+ printf("\n");
+ }
+#endif
+ /* check client version */
+ if ( req->version > NATPMVERSION )
+ result = NOTSUPPORTEDVERSION;
+ else if ( !enable_natportmap )
+ /* natd wasn't launched with portmapping enabled */
+ result = NOTAUTHORIZED;
+
+ if ( result )
+ {
+ SendPortMapResponse( fd, &clientaddr, clientaddrlen, req->opcode, result );
+ return;
+ }
+
+ switch ( req->opcode )
+ {
+ case PUBLICADDRREQ:
+ {
+ SendPublicAddress(fd, &clientaddr, clientaddrlen);
+ break;
+ }
+
+ case MAPUDPREQ:
+ case MAPTCPREQ:
+ case MAPUDPTCPREQ:
+ {
+ DoPortMapping( fd, &clientaddr, clientaddrlen, (publicportreq*)req);
+ break;
+ }
+
+
+ default:
+ SendPortMapResponse( fd, &clientaddr, clientaddrlen, req->opcode, UNSUPPORTEDOPCODE );
+ }
+
+}
+
+
+#endif
+
static void PrintPacket (struct ip* ip)
{
printf ("%s", FormatPacket (ip));
errx(1, "%s: cannot get interface address", ifn);
PacketAliasSetAddress(sin->sin_addr);
+#ifdef NATPORTMAP
+ if ( (enable_natportmap) && (sin->sin_addr.s_addr != lastassignaliasAddr.s_addr) )
+ {
+ lastassignaliasAddr.s_addr = sin->sin_addr.s_addr;
+ /* make sure the timer handler was set before setting timer */
+ if ( !Natdtimerset ){
+ Natdtimerset = 1;
+ signal(SIGALRM, Natdtimer);
+ }
+ NotifyPublicAddress();
+ }
+#endif
syslog(LOG_INFO, "Aliasing to %s, mtu %d bytes",
inet_ntoa(sin->sin_addr), ifMTU);
}
ProxyRule,
LogDenied,
LogFacility,
- PunchFW
+ PunchFW,
+#ifdef NATPORTMAP
+ NATPortMap,
+ ToInterfaceName
+#endif
};
enum Param {
"basenumber:count",
"punch holes in the firewall for incoming FTP/IRC DCC connections",
"punch_fw",
- NULL }
+ NULL },
+
+#ifdef NATPORTMAP
+ { NATPortMap,
+ 0,
+ YesNo,
+ "[yes|no]",
+ "enable NATPortMap protocol",
+ "enable_natportmap",
+ NULL },
+
+ { ToInterfaceName,
+ 0,
+ String,
+ "network_if_name",
+ "take aliasing address to interface",
+ "natportmap_interface",
+ NULL },
+
+#endif
};
static void ParseOption (const char* option, const char* parms)
case PunchFW:
SetupPunchFW(strValue);
break;
+
+#ifdef NATPORTMAP
+ case NATPortMap:
+ enable_natportmap = yesNoValue;
+ break;
+
+
+ case ToInterfaceName:
+ {
+ if (forwardedinterfacename != NULL)
+ {
+ if ( realloc(forwardedinterfacename, (numofinterfaces+1) * sizeof(*forwardedinterfacename)) == NULL){
+ printf("realloc error, cannot allocate memory for fowarded interface name.\n");
+ return;
+ }
+ }
+ else {
+ if ( (forwardedinterfacename = malloc( sizeof(*forwardedinterfacename) )) == NULL ){
+ printf("malloc error, cannot allocate memory for fowarded interface name.\n");
+ return;
+ }
+ }
+
+ forwardedinterfacename[numofinterfaces] = strdup(strValue);
+ numofinterfaces++;
+
+ break;
+ }
+
+#endif
+
}
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
HEADER_PATHS =\
- -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/bsd/netat
+ -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/
NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95";
*/
static const char rcsid[] =
- "$Id: if.c,v 1.2 2002/03/05 20:35:13 lindak Exp $";
+ "$Id: if.c,v 1.6 2005/01/25 00:10:05 lindak Exp $";
#endif /* not lint */
#include <sys/types.h>
-#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/if_types.h>
+#include <net/if_mib.h>
#include <net/ethernet.h>
+#include <net/route.h>
+
#include <netinet/in.h>
#include <netinet/in_var.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <stdlib.h>
+#include <err.h>
#include "netstat.h"
#define YES 1
#define NO 0
-static void sidewaysintpr (u_int, u_long);
+#define ROUNDUP(a, size) (((a) & ((size) - 1)) ? (1 + ((a)|(size - 1))) : (a))
+
+#define NEXT_SA(p) (struct sockaddr *) \
+ ((caddr_t)p + (p->sa_len ? ROUNDUP(p->sa_len, sizeof(u_long)) : \
+ sizeof(u_long)))
+
+static void sidewaysintpr ();
static void catchalarm (int);
#ifdef INET6
-char *netname6 (struct sockaddr_in6 *, struct in6_addr *);
+char *netname6 (struct sockaddr_in6 *, struct sockaddr *);
static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */
-static int bdg_done;
#endif
#if 0
+#ifdef INET6
+static int bdg_done;
+#endif
+
/* print bridge statistics */
void
bdg_stats(u_long dummy , char *name, int af )
* Display a formatted value, or a '-' in the same space.
*/
static void
-show_stat(const char *fmt, int width, u_long value, short showvalue)
+show_stat(const char *fmt, int width, u_int64_t value, short showvalue)
{
char newfmt[32];
}
}
+size_t
+get_rti_info(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
+{
+ int i;
+ size_t len = 0;
+
+ for (i = 0; i < RTAX_MAX; i++) {
+ if (addrs & (1 << i)) {
+ rti_info[i] = sa;
+ if (sa->sa_len < sizeof(struct sockaddr))
+ len += sizeof(struct sockaddr);
+ else
+ len += sa->sa_len;
+ sa = NEXT_SA(sa);
+ } else {
+ rti_info[i] = NULL;
+ }
+ }
+ return len;
+}
+static void
+multipr(int family, char *buf, char *lim)
+{
+ char *next;
+
+ for (next = buf; next < lim; ) {
+ struct ifma_msghdr2 *ifmam = (struct ifma_msghdr2 *)next;
+ struct sockaddr *rti_info[RTAX_MAX];
+ struct sockaddr *sa;
+ const char *fmt = 0;
+
+ next += ifmam->ifmam_msglen;
+ if (ifmam->ifmam_type == RTM_IFINFO2)
+ break;
+ else if (ifmam->ifmam_type != RTM_NEWMADDR2)
+ continue;
+ get_rti_info(ifmam->ifmam_addrs, (struct sockaddr*)(ifmam + 1), rti_info);
+ sa = rti_info[RTAX_IFA];
+
+ if (sa->sa_family != family)
+ continue;
+ switch (sa->sa_family) {
+ case AF_INET: {
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+
+ fmt = routename(sin->sin_addr.s_addr);
+ break;
+ }
+ #ifdef INET6
+ case AF_INET6: {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+
+ printf("%23s %-19.19s(refs: %d)\n", "",
+ inet_ntop(AF_INET6,
+ &sin6->sin6_addr,
+ ntop_buf,
+ sizeof(ntop_buf)),
+ ifmam->ifmam_refcount);
+ break;
+ }
+ #endif /* INET6 */
+ case AF_LINK: {
+ struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
+
+ switch (sdl->sdl_type) {
+ case IFT_ETHER:
+ case IFT_FDDI:
+ fmt = ether_ntoa(
+ (struct ether_addr *)
+ LLADDR(sdl));
+ break;
+ }
+ break;
+ }
+ }
+ if (fmt)
+ printf("%23s %s\n", "", fmt);
+ }
+}
/*
* Print a description of the network interfaces.
*/
void
-intpr(int interval, u_long ifnetaddr, void (*pfunc)(char *))
+intpr(void (*pfunc)(char *))
{
- struct ifnet ifnet;
- struct ifnethead ifnethead;
- union {
- struct ifaddr ifa;
- struct in_ifaddr in;
-#ifdef INET6
- struct in6_ifaddr in6;
-#endif
-#if 0
- struct ipx_ifaddr ipx;
-#endif
-#ifdef NS
- struct ns_ifaddr ns;
-#endif
-#ifdef ISO
- struct iso_ifaddr iso;
-#endif
- } ifaddr;
- u_long ifaddraddr;
- u_long ifaddrfound;
- u_long ifnetfound;
- u_long opackets;
- u_long ipackets;
- u_long obytes;
- u_long ibytes;
- u_long oerrors;
- u_long ierrors;
- u_long collisions;
- short timer;
- int drops;
+ u_int64_t opackets = 0;
+ u_int64_t ipackets = 0;
+ u_int64_t obytes = 0;
+ u_int64_t ibytes = 0;
+ u_int64_t oerrors = 0;
+ u_int64_t ierrors = 0;
+ u_int64_t collisions = 0;
+ u_long mtu = 0;
+ short timer = 0;
+ int drops = 0;
struct sockaddr *sa = NULL;
- char name[32], tname[16];
+ char name[32];
short network_layer;
short link_layer;
-
- if (ifnetaddr == 0) {
- printf("ifnet: symbol not defined\n");
- return;
- }
+ int mib[6];
+ char *buf = NULL, *lim, *next;
+ size_t len;
+ struct if_msghdr *ifm;
+ struct sockaddr *rti_info[RTAX_MAX];
+ unsigned int ifindex = 0;
+
if (interval) {
- sidewaysintpr((unsigned)interval, ifnetaddr);
+ sidewaysintpr();
return;
}
- if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead))
+
+ if (interface != 0)
+ ifindex = if_nametoindex(interface);
+
+ mib[0] = CTL_NET; // networking subsystem
+ mib[1] = PF_ROUTE; // type of information
+ mib[2] = 0; // protocol (IPPROTO_xxx)
+ mib[3] = 0; // address family
+ mib[4] = NET_RT_IFLIST2; // operation
+ mib[5] = 0;
+ if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
return;
- ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead);
- if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet))
+ if ((buf = malloc(len)) == NULL) {
+ printf("malloc failed\n");
+ exit(1);
+ }
+ if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
+ if (buf)
+ free(buf);
return;
-
+ }
if (!pfunc) {
printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s",
"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
printf(" %s", "Drop");
putchar('\n');
}
- ifaddraddr = 0;
- while (ifnetaddr || ifaddraddr) {
- struct sockaddr_in *sin;
-#ifdef INET6
- struct sockaddr_in6 *sin6;
-#endif
- register char *cp;
+ lim = buf + len;
+ for (next = buf; next < lim; ) {
+ char *cp;
int n, m;
-
+
network_layer = 0;
link_layer = 0;
+ ifm = (struct if_msghdr *)next;
+ next += ifm->ifm_msglen;
+
+ if (ifm->ifm_type == RTM_IFINFO2) {
+ struct if_msghdr2 *if2m = (struct if_msghdr2 *)ifm;
+ struct sockaddr_dl *sdl = (struct sockaddr_dl *)(if2m + 1);
- if (ifaddraddr == 0) {
- ifnetfound = ifnetaddr;
- if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) ||
- kread((u_long)ifnet.if_name, tname, 16))
- return;
- tname[15] = '\0';
- ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link);
- snprintf(name, 32, "%s%d", tname, ifnet.if_unit);
- if (interface != 0 && (strcmp(name, interface) != 0))
+ strncpy(name, sdl->sdl_data, sdl->sdl_nlen);
+ name[sdl->sdl_nlen] = 0;
+ if (interface != 0 && if2m->ifm_index != ifindex)
continue;
cp = index(name, '\0');
continue;
}
- if ((ifnet.if_flags&IFF_UP) == 0)
+ if ((if2m->ifm_flags & IFF_UP) == 0)
*cp++ = '*';
*cp = '\0';
- ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead);
- }
- printf("%-5.5s %-5lu ", name, ifnet.if_mtu);
- ifaddrfound = ifaddraddr;
-
- /*
- * Get the interface stats. These may get
- * overriden below on a per-interface basis.
- */
- opackets = ifnet.if_opackets;
- ipackets = ifnet.if_ipackets;
- obytes = ifnet.if_obytes;
- ibytes = ifnet.if_ibytes;
- oerrors = ifnet.if_oerrors;
- ierrors = ifnet.if_ierrors;
- collisions = ifnet.if_collisions;
- timer = ifnet.if_timer;
- drops = ifnet.if_snd.ifq_drops;
-
- if (ifaddraddr == 0) {
+
+ /*
+ * Get the interface stats. These may get
+ * overriden below on a per-interface basis.
+ */
+ opackets = if2m->ifm_data.ifi_opackets;
+ ipackets = if2m->ifm_data.ifi_ipackets;
+ obytes = if2m->ifm_data.ifi_obytes;
+ ibytes = if2m->ifm_data.ifi_ibytes;
+ oerrors =if2m->ifm_data.ifi_oerrors;
+ ierrors = if2m->ifm_data.ifi_ierrors;
+ collisions = if2m->ifm_data.ifi_collisions;
+ timer = if2m->ifm_timer;
+ drops = if2m->ifm_snd_drops;
+ mtu = if2m->ifm_data.ifi_mtu;
+
+ get_rti_info(if2m->ifm_addrs, (struct sockaddr*)(if2m + 1), rti_info);
+ sa = rti_info[RTAX_IFP];
+ } else if (ifm->ifm_type == RTM_NEWADDR) {
+ struct ifa_msghdr *ifam = (struct ifa_msghdr *)ifm;
+
+ if (interface != 0 && ifam->ifam_index != ifindex)
+ continue;
+ get_rti_info(ifam->ifam_addrs, (struct sockaddr*)(ifam + 1), rti_info);
+ sa = rti_info[RTAX_IFA];
+ } else
+ continue;
+ printf("%-5.5s %-5lu ", name, mtu);
+
+ if (sa == 0) {
printf("%-13.13s ", "none");
printf("%-15.15s ", "none");
} else {
- if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
- ifaddraddr = 0;
- continue;
- }
-#define CP(x) ((char *)(x))
- cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
- CP(&ifaddr);
- sa = (struct sockaddr *)cp;
switch (sa->sa_family) {
case AF_UNSPEC:
printf("%-13.13s ", "none");
printf("%-15.15s ", "none");
break;
- case AF_INET:
- sin = (struct sockaddr_in *)sa;
-#ifdef notdef
- /* can't use inet_makeaddr because kernel
- * keeps nets unshifted.
- */
- in = inet_makeaddr(ifaddr.in.ia_subnet,
- INADDR_ANY);
- printf("%-13.13s ", netname(in.s_addr,
- ifaddr.in.ia_subnetmask));
-#else
- printf("%-13.13s ",
- netname(htonl(ifaddr.in.ia_subnet),
- ifaddr.in.ia_subnetmask));
-#endif
+ case AF_INET: {
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+ struct sockaddr_in mask;
+
+ mask.sin_addr.s_addr = 0;
+ memcpy(&mask, rti_info[RTAX_NETMASK], ((struct sockaddr_in *)rti_info[RTAX_NETMASK])->sin_len);
+
+ printf("%-13.13s ", netname(sin->sin_addr.s_addr & mask.sin_addr.s_addr,
+ mask.sin_addr.s_addr));
+
printf("%-15.15s ",
routename(sin->sin_addr.s_addr));
network_layer = 1;
break;
+ }
#ifdef INET6
- case AF_INET6:
- sin6 = (struct sockaddr_in6 *)sa;
+ case AF_INET6: {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+ struct sockaddr *mask = (struct sockaddr *)rti_info[RTAX_NETMASK];
+
printf("%-11.11s ",
- netname6(&ifaddr.in6.ia_addr,
- &ifaddr.in6.ia_prefixmask.sin6_addr));
+ netname6(sin6,
+ mask));
printf("%-17.17s ",
(char *)inet_ntop(AF_INET6,
&sin6->sin6_addr,
network_layer = 1;
break;
+ }
#endif /*INET6*/
-#if 0
- case AF_IPX:
- {
- struct sockaddr_ipx *sipx =
- (struct sockaddr_ipx *)sa;
- u_long net;
- char netnum[10];
-
- *(union ipx_net *) &net = sipx->sipx_addr.x_net;
- sprintf(netnum, "%lx", (u_long)ntohl(net));
- printf("ipx:%-8s ", netnum);
-/* printf("ipx:%-8s ", netname(net, 0L)); */
- printf("%-15s ",
- ipx_phost((struct sockaddr *)sipx));
- }
- break;
-
- case AF_APPLETALK:
- printf("atalk:%-12.12s ",atalk_print(sa,0x10) );
- printf("%-9.9s ",atalk_print(sa,0x0b) );
- break;
-#endif
-#ifdef NS
- case AF_NS:
- {
- struct sockaddr_ns *sns =
- (struct sockaddr_ns *)sa;
- u_long net;
- char netnum[10];
-
- *(union ns_net *) &net = sns->sns_addr.x_net;
- sprintf(netnum, "%lxH", ntohl(net));
- upHex(netnum);
- printf("ns:%-8s ", netnum);
- printf("%-15s ",
- ns_phost((struct sockaddr *)sns));
- }
- break;
-#endif
case AF_LINK:
{
struct sockaddr_dl *sdl =
ibytes = ifaddr.in.ia_ifa.if_ibytes;
}
#endif
- ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link);
}
- show_stat("lu", 8, ipackets, link_layer|network_layer);
+ show_stat("llu", 8, ipackets, link_layer|network_layer);
printf(" ");
- show_stat("lu", 5, ierrors, link_layer);
+ show_stat("llu", 5, ierrors, link_layer);
printf(" ");
if (bflag) {
- show_stat("lu", 10, ibytes, link_layer|network_layer);
+ show_stat("llu", 10, ibytes, link_layer|network_layer);
printf(" ");
}
- show_stat("lu", 8, opackets, link_layer|network_layer);
+ show_stat("llu", 8, opackets, link_layer|network_layer);
printf(" ");
- show_stat("lu", 5, oerrors, link_layer);
+ show_stat("llu", 5, oerrors, link_layer);
printf(" ");
if (bflag) {
- show_stat("lu", 10, obytes, link_layer|network_layer);
+ show_stat("llu", 10, obytes, link_layer|network_layer);
printf(" ");
}
- show_stat("lu", 5, collisions, link_layer);
+ show_stat("llu", 5, collisions, link_layer);
if (tflag) {
printf(" ");
- show_stat("d", 3, timer, link_layer);
+ show_stat("ll", 3, timer, link_layer);
}
if (dflag) {
printf(" ");
- show_stat("d", 3, drops, link_layer);
+ show_stat("ll", 3, drops, link_layer);
}
putchar('\n');
- if (aflag && ifaddrfound) {
- /*
- * Print family's multicast addresses
- */
- u_long multiaddr;
- struct ifmultiaddr ifma;
- union {
- struct sockaddr sa;
- struct sockaddr_in in;
-#ifdef INET6
- struct sockaddr_in6 in6;
-#endif /* INET6 */
- struct sockaddr_dl dl;
- } msa;
- const char *fmt;
-
- for(multiaddr = (u_long)ifnet.if_multiaddrs.lh_first;
- multiaddr;
- multiaddr = (u_long)ifma.ifma_link.le_next) {
- if (kread(multiaddr, (char *)&ifma,
- sizeof ifma))
- break;
- if (kread((u_long)ifma.ifma_addr, (char *)&msa,
- sizeof msa))
- break;
- if (msa.sa.sa_family != sa->sa_family)
- continue;
-
- fmt = 0;
- switch (msa.sa.sa_family) {
- case AF_INET:
- fmt = routename(msa.in.sin_addr.s_addr);
- break;
-#ifdef INET6
- case AF_INET6:
- printf("%23s %-19.19s(refs: %d)\n", "",
- inet_ntop(AF_INET6,
- &msa.in6.sin6_addr,
- ntop_buf,
- sizeof(ntop_buf)),
- ifma.ifma_refcount);
- break;
-#endif /* INET6 */
- case AF_LINK:
- switch (msa.dl.sdl_type) {
- case IFT_ETHER:
- case IFT_FDDI:
- fmt = ether_ntoa(
- (struct ether_addr *)
- LLADDR(&msa.dl));
- break;
- }
- break;
- }
- if (fmt)
- printf("%23s %s\n", "", fmt);
- }
- }
+
+ if (aflag)
+ multipr(sa->sa_family, next, lim);
}
}
struct iftot {
SLIST_ENTRY(iftot) chain;
- char ift_name[16]; /* interface name */
- u_long ift_ip; /* input packets */
- u_long ift_ie; /* input errors */
- u_long ift_op; /* output packets */
- u_long ift_oe; /* output errors */
- u_long ift_co; /* collisions */
- u_int ift_dr; /* drops */
- u_long ift_ib; /* input bytes */
- u_long ift_ob; /* output bytes */
+ char ift_name[16]; /* interface name */
+ u_int64_t ift_ip; /* input packets */
+ u_int64_t ift_ie; /* input errors */
+ u_int64_t ift_op; /* output packets */
+ u_int64_t ift_oe; /* output errors */
+ u_int64_t ift_co; /* collisions */
+ u_int64_t ift_dr; /* drops */
+ u_int64_t ift_ib; /* input bytes */
+ u_int64_t ift_ob; /* output bytes */
};
u_char signalled; /* set if alarm goes off "early" */
* XXX - should be rewritten to use ifmib(4).
*/
static void
-sidewaysintpr(unsigned interval, u_long off)
+sidewaysintpr()
{
- struct ifnet ifnet;
- u_long firstifnet;
- struct ifnethead ifnethead;
- struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting;
+ struct iftot *total, *sum, *interesting;
register int line;
int oldmask, first;
- u_long interesting_off;
-
- if (kread(off, (char *)&ifnethead, sizeof ifnethead))
- return;
- firstifnet = (u_long)TAILQ_FIRST(&ifnethead);
-
- if ((iftot = malloc(sizeof(struct iftot))) == NULL) {
- printf("malloc failed\n");
- exit(1);
- }
- memset(iftot, 0, sizeof(struct iftot));
-
+ int name[6];
+ size_t len;
+ unsigned int ifcount, i;
+ struct ifmibdata *ifmdall = 0;
+ int interesting_row;
+
+ /* Common OID prefix */
+ name[0] = CTL_NET;
+ name[1] = PF_LINK;
+ name[2] = NETLINK_GENERIC;
+
+ len = sizeof(int);
+ name[3] = IFMIB_SYSTEM;
+ name[4] = IFMIB_IFCOUNT;
+ if (sysctl(name, 5, &ifcount, &len, 0, 0) == 1)
+ err(1, "sysctl IFMIB_IFCOUNT");
+
+ len = ifcount * sizeof(struct ifmibdata);
+ ifmdall = malloc(len);
+ if (ifmdall == 0)
+ err(1, "malloc failed");
+ name[3] = IFMIB_IFALLDATA;
+ name[4] = 0;
+ name[5] = IFDATA_GENERAL;
+ if (sysctl(name, 6, ifmdall, &len, (void *)0, 0) == -1)
+ err(1, "sysctl IFMIB_IFALLDATA");
+
interesting = NULL;
- interesting_off = 0;
- for (off = firstifnet, ip = iftot; off;) {
- char name[16], tname[16];
-
- if (kread(off, (char *)&ifnet, sizeof ifnet))
- break;
- if (kread((u_long)ifnet.if_name, tname, 16))
- break;
- tname[15] = '\0';
- snprintf(name, 16, "%s%d", tname, ifnet.if_unit);
- if (interface && strcmp(name, interface) == 0) {
- interesting = ip;
- interesting_off = off;
- }
- snprintf(ip->ift_name, 16, "(%s)", name);;
- if ((ipn = malloc(sizeof(struct iftot))) == NULL) {
- printf("malloc failed\n");
- exit(1);
+ interesting_row = 0;
+ for (i = 0; i < ifcount; i++) {
+ struct ifmibdata *ifmd = ifmdall + i;
+
+ if (interface && strcmp(ifmd->ifmd_name, interface) == 0) {
+ if ((interesting = calloc(ifcount, sizeof(struct iftot))) == NULL)
+ err(1, "malloc failed");
+ interesting_row = i + 1;
+ snprintf(interesting->ift_name, 16, "(%s)", ifmd->ifmd_name);;
}
- memset(ipn, 0, sizeof(struct iftot));
- SLIST_NEXT(ip, chain) = ipn;
- ip = ipn;
- off = (u_long)TAILQ_NEXT(&ifnet, if_link);
}
- if ((total = malloc(sizeof(struct iftot))) == NULL) {
- printf("malloc failed\n");
- exit(1);
- }
- memset(total, 0, sizeof(struct iftot));
- if ((sum = malloc(sizeof(struct iftot))) == NULL) {
- printf("malloc failed\n");
- exit(1);
- }
- memset(sum, 0, sizeof(struct iftot));
+ if ((total = calloc(1, sizeof(struct iftot))) == NULL)
+ err(1, "malloc failed");
+
+ if ((sum = calloc(1, sizeof(struct iftot))) == NULL)
+ err(1, "malloc failed");
(void)signal(SIGALRM, catchalarm);
line = 0;
loop:
if (interesting != NULL) {
- ip = interesting;
- if (kread(interesting_off, (char *)&ifnet, sizeof ifnet)) {
- printf("???\n");
- exit(1);
- };
+ struct ifmibdata ifmd;
+
+ len = sizeof(struct ifmibdata);
+ name[3] = IFMIB_IFDATA;
+ name[4] = interesting_row;
+ name[5] = IFDATA_GENERAL;
+ if (sysctl(name, 6, &ifmd, &len, (void *)0, 0) == -1)
+ err(1, "sysctl IFDATA_GENERAL %d", interesting_row);
+
if (!first) {
- printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu",
- ifnet.if_ipackets - ip->ift_ip,
- ifnet.if_ierrors - ip->ift_ie,
- ifnet.if_ibytes - ip->ift_ib,
- ifnet.if_opackets - ip->ift_op,
- ifnet.if_oerrors - ip->ift_oe,
- ifnet.if_obytes - ip->ift_ob,
- ifnet.if_collisions - ip->ift_co);
+ printf("%10llu %5llu %10llu %10llu %5llu %10llu %5llu",
+ ifmd.ifmd_data.ifi_ipackets - interesting->ift_ip,
+ ifmd.ifmd_data.ifi_ierrors - interesting->ift_ie,
+ ifmd.ifmd_data.ifi_ibytes - interesting->ift_ib,
+ ifmd.ifmd_data.ifi_opackets - interesting->ift_op,
+ ifmd.ifmd_data.ifi_oerrors - interesting->ift_oe,
+ ifmd.ifmd_data.ifi_obytes - interesting->ift_ob,
+ ifmd.ifmd_data.ifi_collisions - interesting->ift_co);
if (dflag)
- printf(" %5u", ifnet.if_snd.ifq_drops - ip->ift_dr);
+ printf(" %5llu", ifmd.ifmd_snd_drops - interesting->ift_dr);
}
- ip->ift_ip = ifnet.if_ipackets;
- ip->ift_ie = ifnet.if_ierrors;
- ip->ift_ib = ifnet.if_ibytes;
- ip->ift_op = ifnet.if_opackets;
- ip->ift_oe = ifnet.if_oerrors;
- ip->ift_ob = ifnet.if_obytes;
- ip->ift_co = ifnet.if_collisions;
- ip->ift_dr = ifnet.if_snd.ifq_drops;
+ interesting->ift_ip = ifmd.ifmd_data.ifi_ipackets;
+ interesting->ift_ie = ifmd.ifmd_data.ifi_ierrors;
+ interesting->ift_ib = ifmd.ifmd_data.ifi_ibytes;
+ interesting->ift_op = ifmd.ifmd_data.ifi_opackets;
+ interesting->ift_oe = ifmd.ifmd_data.ifi_oerrors;
+ interesting->ift_ob = ifmd.ifmd_data.ifi_obytes;
+ interesting->ift_co = ifmd.ifmd_data.ifi_collisions;
+ interesting->ift_dr = ifmd.ifmd_snd_drops;
} else {
+ unsigned int latest_ifcount;
+
+ len = sizeof(int);
+ name[3] = IFMIB_SYSTEM;
+ name[4] = IFMIB_IFCOUNT;
+ if (sysctl(name, 5, &latest_ifcount, &len, 0, 0) == 1)
+ err(1, "sysctl IFMIB_IFCOUNT");
+ if (latest_ifcount > ifcount) {
+ ifcount = latest_ifcount;
+ len = ifcount * sizeof(struct ifmibdata);
+ free(ifmdall);
+ ifmdall = malloc(len);
+ if (ifmdall == 0)
+ err(1, "malloc failed");
+ } else if (latest_ifcount > ifcount) {
+ ifcount = latest_ifcount;
+ len = ifcount * sizeof(struct ifmibdata);
+ }
+ len = ifcount * sizeof(struct ifmibdata);
+ name[3] = IFMIB_IFALLDATA;
+ name[4] = 0;
+ name[5] = IFDATA_GENERAL;
+ if (sysctl(name, 6, ifmdall, &len, (void *)0, 0) == -1)
+ err(1, "sysctl IFMIB_IFALLDATA");
+
sum->ift_ip = 0;
sum->ift_ie = 0;
sum->ift_ib = 0;
sum->ift_ob = 0;
sum->ift_co = 0;
sum->ift_dr = 0;
- for (off = firstifnet, ip = iftot;
- off && SLIST_NEXT(ip, chain) != NULL;
- ip = SLIST_NEXT(ip, chain)) {
- if (kread(off, (char *)&ifnet, sizeof ifnet)) {
- off = 0;
- continue;
- }
- sum->ift_ip += ifnet.if_ipackets;
- sum->ift_ie += ifnet.if_ierrors;
- sum->ift_ib += ifnet.if_ibytes;
- sum->ift_op += ifnet.if_opackets;
- sum->ift_oe += ifnet.if_oerrors;
- sum->ift_ob += ifnet.if_obytes;
- sum->ift_co += ifnet.if_collisions;
- sum->ift_dr += ifnet.if_snd.ifq_drops;
- off = (u_long)TAILQ_NEXT(&ifnet, if_link);
+ for (i = 0; i < ifcount; i++) {
+ struct ifmibdata *ifmd = ifmdall + i;
+
+ sum->ift_ip += ifmd->ifmd_data.ifi_ipackets;
+ sum->ift_ie += ifmd->ifmd_data.ifi_ierrors;
+ sum->ift_ib += ifmd->ifmd_data.ifi_ibytes;
+ sum->ift_op += ifmd->ifmd_data.ifi_opackets;
+ sum->ift_oe += ifmd->ifmd_data.ifi_oerrors;
+ sum->ift_ob += ifmd->ifmd_data.ifi_obytes;
+ sum->ift_co += ifmd->ifmd_data.ifi_collisions;
+ sum->ift_dr += ifmd->ifmd_snd_drops;
}
if (!first) {
- printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu",
+ printf("%10llu %5llu %10llu %10llu %5llu %10llu %5llu",
sum->ift_ip - total->ift_ip,
sum->ift_ie - total->ift_ie,
sum->ift_ib - total->ift_ib,
sum->ift_ob - total->ift_ob,
sum->ift_co - total->ift_co);
if (dflag)
- printf(" %5u", sum->ift_dr - total->ift_dr);
+ printf(" %5llu", sum->ift_dr - total->ift_dr);
}
*total = *sum;
}
static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95";
*/
static const char rcsid[] =
- "$Id: inet.c,v 1.6 2003/07/08 22:49:49 lindak Exp $";
+ "$Id: inet.c,v 1.7 2004/08/26 23:55:22 lindak Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sysctl.h>
-#include <sys/protosw.h>
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/tcp_seq.h>
#define TCPSTATES
#include <netinet/tcp_fsm.h>
-#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
-#include <netinet/tcp_debug.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/ioctl.h>
-#include <sys/mbuf.h>
-#include <sys/protosw.h>
#include <sys/sysctl.h>
#include <net/route.h>
#ifdef __APPLE__
#define __unused
#endif
-struct socket sockb;
char *inet6name (struct in6_addr *);
void inet6print (struct in6_addr *, int, char *, int);
/*
* Dump PIM statistics structure.
*/
+#ifdef notyet
void
-pim6_stats(u_long off __unused, char *name, int af __unused)
+pim6_stats(void)
{
struct pim6stat pim6stat;
+ size_t len = sizeof(struct pim6stat);
- if (off == 0)
+ if (sysctlbyname("net.inet6.ip6.pim6stat", &pim6stat, &len, 0, 0) == -1)
return;
- kread(off, (char *)&pim6stat, sizeof(pim6stat));
printf("%s:\n", name);
#define p(f, m) if (pim6stat.f || sflag <= 1) \
p(pim6s_snd_registers, "\t%llu register%s sent\n");
#undef p
}
+#endif
/*
* Dump raw ip6 statistics structure.
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/socket.h>
+#include <sys/sysctl.h>
#include <netinet/in.h>
void
ipsec_stats(u_long off __unused, char *name, int af __unused)
{
- if (off == 0)
+ size_t len;
+
+ len = sizeof(struct ipsecstat);
+ if (strcmp(name, "ipsec") == 0)
+ if (sysctlbyname("net.inet.ipsec.stats", &ipsecstat, &len, 0, 0) == -1)
+ return;
+ else if (strcmp(name, "ipsec6") == 0)
+ if (sysctlbyname("net.inet6.ipsec6.stats", &ipsecstat, &len, 0, 0) == -1)
+ return;
+ else
return;
printf ("%s:\n", name);
- kread(off, (char *)&ipsecstat, sizeof (ipsecstat));
print_ipsecstats();
}
{
struct pfkeystat pfkeystat;
unsigned first, type;
-
- if (off == 0)
+ size_t len;
+
+ len = sizeof(struct pfkeystat);
+ if (sysctlbyname("net.key.pfkeystat", &pfkeystat, &len, 0, 0) == -1)
return;
printf ("%s:\n", name);
- kread(off, (char *)&pfkeystat, sizeof(pfkeystat));
#define p(f, m) if (pfkeystat.f || sflag <= 1) \
printf(m, (CAST)pfkeystat.f, plural(pfkeystat.f))
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 3/1/94";
#endif
static const char rcsid[] =
- "$Id: main.c,v 1.5 2003/07/08 22:49:49 lindak Exp $";
+ "$Id: main.c,v 1.8 2004/10/14 22:24:09 lindak Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/file.h>
-#include <sys/protosw.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <net/pfkeyv2.h>
#include <ctype.h>
#include <err.h>
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: main.c,v 1.5 2003/07/08 22:49:49 lindak Exp $
+ * $Id: main.c,v 1.8 2004/10/14 22:24:09 lindak Exp $
*
*/
-
static struct nlist nl[] = {
#define N_IFNET 0
{ "_ifnet" },
{ "_nfile" },
#define N_FILE 18
{ "_file" },
-#define N_MRTSTAT 19
- { "_mrtstat" },
-#define N_MFCTABLE 20
- { "_mfctable" },
-#define N_VIFTABLE 21
- { "_viftable" },
#define N_IPX 22
{ "_ipxpcb"},
#define N_IPXSTAT 23
};
-
struct protox {
u_char pr_index; /* index into nlist of cb head */
u_char pr_sindex; /* index into nlist of stat block */
{ -1, -1, 1, protopr,
igmp_stats, NULL, "igmp", IPPROTO_IGMP },
#ifdef IPSEC
- { -1, N_IPSECSTAT, 1, 0,
- ipsec_stats, NULL, "ipsec", 0},
+ { -1, -1, 1, 0,
+ ipsec_stats, NULL, "ipsec", IPPROTO_ESP},
#endif
#if 0
{ -1, -1, 1, 0,
icmp6_stats, icmp6_ifstats, "icmp6",IPPROTO_ICMPV6 },
#ifdef IPSEC
{ -1, N_IPSEC6STAT, 1, 0,
- ipsec_stats, NULL, "ipsec6",0 },
+ ipsec_stats, NULL, "ipsec6",IPPROTO_ESP },
#endif
#ifdef notyet
{ -1, N_PIM6STAT, 1, 0,
pim6_stats, NULL, "pim6", 0 },
#endif
{ -1, -1, 1, 0,
- rip6_stats, NULL, "rip6", 0 },
+ rip6_stats, NULL, "rip6", IPPROTO_RAW },
#if 0
{ -1, -1, 1, 0,
bdg_stats, NULL, "bdg", 1 /* bridging... */ },
#ifdef IPSEC
struct protox pfkeyprotox[] = {
{ -1, N_PFKEYSTAT, 1, 0,
- pfkey_stats, NULL, "pfkey", 0 },
+ pfkey_stats, NULL, "pfkey", PF_KEY_V2 },
{ -1, -1, 0, 0,
0, NULL, 0, 0 }
};
extern void _serv_cache_close();
#endif
+#if 0
static kvm_t *kvmd;
+#endif
static char *nlistf = NULL, *memf = NULL;
int Aflag; /* show addresses of protocol control block */
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rstuWw:")) != -1)
+ while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rRstuWw:")) != -1)
switch(ch) {
case 'A':
Aflag = 1;
setgid(getgid());
if (mflag) {
- //if (memf != NULL) {
- if (kread(0, 0, 0) == 0)
- mbpr(nl[N_MBSTAT].n_value);
- //mbpr(nl[N_MBSTAT].n_value,
- // nl[N_MBTYPES].n_value,
- // nl[N_NMBCLUSTERS].n_value,
- // nl[N_NMBUFS].n_value);
- //} else
- // mbpr(0, 0, 0, 0);
- //mbpr(0) ;
+ mbpr();
exit(0);
}
#if 0
*/
#endif
if (iflag && !sflag) {
- kread(0, 0, 0);
- intpr(interval, nl[N_IFNET].n_value, NULL);
+ intpr(NULL);
exit(0);
}
if (rflag) {
- kread(0, 0, 0);
if (sflag)
- rt_stats(nl[N_RTSTAT].n_value, nl[N_RTTRASH].n_value);
+ rt_stats();
else
routepr(nl[N_RTREE].n_value);
exit(0);
}
if (gflag) {
- kread(0, 0, 0);
if (sflag) {
if (af == AF_INET || af == AF_UNSPEC)
- mrt_stats(nl[N_MRTSTAT].n_value);
+ mrt_stats();
#ifdef INET6
if (af == AF_INET6 || af == AF_UNSPEC)
- mrt6_stats(nl[N_MRT6STAT].n_value);
+ mrt6_stats();
#endif
} else {
if (af == AF_INET || af == AF_UNSPEC)
- mroutepr(nl[N_MFCTABLE].n_value,
- nl[N_VIFTABLE].n_value);
+ mroutepr();
#ifdef INET6
if (af == AF_INET6 || af == AF_UNSPEC)
- mroute6pr(nl[N_MF6CTABLE].n_value,
- nl[N_MIF6TABLE].n_value);
+ mroute6pr();
#endif
}
exit(0);
}
- kread(0, 0, 0);
if (tp) {
printproto(tp, tp->pr_name);
exit(0);
#endif /*IPSEC*/
#ifndef __APPLE__
if (af == AF_IPX || af == AF_UNSPEC) {
- kread(0, 0, 0);
for (tp = ipxprotox; tp->pr_name; tp++)
printproto(tp, tp->pr_name);
}
if (sflag) {
if (iflag) {
if (tp->pr_istats)
- intpr(interval, nl[N_IFNET].n_value,
- tp->pr_istats);
+ intpr(tp->pr_istats);
else if (pflag)
printf("%s: no per-interface stats routine\n",
tp->pr_name);
}
if (pr != NULL && (off || af != AF_UNSPEC))
(*pr)(off, name, af);
+ else
+ printf("### no stats for %s\n", name);
}
/*
* Read kernel memory, return 0 on success.
*/
+#if 0
int
kread(u_long addr, char *buf, int size)
{
}
return (0);
}
+#endif
char *
plural(int n)
static void
usage(void)
{
- (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
"usage: netstat [-Aan] [-f address_family] [-M core] [-N system]",
" netstat [-bdghimnrs] [-f address_family] [-M core] [-N system]",
" netstat [-bdn] [-I interface] [-M core] [-N system] [-w wait]",
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <sys/param.h>
-#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/mbuf.h>
+#include <sys/sysctl.h>
#include <stdio.h>
#include "netstat.h"
* Print mbuf statistics.
*/
void
-mbpr(mbaddr)
- u_long mbaddr;
+mbpr(void)
{
- register int totmem, totfree, totmbufs;
- register int i;
- register struct mbtypes *mp;
+ int totmem, totfree, totmbufs;
+ int i;
+ struct mbtypes *mp;
+ size_t len;
if (nmbtypes != 256) {
fprintf(stderr,
"netstat: unexpected change to mbstat; check source\n");
return;
}
- if (mbaddr == 0) {
- fprintf(stderr, "netstat: mbstat: symbol not in namelist\n");
- return;
- }
- if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat)))
+ len = sizeof(mbstat);
+ if (sysctlbyname("kern.ipc.mbstat", &mbstat, &len, 0, 0) == -1)
return;
totmbufs = 0;
printf("%u/%u mbuf clusters in use\n",
(unsigned int)(mbstat.m_clusters - mbstat.m_clfree),
(unsigned int)mbstat.m_clusters);
- totmem = totmbufs * MSIZE + mbstat.m_clusters * MCLBYTES;
- totfree = mbstat.m_clfree * MCLBYTES;
+ printf("%u/%u mbuf 4KB clusters in use\n",
+ (unsigned int)(mbstat.m_bigclusters - mbstat.m_bigclfree),
+ (unsigned int)mbstat.m_bigclusters);
+ totmem = totmbufs * MSIZE + mbstat.m_clusters * MCLBYTES + mbstat.m_bigclusters * mbstat.m_bigmclbytes;
+ totfree = mbstat.m_clfree * MCLBYTES + mbstat.m_bigclfree * mbstat.m_bigmclbytes;
printf("%u Kbytes allocated to network (%d%% in use)\n",
totmem / 1024, (totmem - totfree) * 100 / totmem);
printf("%u requests for memory denied\n",
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
-#include <sys/protosw.h>
#include <sys/mbuf.h>
#include <sys/time.h>
+#include <sys/sysctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include "netstat.h"
void
-mroutepr(mfcaddr, vifaddr)
- u_long mfcaddr, vifaddr;
+mroutepr(void)
{
- u_int mrtproto;
- struct mfc *mfctable[MFCTBLSIZ];
+ struct mfc **mfctable = 0;
struct vif viftable[MAXVIFS];
struct mfc mfc, *m;
register struct vif *v;
register int banner_printed;
register int saved_nflag;
vifi_t maxvif = 0;
+ size_t len;
+
+ saved_nflag = nflag;
+ nflag = 1;
- if (mfcaddr == 0 || vifaddr == 0) {
+ len = MAXVIFS * sizeof(struct vif);
+ if (sysctlbyname("net.inet.ip.viftable", viftable, &len, 0, 0) == -1) {
printf("No IPv4 multicast routing compiled into this system.\n");
return;
}
- saved_nflag = nflag;
- nflag = 1;
-
- kread(vifaddr, (char *)&viftable, sizeof(viftable));
banner_printed = 0;
for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
if (v->v_lcl_addr.s_addr == 0)
if (!banner_printed)
printf("\nVirtual Interface Table is empty\n");
- kread(mfcaddr, (char *)&mfctable, sizeof(mfctable));
+ if (sysctlbyname("net.inet.ip.mfctable", 0, &len, 0, 0) == -1) {
+ printf("No IPv4 multicast routing compiled into this system.\n");
+ return;
+ }
+ mfctable = malloc(len);
+ if (mfctable == 0)
+ return;
+ if (sysctlbyname("net.inet.ip.mfctable", mfctable, &len, 0, 0) == -1) {
+ printf("No IPv4 multicast routing compiled into this system.\n");
+ return;
+ }
banner_printed = 0;
for (i = 0; i < MFCTBLSIZ; ++i) {
m = mfctable[i];
while(m) {
- kread((u_long)m, (char *)&mfc, sizeof mfc);
-
if (!banner_printed) {
printf("\nIPv4 Multicast Forwarding Cache\n"
" Origin Group "
printf("\n");
nflag = saved_nflag;
+
+ free(mfctable);
}
void
-mrt_stats(mstaddr)
- u_long mstaddr;
+mrt_stats()
{
struct mrtstat mrtstat;
+ size_t len = sizeof(struct mrtstat);
- if (mstaddr == 0) {
+ if(sysctlbyname("net.inet.ip.mrtstat", &mrtstat, &len, 0, 0) == -1) {
printf("No IPv4 multicast routing compiled into this system.\n");
return;
}
- kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
printf("IPv4 multicast forwarding:\n");
printf(" %10lu multicast forwarding cache lookup%s\n",
mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups));
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
-#include <sys/protosw.h>
+#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_var.h>
#include <netinet/in.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
#define KERNEL 1
#include <netinet6/ip6_mroute.h>
#define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */
void
-mroute6pr(u_long mfcaddr, u_long mifaddr)
+mroute6pr(void)
{
- struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
+ struct mf6c **mf6ctable = 0, *mfcp;
struct mif6 mif6table[MAXMIFS];
struct mf6c mfc;
- struct rtdetq rte, *rtep;
+ struct rtdetq *rtep;
register struct mif6 *mifp;
register mifi_t mifi;
register int i;
register int saved_nflag;
mifi_t maxmif = 0;
long int waitings;
+ size_t len;
- if (mfcaddr == 0 || mifaddr == 0) {
- printf("No IPv6 multicast routing compiled into this"
- " system.\n");
+ len = sizeof(mif6table);
+ if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, 0, 9) == -1) {
+ printf("No IPv6 multicast routing compiled into this system.\n");
return;
}
saved_nflag = nflag;
nflag = 1;
- kread(mifaddr, (char *)&mif6table, sizeof(mif6table));
banner_printed = 0;
for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
struct ifnet ifnet;
if (mifp->m6_ifp == NULL)
continue;
- kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
+ /*
+ * m6_ifp should be ifindex instead of ifnet pointer
+ *
+ * kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
+ */
maxmif = mifi;
if (!banner_printed) {
printf("\nIPv6 Multicast Interface Table\n"
if (!banner_printed)
printf("\nIPv6 Multicast Interface Table is empty\n");
- kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable));
+ len = sizeof(MF6CTBLSIZ * sizeof(struct mf6c));
+ mf6ctable = malloc(len);
+ if (mf6ctable == 0)
+ return;
+ if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, 0, 0) == -1) {
+ printf("No IPv6 multicast routing compiled into this system.\n");
+ free(mf6ctable);
+ return;
+ }
banner_printed = 0;
for (i = 0; i < MF6CTBLSIZ; ++i) {
mfcp = mf6ctable[i];
while(mfcp) {
- kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
if (!banner_printed) {
printf ("\nIPv6 Multicast Forwarding Cache\n");
printf(" %-*.*s %-*.*s %s",
printf(" %9llu", (unsigned long long)mfc.mf6c_pkt_cnt);
for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
+ /* The sysctl should return the number of packet waiting
+ * struct rtdetq rte;
+ * kread((u_long)rtep, (char *)&rte, sizeof(rte));
+ * rtep = rte.next;
+ */
waitings++;
- kread((u_long)rtep, (char *)&rte, sizeof(rte));
- rtep = rte.next;
}
printf(" %3ld", waitings);
printf("\n");
nflag = saved_nflag;
+
+ free(mf6ctable);
}
void
-mrt6_stats(u_long mstaddr)
+mrt6_stats(void)
{
struct mrt6stat mrtstat;
+ size_t len;
- if (mstaddr == 0) {
- printf("No IPv6 multicast routing compiled into this"
- "system.\n");
+ len = sizeof(mrtstat);
+ if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len, 0, 0) == -1) {
+ printf("No IPv6 multicast routing compiled into this system\n");
return;
}
-
- kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
printf("IPv6 multicast forwarding:\n");
printf(" %10llu multicast forwarding cache lookup%s\n",
(unsigned long long)mrtstat.mrt6s_mfc_lookups,
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
extern int af; /* address family */
+#if 0
int kread (u_long addr, char *buf, int size);
+#endif
char *plural (int);
char *plurales (int);
void ip6_ifstats (char *);
void icmp6_stats (u_long, char *, int);
void icmp6_ifstats (char *);
+#ifdef notyet
void pim6_stats (u_long, char *, int);
+#endif
void rip6_stats (u_long, char *, int);
-void mroute6pr (u_long, u_long);
-void mrt6_stats (u_long);
+void mroute6pr (void);
+void mrt6_stats (void);
struct sockaddr_in6;
struct in6_addr;
char *routename6 (struct sockaddr_in6 *);
-char *netname6 (struct sockaddr_in6 *, struct in6_addr *);
+char *netname6 (struct sockaddr_in6 *, struct sockaddr *);
#endif /*INET6*/
#ifdef IPSEC
void bdg_stats (u_long, char *, int);
-//void mbpr (u_long, u_long, u_long, u_long);
-void mbpr (u_long);
+void mbpr (void);
void hostpr (u_long, u_long);
void impstats (u_long, u_long);
-void intpr (int, u_long, void (*)(char *));
+void intpr (void (*)(char *));
void pr_rthdr (int);
void pr_family (int);
-void rt_stats (u_long, u_long);
+void rt_stats (void);
char *ipx_pnet (struct sockaddr *);
char *ipx_phost (struct sockaddr *);
char *ns_phost (struct sockaddr *);
void tp_inproto (u_long);
void tp_stats (caddr_t, caddr_t);
-void mroutepr (u_long, u_long);
-void mrt_stats (u_long);
+void mroutepr (void);
+void mrt_stats (void);
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95";
#endif
static const char rcsid[] =
- "$Id: route.c,v 1.4 2003/07/08 23:03:54 lindak Exp $";
+ "$Id: route.c,v 1.7 2004/10/14 22:24:09 lindak Exp $";
#endif /* not lint */
#include <sys/param.h>
-#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/route.h>
+#include <net/radix.h>
#include <netinet/in.h>
#ifndef __APPLE__
#include <time.h>
#include "netstat.h"
+#if 0
#define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
-
+#endif
/* alignment constraint for routing socket */
#define ROUNDUP(a) \
u_short u_data[128];
} sa_u;
+#if 0
static sa_u pt_u;
+#endif
int do_rtent = 0;
struct rtentry rtentry;
struct radix_mask rmask;
struct radix_node_head *rt_tables[AF_MAX+1];
-int NewTree = 0;
-
+#if 0
static struct sockaddr *kgetsa __P((struct sockaddr *));
static void p_tree __P((struct radix_node *));
static void p_rtnode __P((void));
+static void p_rtentry __P((struct rtentry *));
+#endif
static void ntreestuff __P((void));
-static void np_rtentry __P((struct rt_msghdr *));
+static void np_rtentry __P((struct rt_msghdr2 *));
static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int));
static void p_flags __P((int, char *));
-static void p_rtentry __P((struct rtentry *));
static u_long forgemask __P((u_long));
static void domask __P((char *, u_long, u_long));
void
routepr(u_long rtree)
{
+#if 0
struct radix_node_head *rnh, head;
int i;
+#endif
printf("Routing tables\n");
- if (Aflag == 0 && NewTree)
+ if (dflag == 0)
ntreestuff();
else {
if (rtree == 0) {
printf("rt_tables: symbol not in namelist\n");
return;
}
-
+#if 0
kget(rtree, rt_tables);
for (i = 0; i <= AF_MAX; i++) {
if ((rnh = rt_tables[i]) == 0)
p_tree(head.rnh_treetop);
}
}
+#endif
}
}
#define WID_IF(af) 6 /* width of netif column */
#else
#define WID_DST(af) \
- ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 33: 18)) : 18)
+ ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39: 18)) : 18)
#define WID_GW(af) \
- ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 29 : 18)) : 18)
+ ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 31 : 18)) : 18)
#define WID_IF(af) ((af) == AF_INET6 ? 8 : 6)
#endif /*INET6*/
"Flags", "Netif", "Expire");
}
+#if 0
static struct sockaddr *
kgetsa(struct sockaddr *dst)
{
}
putchar('\n');
}
+#endif
static void
ntreestuff(void)
size_t needed;
int mib[6];
char *buf, *next, *lim;
- register struct rt_msghdr *rtm;
+ register struct rt_msghdr2 *rtm;
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0;
mib[3] = 0;
- mib[4] = NET_RT_DUMP;
+ mib[4] = NET_RT_DUMP2;
mib[5] = 0;
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) {
err(1, "sysctl: net.route.0.0.dump estimate");
}
lim = buf + needed;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
- rtm = (struct rt_msghdr *)next;
+ rtm = (struct rt_msghdr2 *)next;
np_rtentry(rtm);
}
}
static void
-np_rtentry(struct rt_msghdr *rtm)
+get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
{
- register struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
-#ifdef notdef
- static int masks_done, banner_printed;
-#endif
- static int old_af;
- int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST;
-
-#ifdef notdef
- /* for the moment, netmasks are skipped over */
- if (!banner_printed) {
- printf("Netmasks:\n");
- banner_printed = 1;
+ int i;
+
+ for (i = 0; i < RTAX_MAX; i++) {
+ if (addrs & (1 << i)) {
+ rti_info[i] = sa;
+ sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
+ }
+ else
+ rti_info[i] = NULL;
+ }
+}
+
+static void
+np_rtentry(struct rt_msghdr2 *rtm)
+{
+ struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
+ struct sockaddr *rti_info[RTAX_MAX];
+ static int old_fam;
+ int fam = 0;
+ u_short lastindex = 0xffff;
+ static char ifname[IFNAMSIZ + 1];
+ sa_u addr, mask;
+
+ /*
+ * Don't print protocol-cloned routes unless -a.
+ */
+ if ((rtm->rtm_flags & RTF_WASCLONED) && (rtm->rtm_parentflags & RTF_PRCLONING) && !aflag) {
+ return;
+ }
+
+ fam = sa->sa_family;
+ if (af != AF_UNSPEC && af != fam)
+ return;
+ if (fam != old_fam) {
+ pr_family(fam);
+ pr_rthdr(fam);
+ old_fam = fam;
}
- if (masks_done == 0) {
- if (rtm->rtm_addrs != RTA_DST ) {
- masks_done = 1;
- af = sa->sa_family;
+ get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
+ bzero(&addr, sizeof(addr));
+ if ((rtm->rtm_addrs & RTA_DST))
+ bcopy(rti_info[RTAX_DST], &addr, rti_info[RTAX_DST]->sa_len);
+ bzero(&mask, sizeof(mask));
+ if ((rtm->rtm_addrs & RTA_NETMASK))
+ bcopy(rti_info[RTAX_NETMASK], &mask, rti_info[RTAX_NETMASK]->sa_len);
+ p_sockaddr(&addr.u_sa, &mask.u_sa, rtm->rtm_flags,
+ WID_DST(addr.u_sa.sa_family));
+
+ p_sockaddr(rti_info[RTAX_GATEWAY], NULL, RTF_HOST,
+ WID_GW(addr.u_sa.sa_family));
+
+ p_flags(rtm->rtm_flags, "%-6.6s ");
+
+ if (addr.u_sa.sa_family == AF_INET || lflag) {
+ printf("%6u %8d ", rtm->rtm_refcnt, rtm->rtm_use);
+ if (lflag) {
+ if (rtm->rtm_rmx.rmx_mtu != 0)
+ printf("%6lu ", rtm->rtm_rmx.rmx_mtu);
+ else
+ printf("%6s ", "");
}
- } else
-#endif
- af = sa->sa_family;
- if (af != old_af) {
- pr_family(af);
- old_af = af;
}
- if (rtm->rtm_addrs == RTA_DST)
- p_sockaddr(sa, NULL, 0, 36);
- else {
- p_sockaddr(sa, NULL, rtm->rtm_flags, 16);
- sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
- p_sockaddr(sa, NULL, 0, 18);
+ if (rtm->rtm_index != lastindex) {
+ if_indextoname(rtm->rtm_index, ifname);
+ lastindex = rtm->rtm_index;
+ }
+ printf("%*.*s", WID_IF(addr.u_sa.sa_family),
+ WID_IF(addr.u_sa.sa_family), ifname);
+
+ if (rtm->rtm_rmx.rmx_expire) {
+ time_t expire_time;
+
+ if ((expire_time =
+ rtm->rtm_rmx.rmx_expire - time((time_t *)0)) > 0)
+ printf(" %6d", (int)expire_time);
}
- p_flags(rtm->rtm_flags & interesting, "%-6.6s ");
putchar('\n');
}
if ((sin->sin_addr.s_addr == INADDR_ANY) &&
mask &&
- ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr)
- ==0L)
+ (ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L ||
+ mask->sa_len == 0))
cp = "default" ;
else if (flags & RTF_HOST)
cp = routename(sin->sin_addr.s_addr);
if (flags & RTF_HOST)
cp = routename6(sa6);
else if (mask)
- cp = netname6(sa6,
- &((struct sockaddr_in6 *)mask)->sin6_addr);
+ cp = netname6(sa6, mask);
else {
cp = netname6(sa6, NULL);
}
printf(format, name);
}
+#if 0
static void
p_rtentry(struct rtentry *rt)
{
WID_GW(addr.u_sa.sa_family));
p_flags(rt->rt_flags, "%-6.6s ");
if (addr.u_sa.sa_family == AF_INET || lflag) {
- printf("%6ld %8ld ", rt->rt_refcnt, rt->rt_use);
+ printf("%6u %8ld ", rt->rt_refcnt, rt->rt_use);
if (lflag) {
if (rt->rt_rmx.rmx_mtu != 0)
printf("%6lu ", rt->rt_rmx.rmx_mtu);
}
putchar('\n');
}
+#endif
char *
routename(u_long in)
#ifdef INET6
char *
-netname6(struct sockaddr_in6 *sa6, struct in6_addr *mask)
+netname6(struct sockaddr_in6 *sa6, struct sockaddr *sam)
{
static char line[MAXHOSTNAMELEN];
- u_char *p = (u_char *)mask;
u_char *lim;
int masklen, illegal = 0, flag = NI_WITHSCOPEID;
+ struct in6_addr *mask = sam ? &((struct sockaddr_in6 *)sam)->sin6_addr : 0;
- if (mask) {
+ if (sam && sam->sa_len == 0) {
+ masklen = 0;
+ } else if (mask) {
+ u_char *p = (u_char *)mask;
for (masklen = 0, lim = p + 16; p < lim; p++) {
switch (*p) {
case 0xff:
* Print routing statistics
*/
void
-rt_stats(u_long rtsaddr, u_long rttaddr)
+rt_stats(void)
{
struct rtstat rtstat;
int rttrash;
+ int mib[6];
+ size_t len;
- if (rtsaddr == 0) {
- printf("rtstat: symbol not in namelist\n");
+ mib[0] = CTL_NET;
+ mib[1] = AF_ROUTE;
+ mib[2] = 0;
+ mib[3] = 0;
+ mib[4] = NET_RT_STAT;
+ mib[5] = 0;
+ len = sizeof(struct rtstat);
+ if (sysctl(mib, 6, &rtstat, &len, 0, 0) == -1)
return;
- }
- if (rttaddr == 0) {
- printf("rttrash: symbol not in namelist\n");
+
+ mib[0] = CTL_NET;
+ mib[1] = AF_ROUTE;
+ mib[2] = 0;
+ mib[3] = 0;
+ mib[4] = NET_RT_TRASH;
+ mib[5] = 0;
+ len = sizeof(rttrash);
+ if (sysctl(mib, 6, &rttrash, &len, 0, 0) == -1)
return;
- }
- kread(rtsaddr, (char *)&rtstat, sizeof (rtstat));
- kread(rttaddr, (char *)&rttrash, sizeof (rttrash));
+
printf("routing:\n");
#define p(f, m) if (rtstat.f || sflag <= 1) \
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
static char sccsid[] = "@(#)unix.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$Id: unix.c,v 1.2 2001/07/31 05:54:11 wsanchez Exp $";
+ "$Id: unix.c,v 1.3 2004/08/26 23:55:22 lindak Exp $";
#endif /* not lint */
/*
*/
#include <sys/param.h>
#include <sys/queue.h>
-#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/mbuf.h>
CFILES = nfsd.c
-OTHERSRCS = Makefile.preamble Makefile Makefile.dist nfsd.8
+OTHERSRCS = Makefile.preamble Makefile Makefile.dist nfsd.8 Makefile.postamble
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
--- /dev/null
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 nfsd.8 $(DSTROOT)/usr/share/man/man8/nfsd.8
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
CFILES = nfsiod.c
-OTHERSRCS = Makefile.preamble Makefile Makefile.dist nfsiod.8
+OTHERSRCS = Makefile.preamble Makefile Makefile.dist nfsiod.8 Makefile.postamble
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
--- /dev/null
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 nfsiod.8 $(DSTROOT)/usr/share/man/man8/nfsiod.8
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
INSTALL_AS_GROUP = kmem
INSTALL_PERMISSIONS =2555
+
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 nfsstat.1 $(DSTROOT)/usr/share/man/man1/nfsstat.1
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
nfsstats.rpccnt[NFSPROC_READDIR],
nfsstats.rpccnt[NFSPROC_READDIRPLUS],
nfsstats.rpccnt[NFSPROC_ACCESS]);
- printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
- "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit",
- "GLease", "Vacate", "Evict");
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+ printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
+ "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
+ printf("%9d %9d %9d %9d %9d\n",
nfsstats.rpccnt[NFSPROC_MKNOD],
nfsstats.rpccnt[NFSPROC_FSSTAT],
nfsstats.rpccnt[NFSPROC_FSINFO],
nfsstats.rpccnt[NFSPROC_PATHCONF],
- nfsstats.rpccnt[NFSPROC_COMMIT],
- nfsstats.rpccnt[NQNFSPROC_GETLEASE],
- nfsstats.rpccnt[NQNFSPROC_VACATED],
- nfsstats.rpccnt[NQNFSPROC_EVICTED]);
+ nfsstats.rpccnt[NFSPROC_COMMIT]);
printf("Rpc Info:\n");
printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
"TimedOut", "Invalid", "X Replies", "Retries", "Requests");
nfsstats.srvrpccnt[NFSPROC_READDIR],
nfsstats.srvrpccnt[NFSPROC_READDIRPLUS],
nfsstats.srvrpccnt[NFSPROC_ACCESS]);
- printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
- "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit",
- "GLease", "Vacate", "Evict");
- printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+ printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
+ "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
+ printf("%9d %9d %9d %9d %9d\n",
nfsstats.srvrpccnt[NFSPROC_MKNOD],
nfsstats.srvrpccnt[NFSPROC_FSSTAT],
nfsstats.srvrpccnt[NFSPROC_FSINFO],
nfsstats.srvrpccnt[NFSPROC_PATHCONF],
- nfsstats.srvrpccnt[NFSPROC_COMMIT],
- nfsstats.srvrpccnt[NQNFSPROC_GETLEASE],
- nfsstats.srvrpccnt[NQNFSPROC_VACATED],
- nfsstats.srvrpccnt[NQNFSPROC_EVICTED]);
+ nfsstats.srvrpccnt[NFSPROC_COMMIT]);
printf("Server Ret-Failed\n");
printf("%17d\n", nfsstats.srvrpc_errs);
printf("Server Faults\n");
nfsstats.srvcache_idemdonehits,
nfsstats.srvcache_nonidemdonehits,
nfsstats.srvcache_misses);
- printf("Server Lease Stats:\n");
- printf("%9.9s %9.9s %9.9s\n",
- "Leases", "PeakL", "GLeases");
- printf("%9d %9d %9d\n",
- nfsstats.srvnqnfs_leases,
- nfsstats.srvnqnfs_maxleases,
- nfsstats.srvnqnfs_getleases);
printf("Server Write Gathering:\n");
printf("%9.9s %9.9s %9.9s\n",
"WriteOps", "WriteRPC", "Opsaved");
-.\" Copyright (c) 1985, 1991, 1993
-.\" The Regents of the University of California. 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 the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)ping.8 8.3 (Berkeley) 4/28/95
-.\"
-.Dd April 28, 1995
-.Dt PING 8
-.Os BSD 4.3
-.Sh NAME
-.Nm ping
-.Nd send
-.Tn ICMP ECHO_REQUEST
-packets to network hosts
-.Sh SYNOPSIS
-.Nm ping
-.Op Fl Rdfnqrv
-.Op Fl c Ar count
-.Op Fl i Ar wait
-.Op Fl l Ar preload
-.Op Fl p Ar pattern
-.Op Fl s Ar packetsize
-.Ar host
-.Sh DESCRIPTION
-.Nm Ping
-uses the
-.Tn ICMP
-protocol's mandatory
-.Tn ECHO_REQUEST
-datagram to elicit an
-.Tn ICMP ECHO_RESPONSE
-from a host or gateway.
-.Tn ECHO_REQUEST
-datagrams (``pings'') have an IP and
-.Tn ICMP
-header,
-followed by a
-.Dq struct timeval
-and then an arbitrary number of ``pad'' bytes used to fill out the
-packet.
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl c Ar count
-Stop after sending (and receiving)
-.Ar count
-.Tn ECHO_RESPONSE
-packets.
-.It Fl d
-Set the
-.Dv SO_DEBUG
-option on the socket being used.
-.It Fl f
-Flood ping.
-Outputs packets as fast as they come back or one hundred times per second,
-whichever is more.
-For every
-.Tn ECHO_REQUEST
-sent a period ``.'' is printed, while for every
-.Tn ECHO_REPLY
-received a backspace is printed.
-This provides a rapid display of how many packets are being dropped.
-Only the super-user may use this option.
-.Bf -emphasis
-This can be very hard on a network and should be used with caution.
-.Ef
-.It Fl i Ar wait
-Wait
-.Ar wait
-seconds
-.Em between sending each packet .
-The default is to wait for one second between each packet.
-This option is incompatible with the
-.Fl f
-option.
-.It Fl l Ar preload
-If
-.Ar preload
-is specified,
-.Nm ping
-sends that many packets as fast as possible before falling into its normal
-mode of behavior.
-.It Fl n
-Numeric output only.
-No attempt will be made to lookup symbolic names for host addresses.
-.It Fl p Ar pattern
-You may specify up to 16 ``pad'' bytes to fill out the packet you send.
-This is useful for diagnosing data-dependent problems in a network.
-For example,
-.Dq Li \-p ff
-will cause the sent packet to be filled with all
-ones.
-.It Fl q
-Quiet output.
-Nothing is displayed except the summary lines at startup time and
-when finished.
-.It Fl R
-Record route.
-Includes the
-.Tn RECORD_ROUTE
-option in the
-.Tn ECHO_REQUEST
-packet and displays
-the route buffer on returned packets.
-Note that the IP header is only large enough for nine such routes.
-Many hosts ignore or discard this option.
-.It Fl r
-Bypass the normal routing tables and send directly to a host on an attached
-network.
-If the host is not on a directly-attached network, an error is returned.
-This option can be used to ping a local host through an interface
-that has no route through it (e.g., after the interface was dropped by
-.Xr routed 8 ) .
-.It Fl s Ar packetsize
-Specifies the number of data bytes to be sent.
-The default is 56, which translates into 64
-.Tn ICMP
-data bytes when combined
-with the 8 bytes of
-.Tn ICMP
-header data.
-.It Fl v
-Verbose output.
-.Tn ICMP
-packets other than
-.Tn ECHO_RESPONSE
-that are received are listed.
-.El
-.Pp
-When using
-.Nm ping
-for fault isolation, it should first be run on the local host, to verify
-that the local network interface is up and running.
-Then, hosts and gateways further and further away should be ``pinged''.
-Round-trip times and packet loss statistics are computed.
-If duplicate packets are received, they are not included in the packet
-loss calculation, although the round trip time of these packets is used
-in calculating the minimum/average/maximum round-trip time numbers.
-When the specified number of packets have been sent (and received) or
-if the program is terminated with a
-.Dv SIGINT ,
-a brief summary is displayed.
-.Pp
-This program is intended for use in network testing, measurement and
-management.
-Because of the load it can impose on the network, it is unwise to use
-.Nm ping
-during normal operations or from automated scripts.
-.Sh ICMP PACKET DETAILS
-An IP header without options is 20 bytes.
-An
-.Tn ICMP
-.Tn ECHO_REQUEST
-packet contains an additional 8 bytes worth
-of
-.Tn ICMP
-header followed by an arbitrary amount of data.
-When a
-.Ar packetsize
-is given, this indicated the size of this extra piece of data (the
-default is 56).
-Thus the amount of data received inside of an IP packet of type
-.Tn ICMP
-.Tn ECHO_REPLY
-will always be 8 bytes more than the requested data space
-(the
-.Tn ICMP
-header).
-.Pp
-If the data space is at least eight bytes large,
-.Nm ping
-uses the first eight bytes of this space to include a timestamp which
-it uses in the computation of round trip times.
-If less than eight bytes of pad are specified, no round trip times are
-given.
-.Sh DUPLICATE AND DAMAGED PACKETS
-.Nm Ping
-will report duplicate and damaged packets.
-Duplicate packets should never occur, and seem to be caused by
-inappropriate link-level retransmissions.
-Duplicates may occur in many situations and are rarely (if ever) a
-good sign, although the presence of low levels of duplicates may not
-always be cause for alarm.
-.Pp
-Damaged packets are obviously serious cause for alarm and often
-indicate broken hardware somewhere in the
-.Nm ping
-packet's path (in the network or in the hosts).
-.Sh TRYING DIFFERENT DATA PATTERNS
-The (inter)network layer should never treat packets differently depending
-on the data contained in the data portion.
-Unfortunately, data-dependent problems have been known to sneak into
-networks and remain undetected for long periods of time.
-In many cases the particular pattern that will have problems is something
-that doesn't have sufficient ``transitions'', such as all ones or all
-zeros, or a pattern right at the edge, such as almost all zeros.
-It isn't necessarily enough to specify a data pattern of all zeros (for
-example) on the command line because the pattern that is of interest is
-at the data link level, and the relationship between what you type and
-what the controllers transmit can be complicated.
-.Pp
-This means that if you have a data-dependent problem you will probably
-have to do a lot of testing to find it.
-If you are lucky, you may manage to find a file that either can't be sent
-across your network or that takes much longer to transfer than other
-similar length files.
-You can then examine this file for repeated patterns that you can test
-using the
-.Fl p
-option of
-.Nm ping .
-.Sh TTL DETAILS
-The
-.Tn TTL
-value of an IP packet represents the maximum number of IP routers
-that the packet can go through before being thrown away.
-In current practice you can expect each router in the Internet to decrement
-the
-.Tn TTL
-field by exactly one.
-.Pp
-The
-.Tn TCP/IP
-specification states that the
-.Tn TTL
-field for
-.Tn TCP
-packets should
-be set to 60, but many systems use smaller values (4.3
-.Tn BSD
-uses 30, 4.2 used
-15).
-.Pp
-The maximum possible value of this field is 255, and most Unix systems set
-the
-.Tn TTL
-field of
-.Tn ICMP ECHO_REQUEST
-packets to 255.
-This is why you will find you can ``ping'' some hosts, but not reach them
-with
-.Xr telnet 1
-or
-.Xr ftp 1 .
-.Pp
-In normal operation ping prints the ttl value from the packet it receives.
-When a remote system receives a ping packet, it can do one of three things
-with the
-.Tn TTL
-field in its response:
-.Bl -bullet
-.It
-Not change it; this is what Berkeley Unix systems did before the
-.Bx 4.3 tahoe
-release.
-In this case the
-.Tn TTL
-value in the received packet will be 255 minus the
-number of routers in the round-trip path.
-.It
-Set it to 255; this is what current Berkeley Unix systems do.
-In this case the
-.Tn TTL
-value in the received packet will be 255 minus the
-number of routers in the path
-.Xr from
-the remote system
-.Em to
-the
-.Nm ping Ns Em ing
-host.
-.It
-Set it to some other value.
-Some machines use the same value for
-.Tn ICMP
-packets that they use for
-.Tn TCP
-packets, for example either 30 or 60.
-Others may use completely wild values.
-.El
-.Sh BUGS
-Many Hosts and Gateways ignore the
-.Tn RECORD_ROUTE
-option.
-.Pp
-The maximum IP header length is too small for options like
-.Tn RECORD_ROUTE
-to
-be completely useful.
-There's not much that that can be done about this, however.
-.Pp
-Flood pinging is not recommended in general, and flood pinging the
-broadcast address should only be done under very controlled conditions.
-.Sh SEE ALSO
-.Xr netstat 1 ,
-.Xr ifconfig 8 ,
-.Xr routed 8
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 4.3 .
+.\" Copyright (c) 1985, 1991, 1993\r
+.\" The Regents of the University of California. All rights reserved.\r
+.\"\r
+.\" Redistribution and use in source and binary forms, with or without\r
+.\" modification, are permitted provided that the following conditions\r
+.\" are met:\r
+.\" 1. Redistributions of source code must retain the above copyright\r
+.\" notice, this list of conditions and the following disclaimer.\r
+.\" 2. Redistributions in binary form must reproduce the above copyright\r
+.\" notice, this list of conditions and the following disclaimer in the\r
+.\" documentation and/or other materials provided with the distribution.\r
+.\" 4. Neither the name of the University nor the names of its contributors\r
+.\" may be used to endorse or promote products derived from this software\r
+.\" without specific prior written permission.\r
+.\"\r
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+.\" SUCH DAMAGE.\r
+.\"\r
+.\" @(#)ping.8 8.2 (Berkeley) 12/11/93\r
+.\" $FreeBSD: /repoman/r/ncvs/src/sbin/ping/ping.8,v 1.51 2004/04/09 19:58:34 markm Exp $\r
+.\"\r
+.Dd October 2, 2002\r
+.Dt PING 8\r
+.Os\r
+.Sh NAME\r
+.Nm ping\r
+.Nd send\r
+.Tn ICMP ECHO_REQUEST\r
+packets to network hosts\r
+.Sh SYNOPSIS\r
+.Nm\r
+.Op Fl AaDdfnoQqRrv\r
+.Op Fl c Ar count\r
+.Op Fl i Ar wait\r
+.Op Fl l Ar preload\r
+.Op Fl M Cm mask | time\r
+.Op Fl m Ar ttl\r
+.Op Fl P Ar policy\r
+.Op Fl p Ar pattern\r
+.Op Fl S Ar src_addr\r
+.Op Fl s Ar packetsize\r
+.Op Fl t Ar timeout\r
+.Op Fl z Ar tos\r
+.Ar host\r
+.Nm\r
+.Op Fl AaDdfLnoQqRrv\r
+.Op Fl c Ar count\r
+.Op Fl I Ar iface\r
+.Op Fl i Ar wait\r
+.Op Fl l Ar preload\r
+.Op Fl M Cm mask | time\r
+.Op Fl m Ar ttl\r
+.Op Fl P Ar policy\r
+.Op Fl p Ar pattern\r
+.Op Fl S Ar src_addr\r
+.Op Fl s Ar packetsize\r
+.Op Fl T Ar ttl\r
+.Op Fl t Ar timeout\r
+.Op Fl z Ar tos\r
+.Ar mcast-group\r
+.Sh DESCRIPTION\r
+The\r
+.Nm\r
+utility uses the\r
+.Tn ICMP\r
+.No protocol Ap s mandatory\r
+.Tn ECHO_REQUEST\r
+datagram to elicit an\r
+.Tn ICMP ECHO_RESPONSE\r
+from a host or gateway.\r
+.Tn ECHO_REQUEST\r
+datagrams\r
+.Pq Dq pings\r
+have an IP and\r
+.Tn ICMP\r
+header, followed by a\r
+.Dq struct timeval\r
+and then an arbitrary number of\r
+.Dq pad\r
+bytes used to fill out the packet.\r
+The options are as follows:\r
+.Bl -tag -width indent\r
+.It Fl A\r
+Audible.\r
+Output a bell\r
+.Tn ( ASCII\r
+0x07)\r
+character when no packet is received before the next packet\r
+is transmitted.\r
+To cater for round-trip times that are longer than the interval\r
+between transmissions, further missing packets cause a bell only\r
+if the maximum number of unreceived packets has increased.\r
+.It Fl a\r
+Audible.\r
+Include a bell\r
+.Tn ( ASCII\r
+0x07)\r
+character in the output when any packet is received.\r
+This option is ignored\r
+if other format options are present.\r
+.It Fl c Ar count\r
+Stop after sending\r
+(and receiving)\r
+.Ar count\r
+.Tn ECHO_RESPONSE\r
+packets.\r
+If this option is not specified,\r
+.Nm\r
+will operate until interrupted.\r
+.It Fl D\r
+Set the Don't Fragment bit.\r
+.It Fl d\r
+Set the\r
+.Dv SO_DEBUG\r
+option on the socket being used.\r
+.It Fl f\r
+Flood ping.\r
+Outputs packets as fast as they come back or one hundred times per second,\r
+whichever is more.\r
+For every\r
+.Tn ECHO_REQUEST\r
+sent a period\r
+.Dq .\&\r
+is printed, while for every\r
+.Tn ECHO_REPLY\r
+received a backspace is printed.\r
+This provides a rapid display of how many packets are being dropped.\r
+Only the super-user may use this option.\r
+.Bf -emphasis\r
+This can be very hard on a network and should be used with caution.\r
+.Ef\r
+.It Fl I Ar iface\r
+Source multicast packets with the given interface address.\r
+This flag only applies if the ping destination is a multicast address.\r
+.It Fl i Ar wait\r
+Wait\r
+.Ar wait\r
+seconds\r
+.Em between sending each packet .\r
+The default is to wait for one second between each packet.\r
+The wait time may be fractional, but only the super-user may specify\r
+values less than 1 second.\r
+This option is incompatible with the\r
+.Fl f\r
+option.\r
+.It Fl L\r
+Suppress loopback of multicast packets.\r
+This flag only applies if the ping destination is a multicast address.\r
+.It Fl l Ar preload\r
+If\r
+.Ar preload\r
+is specified,\r
+.Nm\r
+sends that many packets as fast as possible before falling into its normal\r
+mode of behavior.\r
+Only the super-user may use this option.\r
+.It Fl M Cm mask | time\r
+Use\r
+.Dv ICMP_MASKREQ\r
+or\r
+.Dv ICMP_TSTAMP\r
+instead of\r
+.Dv ICMP_ECHO .\r
+For\r
+.Cm mask ,\r
+print the netmask of the remote machine.\r
+Set the\r
+.Va net.inet.icmp.maskrepl\r
+MIB variable to enable\r
+.Dv ICMP_MASKREPLY .\r
+For\r
+.Cm time ,\r
+print the origination, reception and transmission timestamps.\r
+.It Fl m Ar ttl\r
+Set the IP Time To Live for outgoing packets.\r
+If not specified, the kernel uses the value of the\r
+.Va net.inet.ip.ttl\r
+MIB variable.\r
+.It Fl n\r
+Numeric output only.\r
+No attempt will be made to lookup symbolic names for host addresses.\r
+.It Fl o\r
+Exit successfully after receiving one reply packet.\r
+.It Fl P Ar policy\r
+.Ar policy\r
+specifies IPsec policy for the ping session.\r
+For details please refer to\r
+.Xr ipsec 4\r
+and\r
+.Xr ipsec_set_policy 3 .\r
+.It Fl p Ar pattern\r
+You may specify up to 16\r
+.Dq pad\r
+bytes to fill out the packet you send.\r
+This is useful for diagnosing data-dependent problems in a network.\r
+For example,\r
+.Dq Li \-p ff\r
+will cause the sent packet to be filled with all\r
+ones.\r
+.It Fl Q\r
+Somewhat quiet output.\r
+.No Don Ap t\r
+display ICMP error messages that are in response to our query messages.\r
+Originally, the\r
+.Fl v\r
+flag was required to display such errors, but\r
+.Fl v\r
+displays all ICMP error messages.\r
+On a busy machine, this output can be overbearing.\r
+Without the\r
+.Fl Q\r
+flag,\r
+.Nm\r
+prints out any ICMP error messages caused by its own ECHO_REQUEST\r
+messages.\r
+.It Fl q\r
+Quiet output.\r
+Nothing is displayed except the summary lines at startup time and\r
+when finished.\r
+.It Fl R\r
+Record route.\r
+Includes the\r
+.Tn RECORD_ROUTE\r
+option in the\r
+.Tn ECHO_REQUEST\r
+packet and displays\r
+the route buffer on returned packets.\r
+Note that the IP header is only large enough for nine such routes;\r
+the\r
+.Xr traceroute 8\r
+command is usually better at determining the route packets take to a\r
+particular destination.\r
+If more routes come back than should, such as due to an illegal spoofed\r
+packet, ping will print the route list and then truncate it at the correct\r
+spot.\r
+Many hosts ignore or discard the\r
+.Tn RECORD_ROUTE\r
+option.\r
+.It Fl r\r
+Bypass the normal routing tables and send directly to a host on an attached\r
+network.\r
+If the host is not on a directly-attached network, an error is returned.\r
+This option can be used to ping a local host through an interface\r
+that has no route through it\r
+(e.g., after the interface was dropped by\r
+.Xr routed 8 ) .\r
+.It Fl S Ar src_addr\r
+Use the following IP address as the source address in outgoing packets.\r
+On hosts with more than one IP address, this option can be used to\r
+force the source address to be something other than the IP address\r
+of the interface the probe packet is sent on.\r
+If the IP address\r
+is not one of this machine's interface addresses, an error is\r
+returned and nothing is sent.\r
+.It Fl s Ar packetsize\r
+Specify the number of data bytes to be sent.\r
+The default is 56, which translates into 64\r
+.Tn ICMP\r
+data bytes when combined\r
+with the 8 bytes of\r
+.Tn ICMP\r
+header data.\r
+.It Fl T Ar ttl\r
+Set the IP Time To Live for multicasted packets.\r
+This flag only applies if the ping destination is a multicast address.\r
+.It Fl t Ar timeout\r
+Specify a timeout, in seconds, before ping exits regardless of how\r
+many packets have been received.\r
+.It Fl v\r
+Verbose output.\r
+.Tn ICMP\r
+packets other than\r
+.Tn ECHO_RESPONSE\r
+that are received are listed.\r
+.It Fl z Ar tos\r
+Use the specified type of service.\r
+.El\r
+.Pp\r
+When using\r
+.Nm\r
+for fault isolation, it should first be run on the local host, to verify\r
+that the local network interface is up and running.\r
+Then, hosts and gateways further and further away should be\r
+.Dq pinged .\r
+Round-trip times and packet loss statistics are computed.\r
+If duplicate packets are received, they are not included in the packet\r
+loss calculation, although the round trip time of these packets is used\r
+in calculating the round-trip time statistics.\r
+When the specified number of packets have been sent\r
+(and received)\r
+or if the program is terminated with a\r
+.Dv SIGINT ,\r
+a brief summary is displayed, showing the number of packets sent and\r
+received, and the minimum, mean, maximum, and standard deviation of\r
+the round-trip times.\r
+.Pp\r
+If\r
+.Nm\r
+receives a\r
+.Dv SIGINFO\r
+(see the\r
+.Cm status\r
+argument for\r
+.Xr stty 1 )\r
+signal, the current number of packets sent and received, and the\r
+minimum, mean, and maximum of the round-trip times will be written to\r
+the standard error output.\r
+.Pp\r
+This program is intended for use in network testing, measurement and\r
+management.\r
+Because of the load it can impose on the network, it is unwise to use\r
+.Nm\r
+during normal operations or from automated scripts.\r
+.Sh ICMP PACKET DETAILS\r
+An IP header without options is 20 bytes.\r
+An\r
+.Tn ICMP\r
+.Tn ECHO_REQUEST\r
+packet contains an additional 8 bytes worth of\r
+.Tn ICMP\r
+header followed by an arbitrary amount of data.\r
+When a\r
+.Ar packetsize\r
+is given, this indicated the size of this extra piece of data\r
+(the default is 56).\r
+Thus the amount of data received inside of an IP packet of type\r
+.Tn ICMP\r
+.Tn ECHO_REPLY\r
+will always be 8 bytes more than the requested data space\r
+(the\r
+.Tn ICMP\r
+header).\r
+.Pp\r
+If the data space is at least eight bytes large,\r
+.Nm\r
+uses the first eight bytes of this space to include a timestamp which\r
+it uses in the computation of round trip times.\r
+If less than eight bytes of pad are specified, no round trip times are\r
+given.\r
+.Sh DUPLICATE AND DAMAGED PACKETS\r
+The\r
+.Nm\r
+utility will report duplicate and damaged packets.\r
+Duplicate packets should never occur when pinging a unicast address,\r
+and seem to be caused by\r
+inappropriate link-level retransmissions.\r
+Duplicates may occur in many situations and are rarely\r
+(if ever)\r
+a good sign, although the presence of low levels of duplicates may not\r
+always be cause for alarm.\r
+Duplicates are expected when pinging a broadcast or multicast address,\r
+since they are not really duplicates but replies from different hosts\r
+to the same request.\r
+.Pp\r
+Damaged packets are obviously serious cause for alarm and often\r
+indicate broken hardware somewhere in the\r
+.Nm\r
+packet's path (in the network or in the hosts).\r
+.Sh TRYING DIFFERENT DATA PATTERNS\r
+The\r
+(inter)network\r
+layer should never treat packets differently depending on the data\r
+contained in the data portion.\r
+Unfortunately, data-dependent problems have been known to sneak into\r
+networks and remain undetected for long periods of time.\r
+In many cases the particular pattern that will have problems is something\r
+that does not have sufficient\r
+.Dq transitions ,\r
+such as all ones or all zeros, or a pattern right at the edge, such as\r
+almost all zeros.\r
+It is not\r
+necessarily enough to specify a data pattern of all zeros (for example)\r
+on the command line because the pattern that is of interest is\r
+at the data link level, and the relationship between what you type and\r
+what the controllers transmit can be complicated.\r
+.Pp\r
+This means that if you have a data-dependent problem you will probably\r
+have to do a lot of testing to find it.\r
+If you are lucky, you may manage to find a file that either\r
+cannot\r
+be sent across your network or that takes much longer to transfer than\r
+other similar length files.\r
+You can then examine this file for repeated patterns that you can test\r
+using the\r
+.Fl p\r
+option of\r
+.Nm .\r
+.Sh TTL DETAILS\r
+The\r
+.Tn TTL\r
+value of an IP packet represents the maximum number of IP routers\r
+that the packet can go through before being thrown away.\r
+In current practice you can expect each router in the Internet to decrement\r
+the\r
+.Tn TTL\r
+field by exactly one.\r
+.Pp\r
+The\r
+.Tn TCP/IP\r
+specification recommends setting the\r
+.Tn TTL\r
+field for\r
+.Tn IP\r
+packets to 64, but many systems use smaller values\r
+.No ( Bx 4.3\r
+uses 30,\r
+.Bx 4.2\r
+used 15).\r
+.Pp\r
+The maximum possible value of this field is 255, and most\r
+.Ux\r
+systems set\r
+the\r
+.Tn TTL\r
+field of\r
+.Tn ICMP ECHO_REQUEST\r
+packets to 255.\r
+This is why you will find you can\r
+.Dq ping\r
+some hosts, but not reach them with\r
+.Xr telnet 1\r
+or\r
+.Xr ftp 1 .\r
+.Pp\r
+In normal operation\r
+.Nm\r
+prints the ttl value from the packet it receives.\r
+When a remote system receives a ping packet, it can do one of three things\r
+with the\r
+.Tn TTL\r
+field in its response:\r
+.Bl -bullet\r
+.It\r
+Not change it; this is what\r
+.Bx\r
+systems did before the\r
+.Bx 4.3 tahoe\r
+release.\r
+In this case the\r
+.Tn TTL\r
+value in the received packet will be 255 minus the\r
+number of routers in the round-trip path.\r
+.It\r
+Set it to 255; this is what current\r
+.Bx\r
+systems do.\r
+In this case the\r
+.Tn TTL\r
+value in the received packet will be 255 minus the\r
+number of routers in the path\r
+.Em from\r
+the remote system\r
+.Em to\r
+the\r
+.Nm Ns Em ing\r
+host.\r
+.It\r
+Set it to some other value.\r
+Some machines use the same value for\r
+.Tn ICMP\r
+packets that they use for\r
+.Tn TCP\r
+packets, for example either 30 or 60.\r
+Others may use completely wild values.\r
+.El\r
+.Sh RETURN VALUES\r
+The\r
+.Nm\r
+utility returns an exit status of zero if at least one response was\r
+heard from the specified\r
+.Ar host ;\r
+a status of two if the transmission was successful but no responses\r
+were received; or another value\r
+(from\r
+.In sysexits.h )\r
+if an error occurred.\r
+.Sh SEE ALSO\r
+.Xr netstat 1 ,\r
+.Xr ifconfig 8 ,\r
+.Xr routed 8 ,\r
+.Xr traceroute 8\r
+.Sh HISTORY\r
+The\r
+.Nm\r
+utility appeared in\r
+.Bx 4.3 .\r
+.Sh AUTHORS\r
+The original\r
+.Nm\r
+utility was written by\r
+.An Mike Muuss\r
+while at the US Army Ballistics\r
+Research Laboratory.\r
+.Sh BUGS\r
+Many Hosts and Gateways ignore the\r
+.Tn RECORD_ROUTE\r
+option.\r
+.Pp\r
+The maximum IP header length is too small for options like\r
+.Tn RECORD_ROUTE\r
+to be completely useful.\r
+.No There Ap s\r
+not much that can be done about this, however.\r
+.Pp\r
+Flood pinging is not recommended in general, and flood pinging the\r
+broadcast address should only be done under very controlled conditions.\r
+.Pp\r
+The\r
+.Fl v\r
+option is not worth much on busy hosts.\r
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
* 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 the University of
- * California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* SUCH DAMAGE.
*/
+#if 0
+#ifndef lint
+static const char copyright[] =
+"@(#) Copyright (c) 1989, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
+#endif /* not lint */
+#endif
+#include <sys/cdefs.h>
+#ifndef __APPLE__
+__FBSDID("$FreeBSD: /repoman/r/ncvs/src/sbin/ping/ping.c,v 1.105 2004/08/14 17:46:10 stefanf Exp $");
+#endif
/*
* P I N G . C
*
- * Using the InterNet Control Message Protocol (ICMP) "ECHO" facility,
+ * Using the Internet Control Message Protocol (ICMP) "ECHO" facility,
* measure round-trip-delays and packet loss across network paths.
*
* Author -
* This program has to run SUID to ROOT to access the ICMP socket.
*/
-#include <sys/param.h>
+#include <sys/param.h> /* NB: we rely on this for <sys/types.h> */
#include <sys/socket.h>
-#include <sys/file.h>
+#include <sys/sysctl.h>
#include <sys/time.h>
-#include <sys/signal.h>
+#include <sys/uio.h>
-#include <netinet/in_systm.h>
#include <netinet/in.h>
+#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/ip_var.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <stdio.h>
+#include <arpa/inet.h>
+
+#ifdef IPSEC
+#include <netinet6/ipsec.h>
+#endif /*IPSEC*/
+
#include <ctype.h>
+#include <err.h>
#include <errno.h>
+#include <math.h>
+#include <netdb.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
-#define DEFDATALEN (64 - 8) /* default data length */
-#define MAXIPLEN 60
-#define MAXICMPLEN 76
-#define MAXPACKET (65536 - 60 - 8)/* max packet size */
+#define INADDR_LEN ((int)sizeof(in_addr_t))
+#define TIMEVAL_LEN ((int)sizeof(struct timeval))
+#define MASK_LEN (ICMP_MASKLEN - ICMP_MINLEN)
+#define TS_LEN (ICMP_TSLEN - ICMP_MINLEN)
+#define DEFDATALEN 56 /* default data length */
+#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */
+ /* runs out of buffer space */
+#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN)
+#define MAXICMPLEN (ICMP_ADVLENMIN + MAX_IPOPTLEN)
#define MAXWAIT 10 /* max seconds to wait for response */
-#define NROUTES 9 /* number of record route slots */
+#define MAXALARM (60 * 60) /* max seconds for alarm timeout */
+#define MAXTOS 255
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
/* various options */
int options;
-#define F_FLOOD 0x001
-#define F_INTERVAL 0x002
-#define F_NUMERIC 0x004
-#define F_PINGFILLED 0x008
-#define F_QUIET 0x010
-#define F_RROUTE 0x020
-#define F_SO_DEBUG 0x040
-#define F_SO_DONTROUTE 0x080
-#define F_VERBOSE 0x100
+#define F_FLOOD 0x0001
+#define F_INTERVAL 0x0002
+#define F_NUMERIC 0x0004
+#define F_PINGFILLED 0x0008
+#define F_QUIET 0x0010
+#define F_RROUTE 0x0020
+#define F_SO_DEBUG 0x0040
+#define F_SO_DONTROUTE 0x0080
+#define F_VERBOSE 0x0100
+#define F_QUIET2 0x0200
+#define F_NOLOOP 0x0400
+#define F_MTTL 0x0800
+#define F_MIF 0x1000
+#define F_AUDIBLE 0x2000
+#ifdef IPSEC
+#ifdef IPSEC_POLICY_IPSEC
+#define F_POLICY 0x4000
+#endif /*IPSEC_POLICY_IPSEC*/
+#endif /*IPSEC*/
+#define F_TTL 0x8000
+#define F_MISSED 0x10000
+#define F_ONCE 0x20000
+#define F_HDRINCL 0x40000
+#define F_MASK 0x80000
+#define F_TIME 0x100000
/*
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum
int mx_dup_ck = MAX_DUP_CHK;
char rcvd_tbl[MAX_DUP_CHK / 8];
-struct sockaddr whereto; /* who to ping */
+struct sockaddr_in whereto; /* who to ping */
int datalen = DEFDATALEN;
+int maxpayload;
int s; /* socket file descriptor */
-u_char outpack[MAXPACKET];
+u_char outpackhdr[IP_MAXPACKET], *outpack;
+char BBELL = '\a'; /* characters written for MISSED and AUDIBLE */
char BSPACE = '\b'; /* characters written for flood */
char DOT = '.';
char *hostname;
+char *shostname;
int ident; /* process id to identify our packets */
+int uid; /* cached uid for micro-optimization */
+u_char icmp_type = ICMP_ECHO;
+u_char icmp_type_rsp = ICMP_ECHOREPLY;
+int phdr_len = 0;
+int send_len;
/* counters */
+long nmissedmax; /* max value of ntransmitted - nreceived - 1 */
long npackets; /* max packets to transmit */
long nreceived; /* # of packets we got back */
long nrepeats; /* number of duplicates */
long ntransmitted; /* sequence # for outbound packets = #sent */
-int interval = 1; /* interval between packets */
+int interval = 1000; /* interval between packets, ms */
/* timing */
int timing; /* flag to do timing */
double tmin = 999999999.0; /* minimum round trip time */
double tmax = 0.0; /* maximum round trip time */
double tsum = 0.0; /* sum of all times, for doing average */
-
-char *pr_addr();
-void catcher(), finish();
-
+double tsumsq = 0.0; /* sum of all times squared, for std. dev. */
+
+volatile sig_atomic_t finish_up; /* nonzero if we've been told to finish up */
+volatile sig_atomic_t siginfo_p;
+
+static void fill(char *, char *);
+static u_short in_cksum(u_short *, int);
+static void check_status(void);
+static void finish(void) __dead2;
+static void pinger(void);
+static char *pr_addr(struct in_addr);
+static char *pr_ntime(n_time);
+static void pr_icmph(struct icmp *);
+static void pr_iph(struct ip *);
+static void pr_pack(char *, int, struct sockaddr_in *, struct timeval *);
+static void pr_retip(struct ip *);
+static void status(int);
+static void stopit(int);
+static void tvsub(struct timeval *, struct timeval *);
+static void usage(void) __dead2;
+
+int
main(argc, argv)
int argc;
- char **argv;
+ char *const *argv;
{
- extern int errno, optind;
- extern char *optarg;
- struct timeval timeout;
+ struct sockaddr_in from, sock_in;
+ struct in_addr ifaddr;
+ struct timeval last, intvl;
+ struct iovec iov;
+ struct ip *ip;
+ struct msghdr msg;
+ struct sigaction si_sa;
+ size_t sz;
+ u_char *datap, packet[IP_MAXPACKET];
+ char *ep, *source, *target, *payload;
struct hostent *hp;
+#ifdef IPSEC_POLICY_IPSEC
+ char *policy_in, *policy_out;
+#endif
struct sockaddr_in *to;
- struct protoent *proto;
- register int i;
- int ch, fdmask, hold, packlen, preload;
- u_char *datap, *packet;
- char *target, hnamebuf[MAXHOSTNAMELEN], *malloc();
+ double t;
+ u_long alarmtimeout, ultmp;
+ int almost_done, ch, df, hold, i, icmp_len, mib[4], preload, sockerrno,
+ tos, ttl;
+ char ctrl[CMSG_SPACE(sizeof(struct timeval))];
+ char hnamebuf[MAXHOSTNAMELEN], snamebuf[MAXHOSTNAMELEN];
#ifdef IP_OPTIONS
- char rspace[3 + 4 * NROUTES + 1]; /* record route space */
+ char rspace[MAX_IPOPTLEN]; /* record route space */
+#endif
+ unsigned char loop, mttl;
+
+ payload = source = NULL;
+#ifdef IPSEC_POLICY_IPSEC
+ policy_in = policy_out = NULL;
#endif
- preload = 0;
- datap = &outpack[8 + sizeof(struct timeval)];
- while ((ch = getopt(argc, argv, "Rc:dfh:i:l:np:qrs:v")) != EOF)
+ /*
+ * Do the stuff that we need root priv's for *first*, and
+ * then drop our setuid bit. Save error reporting for
+ * after arg parsing.
+ */
+ s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
+ sockerrno = errno;
+
+ setuid(getuid());
+ uid = getuid();
+
+ alarmtimeout = df = preload = tos = 0;
+
+ outpack = outpackhdr + sizeof(struct ip);
+ while ((ch = getopt(argc, argv,
+ "Aac:DdfI:i:Ll:M:m:nop:QqRrS:s:T:t:vz:"
+#ifdef IPSEC
+#ifdef IPSEC_POLICY_IPSEC
+ "P:"
+#endif /*IPSEC_POLICY_IPSEC*/
+#endif /*IPSEC*/
+ )) != -1)
+ {
switch(ch) {
+ case 'A':
+ options |= F_MISSED;
+ break;
+ case 'a':
+ options |= F_AUDIBLE;
+ break;
case 'c':
- npackets = atoi(optarg);
- if (npackets <= 0) {
- (void)fprintf(stderr,
- "ping: bad number of packets to transmit.\n");
- exit(1);
- }
+ ultmp = strtoul(optarg, &ep, 0);
+ if (*ep || ep == optarg || ultmp > LONG_MAX || !ultmp)
+ errx(EX_USAGE,
+ "invalid count of packets to transmit: `%s'",
+ optarg);
+ npackets = ultmp;
+ break;
+ case 'D':
+ options |= F_HDRINCL;
+ df = 1;
break;
case 'd':
options |= F_SO_DEBUG;
break;
case 'f':
- if (getuid()) {
- (void)fprintf(stderr,
- "ping: %s\n", strerror(EPERM));
- exit(1);
+ if (uid) {
+ errno = EPERM;
+ err(EX_NOPERM, "-f flag");
}
options |= F_FLOOD;
setbuf(stdout, (char *)NULL);
break;
+ case 'I': /* multicast interface */
+ if (inet_aton(optarg, &ifaddr) == 0)
+ errx(EX_USAGE,
+ "invalid multicast interface: `%s'",
+ optarg);
+ options |= F_MIF;
+ break;
case 'i': /* wait between sending packets */
- interval = atoi(optarg);
- if (interval <= 0) {
- (void)fprintf(stderr,
- "ping: bad timing interval.\n");
- exit(1);
- }
+ t = strtod(optarg, &ep) * 1000.0;
+ if (*ep || ep == optarg || t > (double)INT_MAX)
+ errx(EX_USAGE, "invalid timing interval: `%s'",
+ optarg);
options |= F_INTERVAL;
+ interval = (int)t;
+ if (uid && interval < 1000) {
+ errno = EPERM;
+ err(EX_NOPERM, "-i interval too short");
+ }
+ break;
+ case 'L':
+ options |= F_NOLOOP;
+ loop = 0;
break;
case 'l':
- if (getuid()) {
- (void)fprintf(stderr,
- "ping: %s\n", strerror(EPERM));
- exit(1);
+ ultmp = strtoul(optarg, &ep, 0);
+ if (*ep || ep == optarg || ultmp > INT_MAX)
+ errx(EX_USAGE,
+ "invalid preload value: `%s'", optarg);
+ if (uid) {
+ errno = EPERM;
+ err(EX_NOPERM, "-l flag");
}
- preload = atoi(optarg);
- if (preload < 0) {
- (void)fprintf(stderr,
- "ping: bad preload value.\n");
- exit(1);
+ preload = ultmp;
+ break;
+ case 'M':
+ switch(optarg[0]) {
+ case 'M':
+ case 'm':
+ options |= F_MASK;
+ break;
+ case 'T':
+ case 't':
+ options |= F_TIME;
+ break;
+ default:
+ errx(EX_USAGE, "invalid message: `%c'", optarg[0]);
+ break;
}
break;
+ case 'm': /* TTL */
+ ultmp = strtoul(optarg, &ep, 0);
+ if (*ep || ep == optarg || ultmp > MAXTTL)
+ errx(EX_USAGE, "invalid TTL: `%s'", optarg);
+ ttl = ultmp;
+ options |= F_TTL;
+ break;
case 'n':
options |= F_NUMERIC;
break;
+ case 'o':
+ options |= F_ONCE;
+ break;
+#ifdef IPSEC
+#ifdef IPSEC_POLICY_IPSEC
+ case 'P':
+ options |= F_POLICY;
+ if (!strncmp("in", optarg, 2))
+ policy_in = strdup(optarg);
+ else if (!strncmp("out", optarg, 3))
+ policy_out = strdup(optarg);
+ else
+ errx(1, "invalid security policy");
+ break;
+#endif /*IPSEC_POLICY_IPSEC*/
+#endif /*IPSEC*/
case 'p': /* fill buffer with user pattern */
options |= F_PINGFILLED;
- fill((char *)datap, optarg);
- break;
+ payload = optarg;
+ break;
+ case 'Q':
+ options |= F_QUIET2;
+ break;
case 'q':
options |= F_QUIET;
break;
case 'r':
options |= F_SO_DONTROUTE;
break;
+ case 'S':
+ source = optarg;
+ break;
case 's': /* size of packet to send */
- datalen = atoi(optarg);
- if (datalen > MAXPACKET) {
- (void)fprintf(stderr,
- "ping: packet size too large.\n");
- exit(1);
- }
- if (datalen <= 0) {
- (void)fprintf(stderr,
- "ping: illegal packet size.\n");
- exit(1);
+ ultmp = strtoul(optarg, &ep, 0);
+ if (*ep || ep == optarg)
+ errx(EX_USAGE, "invalid packet size: `%s'",
+ optarg);
+#ifndef __APPLE__
+ if (uid != 0 && ultmp > DEFDATALEN) {
+ errno = EPERM;
+ err(EX_NOPERM,
+ "packet size too large: %lu > %u",
+ ultmp, DEFDATALEN);
}
+#endif
+ datalen = ultmp;
+ break;
+ case 'T': /* multicast TTL */
+ ultmp = strtoul(optarg, &ep, 0);
+ if (*ep || ep == optarg || ultmp > MAXTTL)
+ errx(EX_USAGE, "invalid multicast TTL: `%s'",
+ optarg);
+ mttl = ultmp;
+ options |= F_MTTL;
+ break;
+ case 't':
+ alarmtimeout = strtoul(optarg, &ep, 0);
+ if ((alarmtimeout < 1) || (alarmtimeout == ULONG_MAX))
+ errx(EX_USAGE, "invalid timeout: `%s'",
+ optarg);
+ if (alarmtimeout > MAXALARM)
+ errx(EX_USAGE, "invalid timeout: `%s' > %d",
+ optarg, MAXALARM);
+ alarm((int)alarmtimeout);
break;
case 'v':
options |= F_VERBOSE;
break;
+ case 'z':
+ options |= F_HDRINCL;
+ ultmp = strtoul(optarg, &ep, 0);
+ if (*ep || ep == optarg || ultmp > MAXTOS)
+ errx(EX_USAGE, "invalid TOS: `%s'", optarg);
+ tos = ultmp;
+ break;
default:
usage();
}
- argc -= optind;
- argv += optind;
+ }
- if (argc != 1)
+ if (argc - optind != 1)
usage();
- target = *argv;
+ target = argv[optind];
+
+ switch (options & (F_MASK|F_TIME)) {
+ case 0: break;
+ case F_MASK:
+ icmp_type = ICMP_MASKREQ;
+ icmp_type_rsp = ICMP_MASKREPLY;
+ phdr_len = MASK_LEN;
+ if (!(options & F_QUIET))
+ (void)printf("ICMP_MASKREQ\n");
+ break;
+ case F_TIME:
+ icmp_type = ICMP_TSTAMP;
+ icmp_type_rsp = ICMP_TSTAMPREPLY;
+ phdr_len = TS_LEN;
+ if (!(options & F_QUIET))
+ (void)printf("ICMP_TSTAMP\n");
+ break;
+ default:
+ errx(EX_USAGE, "ICMP_TSTAMP and ICMP_MASKREQ are exclusive.");
+ break;
+ }
+ icmp_len = sizeof(struct ip) + ICMP_MINLEN + phdr_len;
+ if (options & F_RROUTE)
+ icmp_len += MAX_IPOPTLEN;
+ maxpayload = IP_MAXPACKET - icmp_len;
+ if (datalen > maxpayload)
+ errx(EX_USAGE, "packet size too large: %d > %d", datalen,
+ maxpayload);
+ send_len = icmp_len + datalen;
+ datap = &outpack[ICMP_MINLEN + phdr_len + TIMEVAL_LEN];
+ if (options & F_PINGFILLED) {
+ fill((char *)datap, payload);
+ }
+ if (source) {
+ bzero((char *)&sock_in, sizeof(sock_in));
+ sock_in.sin_family = AF_INET;
+ if (inet_aton(source, &sock_in.sin_addr) != 0) {
+ shostname = source;
+ } else {
+ hp = gethostbyname2(source, AF_INET);
+ if (!hp)
+ errx(EX_NOHOST, "cannot resolve %s: %s",
+ source, hstrerror(h_errno));
+
+ sock_in.sin_len = sizeof sock_in;
+ if ((unsigned)hp->h_length > sizeof(sock_in.sin_addr) ||
+ hp->h_length < 0)
+ errx(1, "gethostbyname2: illegal address");
+ memcpy(&sock_in.sin_addr, hp->h_addr_list[0],
+ sizeof(sock_in.sin_addr));
+ (void)strncpy(snamebuf, hp->h_name,
+ sizeof(snamebuf) - 1);
+ snamebuf[sizeof(snamebuf) - 1] = '\0';
+ shostname = snamebuf;
+ }
+ if (bind(s, (struct sockaddr *)&sock_in, sizeof sock_in) == -1)
+ err(1, "bind");
+ }
- memset(&whereto, 0, sizeof(struct sockaddr));
- to = (struct sockaddr_in *)&whereto;
+ bzero(&whereto, sizeof(whereto));
+ to = &whereto;
to->sin_family = AF_INET;
- to->sin_addr.s_addr = inet_addr(target);
- if (to->sin_addr.s_addr != (u_int)-1)
+ to->sin_len = sizeof *to;
+ if (inet_aton(target, &to->sin_addr) != 0) {
hostname = target;
- else {
- hp = gethostbyname(target);
- if (!hp) {
- (void)fprintf(stderr,
- "ping: unknown host %s\n", target);
- exit(1);
- }
- to->sin_family = hp->h_addrtype;
- memmove(&to->sin_addr, hp->h_addr, hp->h_length);
+ } else {
+ hp = gethostbyname2(target, AF_INET);
+ if (!hp)
+ errx(EX_NOHOST, "cannot resolve %s: %s",
+ target, hstrerror(h_errno));
+
+ if ((unsigned)hp->h_length > sizeof(to->sin_addr))
+ errx(1, "gethostbyname2 returned an illegal address");
+ memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr);
(void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1);
+ hnamebuf[sizeof(hnamebuf) - 1] = '\0';
hostname = hnamebuf;
}
- if (options & F_FLOOD && options & F_INTERVAL) {
- (void)fprintf(stderr,
- "ping: -f and -i incompatible options.\n");
- exit(1);
- }
+ if (options & F_FLOOD && options & F_INTERVAL)
+ errx(EX_USAGE, "-f and -i: incompatible options");
- if (datalen >= sizeof(struct timeval)) /* can we time transfer */
+ if (options & F_FLOOD && IN_MULTICAST(ntohl(to->sin_addr.s_addr)))
+ errx(EX_USAGE,
+ "-f flag cannot be used with multicast destination");
+ if (options & (F_MIF | F_NOLOOP | F_MTTL)
+ && !IN_MULTICAST(ntohl(to->sin_addr.s_addr)))
+ errx(EX_USAGE,
+ "-I, -L, -T flags cannot be used with unicast destination");
+
+ if (datalen >= TIMEVAL_LEN) /* can we time transfer */
timing = 1;
- packlen = datalen + MAXIPLEN + MAXICMPLEN;
- if (!(packet = (u_char *)malloc((u_int)packlen))) {
- (void)fprintf(stderr, "ping: out of memory.\n");
- exit(1);
- }
+
if (!(options & F_PINGFILLED))
- for (i = 8; i < datalen; ++i)
+ for (i = TIMEVAL_LEN; i < datalen; ++i)
*datap++ = i;
ident = getpid() & 0xFFFF;
- if (!(proto = getprotobyname("icmp"))) {
- (void)fprintf(stderr, "ping: unknown protocol icmp.\n");
- exit(1);
- }
- if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) {
- perror("ping: socket");
- exit(1);
+ if (s < 0) {
+ errno = sockerrno;
+ err(EX_OSERR, "socket");
}
hold = 1;
if (options & F_SO_DEBUG)
if (options & F_SO_DONTROUTE)
(void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&hold,
sizeof(hold));
+#ifdef IPSEC
+#ifdef IPSEC_POLICY_IPSEC
+ if (options & F_POLICY) {
+ char *buf;
+ if (policy_in != NULL) {
+ buf = ipsec_set_policy(policy_in, strlen(policy_in));
+ if (buf == NULL)
+ errx(EX_CONFIG, "%s", ipsec_strerror());
+ if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
+ buf, ipsec_get_policylen(buf)) < 0)
+ err(EX_CONFIG,
+ "ipsec policy cannot be configured");
+ free(buf);
+ }
+ if (policy_out != NULL) {
+ buf = ipsec_set_policy(policy_out, strlen(policy_out));
+ if (buf == NULL)
+ errx(EX_CONFIG, "%s", ipsec_strerror());
+ if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
+ buf, ipsec_get_policylen(buf)) < 0)
+ err(EX_CONFIG,
+ "ipsec policy cannot be configured");
+ free(buf);
+ }
+ }
+#endif /*IPSEC_POLICY_IPSEC*/
+#endif /*IPSEC*/
+
+ if (options & F_HDRINCL) {
+ ip = (struct ip*)outpackhdr;
+ if (!(options & (F_TTL | F_MTTL))) {
+ mib[0] = CTL_NET;
+ mib[1] = PF_INET;
+ mib[2] = IPPROTO_IP;
+ mib[3] = IPCTL_DEFTTL;
+ sz = sizeof(ttl);
+ if (sysctl(mib, 4, &ttl, &sz, NULL, 0) == -1)
+ err(1, "sysctl(net.inet.ip.ttl)");
+ }
+ setsockopt(s, IPPROTO_IP, IP_HDRINCL, &hold, sizeof(hold));
+ ip->ip_v = IPVERSION;
+ ip->ip_hl = sizeof(struct ip) >> 2;
+ ip->ip_tos = tos;
+ ip->ip_id = 0;
+ ip->ip_off = df ? IP_DF : 0;
+ ip->ip_ttl = ttl;
+ ip->ip_p = IPPROTO_ICMP;
+ ip->ip_src.s_addr = source ? sock_in.sin_addr.s_addr : INADDR_ANY;
+ ip->ip_dst = to->sin_addr;
+ }
/* record route option */
if (options & F_RROUTE) {
#ifdef IP_OPTIONS
+ bzero(rspace, sizeof(rspace));
rspace[IPOPT_OPTVAL] = IPOPT_RR;
- rspace[IPOPT_OLEN] = sizeof(rspace)-1;
+ rspace[IPOPT_OLEN] = sizeof(rspace) - 1;
rspace[IPOPT_OFFSET] = IPOPT_MINOFF;
+ rspace[sizeof(rspace) - 1] = IPOPT_EOL;
if (setsockopt(s, IPPROTO_IP, IP_OPTIONS, rspace,
- sizeof(rspace)) < 0) {
- perror("ping: record route");
- exit(1);
- }
+ sizeof(rspace)) < 0)
+ err(EX_OSERR, "setsockopt IP_OPTIONS");
#else
- (void)fprintf(stderr,
- "ping: record route not available in this implementation.\n");
- exit(1);
+ errx(EX_UNAVAILABLE,
+ "record route not available in this implementation");
#endif /* IP_OPTIONS */
}
+ if (options & F_TTL) {
+ if (setsockopt(s, IPPROTO_IP, IP_TTL, &ttl,
+ sizeof(ttl)) < 0) {
+ err(EX_OSERR, "setsockopt IP_TTL");
+ }
+ }
+ if (options & F_NOLOOP) {
+ if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop,
+ sizeof(loop)) < 0) {
+ err(EX_OSERR, "setsockopt IP_MULTICAST_LOOP");
+ }
+ }
+ if (options & F_MTTL) {
+ if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &mttl,
+ sizeof(mttl)) < 0) {
+ err(EX_OSERR, "setsockopt IP_MULTICAST_TTL");
+ }
+ }
+ if (options & F_MIF) {
+ if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &ifaddr,
+ sizeof(ifaddr)) < 0) {
+ err(EX_OSERR, "setsockopt IP_MULTICAST_IF");
+ }
+ }
+#ifdef SO_TIMESTAMP
+ { int on = 1;
+ if (setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on)) < 0)
+ err(EX_OSERR, "setsockopt SO_TIMESTAMP");
+ }
+#endif
+
/*
* When pinging the broadcast address, you can get a lot of answers.
* Doing something so evil is useful if you are trying to stress the
* ethernet, or just want to fill the arp cache to get some stuff for
- * /etc/ethers.
+ * /etc/ethers. But beware: RFC 1122 allows hosts to ignore broadcast
+ * or multicast pings if they wish.
*/
- (void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, &packlen, sizeof(packlen));
- if (to->sin_family == AF_INET)
- (void)printf("PING %s (%s): %d data bytes\n", hostname,
- inet_ntoa(*(struct in_addr *)&to->sin_addr.s_addr),
- datalen);
- else
+ /*
+ * XXX receive buffer needs undetermined space for mbuf overhead
+ * as well.
+ */
+ hold = IP_MAXPACKET + 128;
+ (void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold,
+ sizeof(hold));
+ if (uid == 0)
+ (void)setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&hold,
+ sizeof(hold));
+
+ if (to->sin_family == AF_INET) {
+ (void)printf("PING %s (%s)", hostname,
+ inet_ntoa(to->sin_addr));
+ if (source)
+ (void)printf(" from %s", shostname);
+ (void)printf(": %d data bytes\n", datalen);
+ } else
(void)printf("PING %s: %d data bytes\n", hostname, datalen);
- (void)signal(SIGINT, finish);
- (void)signal(SIGALRM, catcher);
+ /*
+ * Use sigaction() instead of signal() to get unambiguous semantics,
+ * in particular with SA_RESTART not set.
+ */
+
+ sigemptyset(&si_sa.sa_mask);
+ si_sa.sa_flags = 0;
- while (preload--) /* fire off them quickies */
- pinger();
+ si_sa.sa_handler = stopit;
+ if (sigaction(SIGINT, &si_sa, 0) == -1) {
+ err(EX_OSERR, "sigaction SIGINT");
+ }
- if ((options & F_FLOOD) == 0)
- catcher(); /* start things going */
+ si_sa.sa_handler = status;
+ if (sigaction(SIGINFO, &si_sa, 0) == -1) {
+ err(EX_OSERR, "sigaction");
+ }
- for (;;) {
- struct sockaddr_in from;
- register int cc;
- int fromlen;
- sigset_t omask, nmask;
+ if (alarmtimeout > 0) {
+ si_sa.sa_handler = stopit;
+ if (sigaction(SIGALRM, &si_sa, 0) == -1)
+ err(EX_OSERR, "sigaction SIGALRM");
+ }
+
+ bzero(&msg, sizeof(msg));
+ msg.msg_name = (caddr_t)&from;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+#ifdef SO_TIMESTAMP
+ msg.msg_control = (caddr_t)ctrl;
+#endif
+ iov.iov_base = packet;
+ iov.iov_len = IP_MAXPACKET;
- if (options & F_FLOOD) {
+ if (preload == 0)
+ pinger(); /* send the first ping */
+ else {
+ if (npackets != 0 && preload > npackets)
+ preload = npackets;
+ while (preload--) /* fire off them quickies */
pinger();
- timeout.tv_sec = 0;
- timeout.tv_usec = 10000;
- fdmask = 1 << s;
- if (select(s + 1, (fd_set *)&fdmask, (fd_set *)NULL,
- (fd_set *)NULL, &timeout) < 1)
- continue;
+ }
+ (void)gettimeofday(&last, NULL);
+
+ if (options & F_FLOOD) {
+ intvl.tv_sec = 0;
+ intvl.tv_usec = 10000;
+ } else {
+ intvl.tv_sec = interval / 1000;
+ intvl.tv_usec = interval % 1000 * 1000;
+ }
+
+ almost_done = 0;
+ while (!finish_up) {
+ struct timeval now, timeout;
+ fd_set rfds;
+ int cc, n;
+
+ check_status();
+ if ((unsigned)s >= FD_SETSIZE)
+ errx(EX_OSERR, "descriptor too large");
+ FD_ZERO(&rfds);
+ FD_SET(s, &rfds);
+ (void)gettimeofday(&now, NULL);
+ timeout.tv_sec = last.tv_sec + intvl.tv_sec - now.tv_sec;
+ timeout.tv_usec = last.tv_usec + intvl.tv_usec - now.tv_usec;
+ while (timeout.tv_usec < 0) {
+ timeout.tv_usec += 1000000;
+ timeout.tv_sec--;
}
- fromlen = sizeof(from);
- if ((cc = recvfrom(s, (char *)packet, packlen, 0,
- (struct sockaddr *)&from, &fromlen)) < 0) {
- if (errno == EINTR)
+ while (timeout.tv_usec >= 1000000) {
+ timeout.tv_usec -= 1000000;
+ timeout.tv_sec++;
+ }
+ if (timeout.tv_sec < 0)
+ timeout.tv_sec = timeout.tv_usec = 0;
+ n = select(s + 1, &rfds, NULL, NULL, &timeout);
+ if (n < 0)
+ continue; /* Must be EINTR. */
+ if (n == 1) {
+ struct timeval *tv = NULL;
+#ifdef SO_TIMESTAMP
+ struct cmsghdr *cmsg = (struct cmsghdr *)&ctrl;
+
+ msg.msg_controllen = sizeof(ctrl);
+#endif
+ msg.msg_namelen = sizeof(from);
+ if ((cc = recvmsg(s, &msg, 0)) < 0) {
+ if (errno == EINTR)
+ continue;
+ warn("recvmsg");
continue;
- perror("ping: recvfrom");
- continue;
+ }
+#ifdef SO_TIMESTAMP
+ if (cmsg->cmsg_level == SOL_SOCKET &&
+ cmsg->cmsg_type == SCM_TIMESTAMP &&
+ cmsg->cmsg_len == CMSG_LEN(sizeof *tv)) {
+ /* Copy to avoid alignment problems: */
+ memcpy(&now, CMSG_DATA(cmsg), sizeof(now));
+ tv = &now;
+ }
+#endif
+ if (tv == NULL) {
+ (void)gettimeofday(&now, NULL);
+ tv = &now;
+ }
+ pr_pack((char *)packet, cc, &from, tv);
+ if ((options & F_ONCE && nreceived) ||
+ (npackets && nreceived >= npackets))
+ break;
+ }
+ if (n == 0 || options & F_FLOOD) {
+ if (!npackets || ntransmitted < npackets)
+ pinger();
+ else {
+ if (almost_done)
+ break;
+ almost_done = 1;
+ intvl.tv_usec = 0;
+ if (nreceived) {
+ intvl.tv_sec = 2 * tmax / 1000;
+ if (!intvl.tv_sec)
+ intvl.tv_sec = 1;
+ } else
+ intvl.tv_sec = MAXWAIT;
+ }
+ (void)gettimeofday(&last, NULL);
+ if (ntransmitted - nreceived - 1 > nmissedmax) {
+ nmissedmax = ntransmitted - nreceived - 1;
+ if (options & F_MISSED)
+ (void)write(STDOUT_FILENO, &BBELL, 1);
+ }
}
- sigemptyset(&nmask);
- sigaddset(&nmask, SIGALRM);
- sigprocmask(SIG_BLOCK, &nmask, &omask);
- pr_pack((char *)packet, cc, &from);
- sigprocmask(SIG_SETMASK, &omask, NULL);
- if (npackets && nreceived >= npackets)
- break;
}
finish();
/* NOTREACHED */
+ exit(0); /* Make the compiler happy */
}
/*
- * catcher --
- * This routine causes another PING to be transmitted, and then
- * schedules another SIGALRM for 1 second from now.
- *
- * bug --
- * Our sense of time will slowly skew (i.e., packets will not be
- * launched exactly at 1-second intervals). This does not affect the
- * quality of the delay and loss statistics.
+ * stopit --
+ * Set the global bit that causes the main loop to quit.
+ * Do NOT call finish() from here, since finish() does far too much
+ * to be called from a signal handler.
*/
void
-catcher()
+stopit(sig)
+ int sig __unused;
{
- int waittime;
- pinger();
- (void)signal(SIGALRM, catcher);
- if (!npackets || ntransmitted < npackets)
- alarm((u_int)interval);
- else {
- if (nreceived) {
- waittime = 2 * tmax / 1000;
- if (!waittime)
- waittime = 1;
- } else
- waittime = MAXWAIT;
- (void)signal(SIGALRM, finish);
- (void)alarm((u_int)waittime);
- }
+ /*
+ * When doing reverse DNS lookups, the finish_up flag might not
+ * be noticed for a while. Just exit if we get a second SIGINT.
+ */
+ if (!(options & F_NUMERIC) && finish_up)
+ _exit(nreceived ? 0 : 2);
+ finish_up = 1;
}
/*
* pinger --
* Compose and transmit an ICMP ECHO REQUEST packet. The IP packet
* will be added on by the kernel. The ID field is our UNIX process ID,
- * and the sequence number is an ascending integer. The first 8 bytes
- * of the data portion are used to hold a UNIX "timeval" struct in VAX
- * byte-order, to compute the round-trip time.
+ * and the sequence number is an ascending integer. The first TIMEVAL_LEN
+ * bytes of the data portion are used to hold a UNIX "timeval" struct in
+ * host byte-order, to compute the round-trip time.
*/
-pinger()
+static void
+pinger(void)
{
- register struct icmp *icp;
- register int cc;
- int i;
+ struct timeval now;
+ struct ip *ip;
+ struct icmp *icp;
+ int cc, i;
+ u_char *packet;
+ packet = outpack;
icp = (struct icmp *)outpack;
- icp->icmp_type = ICMP_ECHO;
+ icp->icmp_type = icmp_type;
icp->icmp_code = 0;
icp->icmp_cksum = 0;
- icp->icmp_seq = ntransmitted++;
+ icp->icmp_seq = htons(ntransmitted);
icp->icmp_id = ident; /* ID */
- CLR(icp->icmp_seq % mx_dup_ck);
+ CLR(ntransmitted % mx_dup_ck);
- if (timing)
- (void)gettimeofday((struct timeval *)&outpack[8],
- (struct timezone *)NULL);
+ if ((options & F_TIME) || timing) {
+ (void)gettimeofday(&now, NULL);
- cc = datalen + 8; /* skips ICMP portion */
+ if (options & F_TIME)
+ icp->icmp_otime = htonl((now.tv_sec % (24*60*60))
+ * 1000 + now.tv_usec / 1000);
+ if (timing)
+ bcopy((void *)&now,
+ (void *)&outpack[ICMP_MINLEN + phdr_len],
+ sizeof(struct timeval));
+ }
+
+ cc = ICMP_MINLEN + phdr_len + datalen;
/* compute ICMP checksum here */
icp->icmp_cksum = in_cksum((u_short *)icp, cc);
- i = sendto(s, (char *)outpack, cc, 0, &whereto,
- sizeof(struct sockaddr));
+ if (options & F_HDRINCL) {
+ cc += sizeof(struct ip);
+ ip = (struct ip *)outpackhdr;
+ ip->ip_len = cc;
+ ip->ip_sum = in_cksum((u_short *)outpackhdr, cc);
+ packet = outpackhdr;
+ }
+ i = sendto(s, (char *)packet, cc, 0, (struct sockaddr *)&whereto,
+ sizeof(whereto));
if (i < 0 || i != cc) {
- if (i < 0)
- perror("ping: sendto");
- (void)printf("ping: wrote %s %d chars, ret=%d\n",
- hostname, cc, i);
+ if (i < 0) {
+ if (options & F_FLOOD && errno == ENOBUFS) {
+ usleep(FLOOD_BACKOFF);
+ return;
+ }
+ warn("sendto");
+ } else {
+ warn("%s: partial write: %d of %d bytes",
+ hostname, i, cc);
+ }
}
+ ntransmitted++;
if (!(options & F_QUIET) && options & F_FLOOD)
(void)write(STDOUT_FILENO, &DOT, 1);
}
* which arrive ('tis only fair). This permits multiple copies of this
* program to be run without having intermingled output (or statistics!).
*/
-pr_pack(buf, cc, from)
+static void
+pr_pack(buf, cc, from, tv)
char *buf;
int cc;
struct sockaddr_in *from;
+ struct timeval *tv;
{
- register struct icmp *icp;
- register u_long l;
- register u_int i, j;
- register u_char *cp,*dp;
- static int old_rrlen;
- static char old_rr[MAX_IPOPTLEN];
+ struct in_addr ina;
+ u_char *cp, *dp;
+ struct icmp *icp;
struct ip *ip;
- struct timeval tv, *tp;
+ const void *tp;
double triptime;
- int hlen, dupflag;
-
- (void)gettimeofday(&tv, (struct timezone *)NULL);
+ int dupflag, hlen, i, j, recv_len, seq;
+ static int old_rrlen;
+ static char old_rr[MAX_IPOPTLEN];
/* Check the IP header */
ip = (struct ip *)buf;
hlen = ip->ip_hl << 2;
+ recv_len = cc;
if (cc < hlen + ICMP_MINLEN) {
if (options & F_VERBOSE)
- (void)fprintf(stderr,
- "ping: packet too short (%d bytes) from %s\n", cc,
- inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr));
+ warn("packet too short (%d bytes) from %s", cc,
+ inet_ntoa(from->sin_addr));
return;
}
/* Now the ICMP part */
cc -= hlen;
icp = (struct icmp *)(buf + hlen);
- if (icp->icmp_type == ICMP_ECHOREPLY) {
+ if (icp->icmp_type == icmp_type_rsp) {
if (icp->icmp_id != ident)
return; /* 'Twas not our ECHO */
++nreceived;
+ triptime = 0.0;
if (timing) {
+ struct timeval tv1;
#ifndef icmp_data
- tp = (struct timeval *)&icp->icmp_ip;
+ tp = &icp->icmp_ip;
#else
- tp = (struct timeval *)icp->icmp_data;
+ tp = icp->icmp_data;
#endif
- tvsub(&tv, tp);
- triptime = ((double)tv.tv_sec) * 1000.0 +
- ((double)tv.tv_usec) / 1000.0;
- tsum += triptime;
- if (triptime < tmin)
- tmin = triptime;
- if (triptime > tmax)
- tmax = triptime;
+ tp = (const char *)tp + phdr_len;
+
+ if (cc - ICMP_MINLEN - phdr_len >= sizeof(tv1)) {
+ /* Copy to avoid alignment problems: */
+ memcpy(&tv1, tp, sizeof(tv1));
+ tvsub(tv, &tv1);
+ triptime = ((double)tv->tv_sec) * 1000.0 +
+ ((double)tv->tv_usec) / 1000.0;
+ tsum += triptime;
+ tsumsq += triptime * triptime;
+ if (triptime < tmin)
+ tmin = triptime;
+ if (triptime > tmax)
+ tmax = triptime;
+ } else
+ timing = 0;
}
- if (TST(icp->icmp_seq % mx_dup_ck)) {
+ seq = ntohs(icp->icmp_seq);
+
+ if (TST(seq % mx_dup_ck)) {
++nrepeats;
--nreceived;
dupflag = 1;
} else {
- SET(icp->icmp_seq % mx_dup_ck);
+ SET(seq % mx_dup_ck);
dupflag = 0;
}
else {
(void)printf("%d bytes from %s: icmp_seq=%u", cc,
inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr),
- icp->icmp_seq);
+ seq);
(void)printf(" ttl=%d", ip->ip_ttl);
if (timing)
- (void)printf(" time=%g ms", triptime);
+ (void)printf(" time=%.3f ms", triptime);
if (dupflag)
(void)printf(" (DUP!)");
+ if (options & F_AUDIBLE)
+ (void)write(STDOUT_FILENO, &BBELL, 1);
+ if (options & F_MASK) {
+ /* Just prentend this cast isn't ugly */
+ (void)printf(" mask=%s",
+ pr_addr(*(struct in_addr *)&(icp->icmp_mask)));
+ }
+ if (options & F_TIME) {
+ (void)printf(" tso=%s", pr_ntime(icp->icmp_otime));
+ (void)printf(" tsr=%s", pr_ntime(icp->icmp_rtime));
+ (void)printf(" tst=%s", pr_ntime(icp->icmp_ttime));
+ }
+ if (recv_len != send_len) {
+ (void)printf(
+ "\nwrong total length %d instead of %d",
+ recv_len, send_len);
+ }
/* check the data */
- cp = (u_char*)&icp->icmp_data[8];
- dp = &outpack[8 + sizeof(struct timeval)];
- for (i = 8; i < datalen; ++i, ++cp, ++dp) {
+ cp = (u_char*)&icp->icmp_data[phdr_len];
+ dp = &outpack[ICMP_MINLEN + phdr_len];
+ cc -= ICMP_MINLEN + phdr_len;
+ i = 0;
+ if (timing) { /* don't check variable timestamp */
+ cp += TIMEVAL_LEN;
+ dp += TIMEVAL_LEN;
+ cc -= TIMEVAL_LEN;
+ i += TIMEVAL_LEN;
+ }
+ for (; i < datalen && cc > 0; ++i, ++cp, ++dp, --cc) {
if (*cp != *dp) {
(void)printf("\nwrong data byte #%d should be 0x%x but was 0x%x",
i, *dp, *cp);
+ (void)printf("\ncp:");
cp = (u_char*)&icp->icmp_data[0];
- for (i = 8; i < datalen; ++i, ++cp) {
- if ((i % 32) == 8)
+ for (i = 0; i < datalen; ++i, ++cp) {
+ if ((i % 16) == 8)
+ (void)printf("\n\t");
+ (void)printf("%2x ", *cp);
+ }
+ (void)printf("\ndp:");
+ cp = &outpack[ICMP_MINLEN];
+ for (i = 0; i < datalen; ++i, ++cp) {
+ if ((i % 16) == 8)
(void)printf("\n\t");
- (void)printf("%x ", *cp);
+ (void)printf("%2x ", *cp);
}
break;
}
}
}
} else {
- /* We've got something other than an ECHOREPLY */
- if (!(options & F_VERBOSE))
- return;
- (void)printf("%d bytes from %s: ", cc,
- pr_addr(from->sin_addr.s_addr));
- pr_icmph(icp);
+ /*
+ * We've got something other than an ECHOREPLY.
+ * See if it's a reply to something that we sent.
+ * We can compare IP destination, protocol,
+ * and ICMP type and ID.
+ *
+ * Only print all the error messages if we are running
+ * as root to avoid leaking information not normally
+ * available to those not running as root.
+ */
+#ifndef icmp_data
+ struct ip *oip = &icp->icmp_ip;
+#else
+ struct ip *oip = (struct ip *)icp->icmp_data;
+#endif
+ struct icmp *oicmp = (struct icmp *)(oip + 1);
+
+ if (((options & F_VERBOSE) && uid == 0) ||
+ (!(options & F_QUIET2) &&
+ (oip->ip_dst.s_addr == whereto.sin_addr.s_addr) &&
+ (oip->ip_p == IPPROTO_ICMP) &&
+ (oicmp->icmp_type == ICMP_ECHO) &&
+ (oicmp->icmp_id == ident))) {
+ (void)printf("%d bytes from %s: ", cc,
+ pr_addr(from->sin_addr));
+ pr_icmph(icp);
+ } else
+ return;
}
/* Display any IP options */
hlen = 0;
break;
case IPOPT_LSRR:
- (void)printf("\nLSRR: ");
+ case IPOPT_SSRR:
+ (void)printf(*cp == IPOPT_LSRR ?
+ "\nLSRR: " : "\nSSRR: ");
+ j = cp[IPOPT_OLEN] - IPOPT_MINOFF + 1;
hlen -= 2;
- j = *++cp;
- ++cp;
- if (j > IPOPT_MINOFF)
+ cp += 2;
+ if (j >= INADDR_LEN &&
+ j <= hlen - (int)sizeof(struct ip)) {
for (;;) {
- l = *++cp;
- l = (l<<8) + *++cp;
- l = (l<<8) + *++cp;
- l = (l<<8) + *++cp;
- if (l == 0)
+ bcopy(++cp, &ina.s_addr, INADDR_LEN);
+ if (ina.s_addr == 0)
(void)printf("\t0.0.0.0");
- else
- (void)printf("\t%s", pr_addr(ntohl(l)));
- hlen -= 4;
- j -= 4;
- if (j <= IPOPT_MINOFF)
- break;
- (void)putchar('\n');
- }
+ else
+ (void)printf("\t%s",
+ pr_addr(ina));
+ hlen -= INADDR_LEN;
+ cp += INADDR_LEN - 1;
+ j -= INADDR_LEN;
+ if (j < INADDR_LEN)
+ break;
+ (void)putchar('\n');
+ }
+ } else
+ (void)printf("\t(truncated route)\n");
break;
case IPOPT_RR:
- j = *++cp; /* get length */
- i = *++cp; /* and pointer */
+ j = cp[IPOPT_OLEN]; /* get length */
+ i = cp[IPOPT_OFFSET]; /* and pointer */
hlen -= 2;
+ cp += 2;
if (i > j)
i = j;
- i -= IPOPT_MINOFF;
- if (i <= 0)
+ i = i - IPOPT_MINOFF + 1;
+ if (i < 0 || i > (hlen - (int)sizeof(struct ip))) {
+ old_rrlen = 0;
continue;
+ }
if (i == old_rrlen
- && cp == (u_char *)buf + sizeof(struct ip) + 2
- && !memcmp(cp, old_rr, i)
+ && !bcmp((char *)cp, old_rr, i)
&& !(options & F_FLOOD)) {
(void)printf("\t(same route)");
- i = ((i + 3) / 4) * 4;
hlen -= i;
cp += i;
break;
}
- if (i < MAX_IPOPTLEN) {
- old_rrlen = i;
- memcpy(old_rr, cp, i);
- } else
- old_rrlen = 0;
-
+ old_rrlen = i;
+ bcopy((char *)cp, old_rr, i);
(void)printf("\nRR: ");
- j = 0;
- for (;;) {
- l = *++cp;
- l = (l<<8) + *++cp;
- l = (l<<8) + *++cp;
- l = (l<<8) + *++cp;
- if (l == 0)
- (void)printf("\t0.0.0.0");
- else
- (void)printf("\t%s", pr_addr(ntohl(l)));
- hlen -= 4;
- i -= 4;
- j += 4;
- if (i <= 0)
- break;
- if (j >= MAX_IPOPTLEN) {
- (void)printf("\t(truncated route)");
- break;
+ if (i >= INADDR_LEN &&
+ i <= hlen - (int)sizeof(struct ip)) {
+ for (;;) {
+ bcopy(++cp, &ina.s_addr, INADDR_LEN);
+ if (ina.s_addr == 0)
+ (void)printf("\t0.0.0.0");
+ else
+ (void)printf("\t%s",
+ pr_addr(ina));
+ hlen -= INADDR_LEN;
+ cp += INADDR_LEN - 1;
+ i -= INADDR_LEN;
+ if (i < INADDR_LEN)
+ break;
+ (void)putchar('\n');
}
- (void)putchar('\n');
- }
+ } else
+ (void)printf("\t(truncated route)");
break;
case IPOPT_NOP:
(void)printf("\nNOP");
* in_cksum --
* Checksum routine for Internet Protocol family headers (C Version)
*/
+u_short
in_cksum(addr, len)
u_short *addr;
int len;
{
- register int nleft = len;
- register u_short *w = addr;
- register int sum = 0;
- u_short answer = 0;
+ int nleft, sum;
+ u_short *w;
+ union {
+ u_short us;
+ u_char uc[2];
+ } last;
+ u_short answer;
+
+ nleft = len;
+ sum = 0;
+ w = addr;
/*
* Our algorithm is simple, using a 32 bit accumulator (sum), we add
/* mop up an odd byte, if necessary */
if (nleft == 1) {
- *(u_char *)(&answer) = *(u_char *)w ;
- sum += answer;
+ last.uc[0] = *(u_char *)w;
+ last.uc[1] = 0;
+ sum += last.us;
}
/* add back carry outs from top 16 bits to low 16 bits */
* Subtract 2 timeval structs: out = out - in. Out is assumed to
* be >= in.
*/
+static void
tvsub(out, in)
- register struct timeval *out, *in;
+ struct timeval *out, *in;
{
+
if ((out->tv_usec -= in->tv_usec) < 0) {
--out->tv_sec;
out->tv_usec += 1000000;
out->tv_sec -= in->tv_sec;
}
+/*
+ * status --
+ * Print out statistics when SIGINFO is received.
+ */
+
+static void
+status(sig)
+ int sig __unused;
+{
+
+ siginfo_p = 1;
+}
+
+static void
+check_status()
+{
+
+ if (siginfo_p) {
+ siginfo_p = 0;
+ (void)fprintf(stderr, "\r%ld/%ld packets received (%.0f%%)",
+ nreceived, ntransmitted,
+ ntransmitted ? nreceived * 100.0 / ntransmitted : 0.0);
+ if (nreceived && timing)
+ (void)fprintf(stderr, " %.3f min / %.3f avg / %.3f max",
+ tmin, tsum / (nreceived + nrepeats), tmax);
+ (void)fprintf(stderr, "\n");
+ }
+}
+
/*
* finish --
* Print out statistics, and give up.
*/
-void
+static void
finish()
{
- register int i;
(void)signal(SIGINT, SIG_IGN);
+ (void)signal(SIGALRM, SIG_IGN);
(void)putchar('\n');
(void)fflush(stdout);
(void)printf("--- %s ping statistics ---\n", hostname);
(void)printf("%ld packets received, ", nreceived);
if (nrepeats)
(void)printf("+%ld duplicates, ", nrepeats);
- if (ntransmitted)
+ if (ntransmitted) {
if (nreceived > ntransmitted)
(void)printf("-- somebody's printing up packets!");
else
(void)printf("%d%% packet loss",
- (int) (((ntransmitted - nreceived) * 100) /
+ (int)(((ntransmitted - nreceived) * 100) /
ntransmitted));
+ }
(void)putchar('\n');
if (nreceived && timing) {
- /* Only display average to microseconds */
- i = 1000.0 * tsum / (nreceived + nrepeats);
- (void)printf("round-trip min/avg/max = %g/%g/%g ms\n",
- tmin, ((double)i) / 1000.0, tmax);
+ double n = nreceived + nrepeats;
+ double avg = tsum / n;
+ double vari = tsumsq / n - avg * avg;
+ (void)printf(
+ "round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\n",
+ tmin, avg, tmax, sqrt(vari));
}
- exit(0);
+
+ if (nreceived)
+ exit(0);
+ else
+ exit(2);
}
#ifdef notdef
* pr_icmph --
* Print a descriptive string about an ICMP header.
*/
+static void
pr_icmph(icp)
struct icmp *icp;
{
+
switch(icp->icmp_type) {
case ICMP_ECHOREPLY:
(void)printf("Echo Reply\n");
(void)printf("Destination Port Unreachable\n");
break;
case ICMP_UNREACH_NEEDFRAG:
- (void)printf("frag needed and DF set\n");
+ (void)printf("frag needed and DF set (MTU %d)\n",
+ ntohs(icp->icmp_nextmtu));
break;
case ICMP_UNREACH_SRCFAIL:
(void)printf("Source Route Failed\n");
break;
+ case ICMP_UNREACH_FILTER_PROHIB:
+ (void)printf("Communication prohibited by filter\n");
+ break;
default:
(void)printf("Dest Unreachable, Bad Code: %d\n",
icp->icmp_code);
(void)printf("Redirect, Bad Code: %d", icp->icmp_code);
break;
}
- (void)printf("(New addr: 0x%08lx)\n", icp->icmp_gwaddr.s_addr);
+ (void)printf("(New addr: %s)\n", inet_ntoa(icp->icmp_gwaddr));
#ifndef icmp_data
pr_retip(&icp->icmp_ip);
#else
(void)printf("Information Reply\n");
/* XXX ID + Seq */
break;
-#ifdef ICMP_MASKREQ
case ICMP_MASKREQ:
(void)printf("Address Mask Request\n");
break;
-#endif
-#ifdef ICMP_MASKREPLY
case ICMP_MASKREPLY:
(void)printf("Address Mask Reply\n");
break;
-#endif
+ case ICMP_ROUTERADVERT:
+ (void)printf("Router Advertisement\n");
+ break;
+ case ICMP_ROUTERSOLICIT:
+ (void)printf("Router Solicitation\n");
+ break;
default:
(void)printf("Bad ICMP type: %d\n", icp->icmp_type);
}
* pr_iph --
* Print an IP header with options.
*/
+static void
pr_iph(ip)
struct ip *ip;
{
- int hlen;
u_char *cp;
+ int hlen;
hlen = ip->ip_hl << 2;
cp = (u_char *)ip + 20; /* point to options */
- (void)printf("Vr HL TOS Len ID Flg off TTL Pro cks Src Dst Data\n");
+ (void)printf("Vr HL TOS Len ID Flg off TTL Pro cks Src Dst\n");
(void)printf(" %1x %1x %02x %04x %04x",
- ip->ip_v, ip->ip_hl, ip->ip_tos, ip->ip_len, ip->ip_id);
- (void)printf(" %1x %04x", ((ip->ip_off) & 0xe000) >> 13,
- (ip->ip_off) & 0x1fff);
- (void)printf(" %02x %02x %04x", ip->ip_ttl, ip->ip_p, ip->ip_sum);
+ ip->ip_v, ip->ip_hl, ip->ip_tos, ntohs(ip->ip_len),
+ ntohs(ip->ip_id));
+ (void)printf(" %1lx %04lx",
+ (u_long) (ntohl(ip->ip_off) & 0xe000) >> 13,
+ (u_long) ntohl(ip->ip_off) & 0x1fff);
+ (void)printf(" %02x %02x %04x", ip->ip_ttl, ip->ip_p,
+ ntohs(ip->ip_sum));
(void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_src.s_addr));
(void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_dst.s_addr));
- /* dump and option bytes */
+ /* dump any option bytes */
while (hlen-- > 20) {
(void)printf("%02x", *cp++);
}
* Return an ascii host address as a dotted quad and optionally with
* a hostname.
*/
-char *
-pr_addr(l)
- u_long l;
+static char *
+pr_addr(ina)
+ struct in_addr ina;
{
struct hostent *hp;
- static char buf[80];
+ static char buf[16 + 3 + MAXHOSTNAMELEN];
if ((options & F_NUMERIC) ||
- !(hp = gethostbyaddr((char *)&l, 4, AF_INET)))
- (void)sprintf(buf, "%s", inet_ntoa(*(struct in_addr *)&l));
+ !(hp = gethostbyaddr((char *)&ina, 4, AF_INET)))
+ return inet_ntoa(ina);
else
- (void)sprintf(buf, "%s (%s)", hp->h_name,
- inet_ntoa(*(struct in_addr *)&l));
+ (void)snprintf(buf, sizeof(buf), "%s (%s)", hp->h_name,
+ inet_ntoa(ina));
return(buf);
}
* pr_retip --
* Dump some info on a returned (via ICMP) IP packet.
*/
+static void
pr_retip(ip)
struct ip *ip;
{
- int hlen;
u_char *cp;
+ int hlen;
pr_iph(ip);
hlen = ip->ip_hl << 2;
(*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3)));
}
+static char *
+pr_ntime (n_time timestamp)
+{
+ static char buf[10];
+ int hour, min, sec;
+
+ sec = ntohl(timestamp) / 1000;
+ hour = sec / 60 / 60;
+ min = (sec % (60 * 60)) / 60;
+ sec = (sec % (60 * 60)) % 60;
+
+ (void)snprintf(buf, sizeof(buf), "%02d:%02d:%02d", hour, min, sec);
+
+ return (buf);
+}
+
+static void
fill(bp, patp)
char *bp, *patp;
{
- register int ii, jj, kk;
- int pat[16];
char *cp;
+ int pat[16];
+ u_int ii, jj, kk;
- for (cp = patp; *cp; cp++)
- if (!isxdigit(*cp)) {
- (void)fprintf(stderr,
- "ping: patterns must be specified as hex digits.\n");
- exit(1);
- }
+ for (cp = patp; *cp; cp++) {
+ if (!isxdigit(*cp))
+ errx(EX_USAGE,
+ "patterns must be specified as hex digits");
+
+ }
ii = sscanf(patp,
"%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
&pat[0], &pat[1], &pat[2], &pat[3], &pat[4], &pat[5], &pat[6],
&pat[13], &pat[14], &pat[15]);
if (ii > 0)
- for (kk = 0;
- kk <= MAXPACKET - (8 + sizeof(struct timeval) + ii);
- kk += ii)
+ for (kk = 0; kk <= maxpayload - (TIMEVAL_LEN + ii); kk += ii)
for (jj = 0; jj < ii; ++jj)
bp[jj + kk] = pat[jj];
if (!(options & F_QUIET)) {
}
}
+#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
+#define SECOPT " [-P policy]"
+#else
+#define SECOPT ""
+#endif
+static void
usage()
{
- (void)fprintf(stderr,
- "usage: ping [-Rdfnqrv] [-c count] [-i wait] [-l preload]\n\t[-p pattern] [-s packetsize] host\n");
- exit(1);
+
+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n",
+"usage: ping [-AaDdfnoQqRrv] [-c count] [-i wait] [-l preload] [-M mask | time]",
+" [-m ttl]" SECOPT " [-p pattern] [-S src_addr] [-s packetsize]",
+" [-t timeout] [-z tos] host",
+" ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]",
+" [-M mask | time] [-m ttl]" SECOPT " [-p pattern] [-S src_addr]",
+" [-s packetsize] [-T ttl] [-t timeout] [-z tos] mcast-group");
+ exit(EX_USAGE);
}
schedule.h session.h sha2.h sockmisc.h str2val.h strnames.h\
vendorid.h vmbuf.h admin_var.h cftoken.h debug.h dhgroup.h\
gcmalloc.h isakmp_var.h libpfkey.h netdb_dnssec.h\
- rijndael_local.h rijndael.h var.h isakmp_natd.h
+ rijndael_local.h rijndael.h var.h isakmp_natd.h crypto_cssm.h\
+ open_dir.h
OTHERLINKED = cfparse.y cftoken.l
pfkey2.c pfkey_dump.c plog.c policy.c proposal.c\
remoteconf.c rijndael-alg-fst.c rijndael-api-fst.c safefile.c\
sainfo.c schedule.c session.c sha2.c sockmisc.c str2val.c\
- strnames.c vendorid.c vmbuf.c isakmp_natd.c
+ strnames.c vendorid.c vmbuf.c isakmp_natd.c crypto_cssm.c\
+ open_dir.c
OTHERSRCS = Makefile.preamble Makefile Makefile.postamble boxes-fst.dat\
psk.txt racoon.8 racoon.conf anonymous.conf racoon.conf.5
DEBUG_LIBS = $(LIBS)
PROF_LIBS = $(LIBS)
-FRAMEWORKS = -framework CoreFoundation -framework Security
+HEADER_PATHS =\
+ -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/
+FRAMEWORKS = -framework CoreFoundation -framework Security -framework DirectoryService
NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc
"rijndael_local.h",
"rijndael.h",
"var.h",
- "isakmp_natd.h"
+ "isakmp_natd.h",
+ "crypto_cssm.h",
+ "open_dir.h"
);
"OTHER_LIBS" = (crypto, ipsec, ssl);
"OTHER_LINKED" = (
"strnames.c",
"vendorid.c",
"vmbuf.c",
- "isakmp_natd.c"
+ "isakmp_natd.c",
+ "crypto_cssm.c",
+ "open_dir.c"
);
"OTHER_SOURCES" = (
"Makefile.preamble",
* SUCH DAMAGE.
*/
+#ifndef __ADMIN_H__
+#define __ADMIN_H__
+
+
/* command for administration. */
/* NOTE: host byte order. */
struct admin_com {
};
extern int admin2pfkey_proto __P((u_int));
+
+
+#endif /* __ADMIN_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __ADMIN_VAR_H__
+#define __ADMIN_VAR_H__
+
+
#define PORT_ADMIN "/tmp/.racoon"
extern int admin_handler __P((void));
extern int admin_init __P((void));
extern int admin_close __P((void));
+
+
+#endif /*__ADMIN_VAR_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __ALGORITHM_H__
+#define __ALGORITHM_H__
+
/* algorithm class */
enum {
algclass_ipsec_enc,
extern int check_keylen __P((int, int, int));
extern int algtype2doi __P((int, int));
extern int algclass2doi __P((int));
+
+
+#endif /* __ALGORITHM_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __ARC4RANDOM_H__
+#define __ARC4RANDOM_H__
+
extern u_int32_t arc4random __P((void));
+
+
+#endif /* __ARC4RANDOM_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __BACKUPSA_H__
+#define __BACKUPSA_H__
+
+
extern int backupsa_to_file __P((u_int, u_int,
struct sockaddr *, struct sockaddr *, u_int32_t, u_int32_t, u_int,
caddr_t, u_int, u_int, u_int, u_int, u_int,
u_int32_t, u_int64_t, u_int64_t, u_int64_t, u_int32_t));
extern int backupsa_from_file __P((void));
extern int backupsa_clean __P((void));
+
+
+#endif /* __BACKUPSA_H__ */
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO)
#include "gssapi.h"
#endif
#include "vendorid.h"
+#include <CoreFoundation/CFData.h>
struct proposalspec {
time_t lifetime; /* for isakmp/ipsec */
static void clean_tmpalgtype __P((void));
static int expand_isakmpspec __P((int, int, int *,
int, int, time_t, int, int, int, char *, struct remoteconf *));
+
+static int base64toCFData(vchar_t *, CFDataRef*);
#if 0
static int fix_lifebyte __P((u_long));
%token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE VERIFY_CERT SEND_CERT SEND_CR
%token IDENTIFIERTYPE MY_IDENTIFIER PEERS_IDENTIFIER VERIFY_IDENTIFIER
%token SHARED_SECRET SECRETTYPE
+%token OPEN_DIR_AUTH_GROUP IN_KEYCHAIN
+%token CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
%token DNSSEC CERT_X509
%token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
%token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
%type <num> ul_proto UL_PROTO
%type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE
%type <num> CERTTYPE CERT_X509 PROPOSAL_CHECK_LEVEL
+%type <num> VERIFICATION_MODULE VERIFICATION_OPTION
%type <num> unittype_time unittype_byte
%type <val> QUOTEDSTRING HEXSTRING ADDRSTRING sainfo_id
%type <val> identifierstring
delmyaddr(p);
return -1;
}
-
+ p->sock = -1;
+ p->nattsock = -1;
+ p->addrcount = 1;
insmyaddr(p, &lcconf->myaddrs);
lcconf->autograbaddr = 0;
{
struct remoteconf *new;
struct proposalspec *prspec;
-
+
new = newrmconf();
if (new == NULL) {
yyerror("failed to get new remoteconf.");
}
if (cur_rmconf->idvtype == IDTYPE_ASN1DN
- && cur_rmconf->mycertfile == NULL) {
+ && cur_rmconf->mycertfile == NULL
+ && cur_rmconf->identity_in_keychain == 0) {
yyerror("id type mismatched due to "
"no CERT defined.\n");
return -1;
}
+
+ if (cur_rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER
+ && cur_rmconf->idv_p == NULL) {
+ yyerror("peers_identifier required for specified certificate "
+ "verification option.\n");
+ return -1;
+ }
if (set_isakmp_proposal(cur_rmconf, prhead) != 0)
return -1;
| VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
| SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
| SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
+ | CERTIFICATE_VERIFICATION VERIFICATION_MODULE { cur_rmconf->cert_verification = $2; } EOS
+ | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
+ {
+ cur_rmconf->cert_verification = $2;
+ cur_rmconf->cert_verification_option = $3;
+ }
+ EOS
+ | OPEN_DIR_AUTH_GROUP QUOTEDSTRING { cur_rmconf->open_dir_auth_group = $2; } EOS
| IDENTIFIER IDENTIFIERTYPE
{
/*XXX to be deleted */
{
if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
yyerror("failed to set identifer.\n");
+ vfree($3);
return -1;
}
vfree($3);
{
if (set_identifier(&cur_rmconf->idv_p, $2, $3) != 0) {
yyerror("failed to set identifer.\n");
+ vfree($3);
return -1;
}
vfree($3);
#endif
}
EOS
+ | CERT_X509 IN_KEYCHAIN
+ {
+ cur_rmconf->certtype = $1;
+ cur_rmconf->identity_in_keychain = 1;
+ cur_rmconf->keychainCertRef = 0;
+ }
+ EOS
+ ;
+ | CERT_X509 IN_KEYCHAIN QUOTEDSTRING
+ {
+ int result;
+
+ cur_rmconf->certtype = $1;
+ cur_rmconf->identity_in_keychain = 1;
+ result = base64toCFData($3, &cur_rmconf->keychainCertRef);
+ vfree($3);
+ if (result)
+ return -1;
+ }
+ EOS
;
+
dh_group_num
: ALGORITHMTYPE
{
return(cfparse());
}
+
+/* -----------------------------------------------------------------------------
+The base-64 encoding packs three 8-bit bytes into four 7-bit ASCII
+characters. If the number of bytes in the original data isn't divisable
+by three, "=" characters are used to pad the encoded data. The complete
+set of characters used in base-64 are:
+ 'A'..'Z' => 00..25
+ 'a'..'z' => 26..51
+ '0'..'9' => 52..61
+ '+' => 62
+ '/' => 63
+ '=' => pad
+
+----------------------------------------------------------------------------- */
+static const signed char base64_DecodeTable[128] = {
+ /* 000 */ -1, -1, -1, -1, -1, -1, -1, -1,
+ /* 010 */ -1, -1, -1, -1, -1, -1, -1, -1,
+ /* 020 */ -1, -1, -1, -1, -1, -1, -1, -1,
+ /* 030 */ -1, -1, -1, -1, -1, -1, -1, -1,
+ /* ' ' */ -1, -1, -1, -1, -1, -1, -1, -1,
+ /* '(' */ -1, -1, -1, 62, -1, -1, -1, 63,
+ /* '0' */ 52, 53, 54, 55, 56, 57, 58, 59,
+ /* '8' */ 60, 61, -1, -1, -1, 0, -1, -1,
+ /* '@' */ -1, 0, 1, 2, 3, 4, 5, 6,
+ /* 'H' */ 7, 8, 9, 10, 11, 12, 13, 14,
+ /* 'P' */ 15, 16, 17, 18, 19, 20, 21, 22,
+ /* 'X' */ 23, 24, 25, -1, -1, -1, -1, -1,
+ /* '`' */ -1, 26, 27, 28, 29, 30, 31, 32,
+ /* 'h' */ 33, 34, 35, 36, 37, 38, 39, 40,
+ /* 'p' */ 41, 42, 43, 44, 45, 46, 47, 48,
+ /* 'x' */ 49, 50, 51, -1, -1, -1, -1, -1
+};
+
+static int base64toCFData(vchar_t *textin, CFDataRef *dataRef)
+{
+ uint8_t *tmpbuf;
+ uint8_t c;
+ int tmpbufpos = 0;
+ int numeq = 0;
+ int acc = 0;
+ int cntr = 0;
+ uint8_t *textcur = textin->v;
+ int len = textin->l;
+ int i;
+
+ tmpbuf = malloc(len); // len of result will be less than encoded len
+ if (tmpbuf == NULL) {
+ yyerror("memory error - could not allocate buffer for certificate reference conversion from base-64.");
+ return -1;
+ }
+
+ for (i = 0; i < len; i++) {
+ c = *(textcur++);
+ if (c == '=')
+ numeq++;
+ else if (!isspace(c))
+ numeq = 0;
+ if (base64_DecodeTable[c] < 0)
+ continue;
+ cntr++;
+ acc <<= 6;
+ acc += base64_DecodeTable[c];
+ if (0 == (cntr & 0x3)) {
+ tmpbuf[tmpbufpos++] = (acc >> 16) & 0xff;
+ if (numeq < 2)
+ tmpbuf[tmpbufpos++] = (acc >> 8) & 0xff;
+ if (numeq < 1)
+ tmpbuf[tmpbufpos++] = acc & 0xff;
+ }
+ }
+ *dataRef = CFDataCreate(NULL, tmpbuf, tmpbufpos);
+ free(tmpbuf);
+ return 0;
+
+}
+
* SUCH DAMAGE.
*/
+#ifndef __CFTOKEN_H__
+#define __CFTOKEN_H__
+
+
extern int yyerrorcount;
extern int yylex __P((void));
extern int yycf_set_buffer __P((char *));
extern void yycf_init_buffer __P((void));
extern void yycf_clean_buffer __P((void));
+
+
+#endif /* __CFTOKEN_H__ */
+
static int yy_first_time = 1;
%}
-/* common seciton */
+/* common section */
nl \n
ws [ \t]+
digit [0-9]
<S_RMTS>my_identifier { YYD; return(MY_IDENTIFIER); }
<S_RMTS>peers_identifier { YYD; return(PEERS_IDENTIFIER); }
<S_RMTS>verify_identifier { YYD; return(VERIFY_IDENTIFIER); }
+<S_RMTS>open_dir_auth_group { YYD; return(OPEN_DIR_AUTH_GROUP); }
<S_RMTS>certificate_type { YYD; return(CERTIFICATE_TYPE); }
<S_RMTS>shared_secret { YYD; return(SHARED_SECRET); }
<S_RMTS>x509 { YYD; yylval.num = ISAKMP_CERT_X509SIGN; return(CERT_X509); }
+<S_RMTS>in_keychain { YYD; return(IN_KEYCHAIN); }
+<S_RMTS>certificate_verification { YYD; return(CERTIFICATE_VERIFICATION); }
<S_RMTS>peers_certfile { YYD; return(PEERS_CERTFILE); }
<S_RMTS>dnssec { YYD; return(DNSSEC); }
<S_RMTS>verify_cert { YYD; return(VERIFY_CERT); }
key { YYD; yylval.num = SECRETTYPE_KEY; return(SECRETTYPE); }
keychain { YYD; yylval.num = SECRETTYPE_KEYCHAIN; return(SECRETTYPE); }
+ /* certificate verification */
+openssl { YYD; yylval.num = VERIFICATION_MODULE_OPENSSL; return(VERIFICATION_MODULE); }
+sec_framework { YYD; yylval.num = VERIFICATION_MODULE_SEC_FRAMEWORK; return(VERIFICATION_MODULE); }
+use_open_dir { YYD; yylval.num = VERIFICATION_OPTION_OPEN_DIR; return(VERIFICATION_OPTION); }
+use_peers_identifier { YYD; yylval.num = VERIFICATION_OPTION_PEERS_IDENTIFIER; return(VERIFICATION_OPTION); }
+
/* units */
B|byte|bytes { YYD; return(UNITTYPE_BYTE); }
KB { YYD; return(UNITTYPE_KBYTES); }
--- /dev/null
+
+/*
+ * Copyright (c) 2001-2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+
+/*
+ * Racoon module for verifying and signing certificates through Security
+ * Framework and CSSM
+ */
+
+#include <Security/SecBase.h>
+#include <Security/SecCertificate.h>
+#include <Security/SecPolicy.h>
+#include <Security/SecIdentity.h>
+#include <Security/SecIdentityPriv.h>
+#include <Security/SecIdentitySearch.h>
+#include <Security/SecKeychain.h>
+#include <Security/SecKeychainItem.h>
+#include <Security/SecKeychainItemPriv.h>
+#include <Security/SecKey.h>
+#include <Security/SecKeyPriv.h>
+#include <Security/SecTrust.h>
+#include <Security/oidsalg.h>
+#include <Security/cssmapi.h>
+#include <Security/SecPolicySearch.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
+#include "plog.h"
+#include "debug.h"
+#include "misc.h"
+
+#include "crypto_cssm.h"
+
+
+
+static OSStatus FindPolicy(const CSSM_OID *policyOID, SecPolicyRef *policyRef);
+static OSStatus EvaluateCert(SecCertificateRef cert, CFTypeRef policyRef);
+static OSStatus CopySystemKeychain(SecKeychainRef *keychainRef);
+static const char *GetSecurityErrorString(OSStatus err);
+
+
+/*
+ * Verify cert using security framework
+ */
+int crypto_cssm_check_x509cert(vchar_t *cert)
+{
+ OSStatus status;
+ SecCertificateRef certRef = 0;
+ CSSM_DATA certData;
+ CSSM_OID ourPolicyOID = CSSMOID_APPLE_TP_IP_SEC;
+ SecPolicyRef policyRef = 0;
+
+ // create cert ref
+ certData.Length = cert->l;
+ certData.Data = cert->v;
+ status = SecCertificateCreateFromData(&certData, CSSM_CERT_X_509v3, CSSM_CERT_ENCODING_DER,
+ &certRef);
+ if (status != noErr)
+ goto end;
+
+ // get our policy object
+ status = FindPolicy(&ourPolicyOID, &policyRef);
+ if (status != noErr)
+ goto end;
+
+ // setup policy options ???
+ // no options used at present - verification of subjectAltName fields, etc.
+ // are done elsewhere in racoon in oakley_check_certid()
+
+ // evaluate cert
+ status = EvaluateCert(certRef, policyRef);
+
+
+end:
+
+ if (certRef)
+ CFRelease(certRef);
+ if (policyRef)
+ CFRelease(policyRef);
+
+ if (status != noErr && status != -1) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "error %d %s.\n", status, GetSecurityErrorString(status));
+ status = -1;
+ }
+ return status;
+
+}
+
+/*
+ * Encrypt a hash via CSSM using the private key in the keychain
+ * from an identity.
+ */
+vchar_t* crypto_cssm_getsign(CFDataRef persistentCertRef, vchar_t* hash)
+{
+
+ OSStatus status;
+ SecCertificateRef certificateRef = NULL;
+ SecIdentityRef identityRef = NULL;
+ SecIdentitySearchRef idSearchRef = NULL;
+ SecKeychainRef keychainRef = NULL;
+ SecKeyRef privateKeyRef = NULL;
+ const CSSM_KEY *cssmKey = NULL;
+ CSSM_CSP_HANDLE cspHandle = nil;
+ CSSM_CC_HANDLE cssmContextHandle = nil;
+ const CSSM_ACCESS_CREDENTIALS *credentials = NULL;
+ uint32 bytesEncrypted = 0;
+ CSSM_DATA clearData;
+ CSSM_DATA cipherData;
+ CSSM_DATA remData;
+ CSSM_CONTEXT_ATTRIBUTE newAttr;
+ vchar_t *sig = NULL;
+
+ remData.Length = 0;
+ remData.Data = 0;
+
+ if (persistentCertRef) {
+ // get cert from keychain
+ status = SecKeychainItemCopyFromPersistentReference(persistentCertRef, (SecKeychainItemRef*)&certificateRef);
+ if (status != noErr)
+ goto end;
+
+ // get keychain ref where cert is contained
+ status = SecKeychainItemCopyKeychain((SecKeychainItemRef)certificateRef, &keychainRef);
+ if (status != noErr)
+ goto end;
+
+ // get identity from the certificate
+ status = SecIdentityCreateWithCertificate(keychainRef, certificateRef, &identityRef);
+ if (status != noErr)
+ goto end;
+
+ } else {
+ // copy system keychain
+ status = CopySystemKeychain(&keychainRef);
+ if (status != noErr)
+ goto end;
+
+ // serach for first identity in system keychain
+ status = SecIdentitySearchCreate(keychainRef, CSSM_KEYUSE_SIGN, &idSearchRef);
+ if (status != noErr)
+ goto end;
+
+ status = SecIdentitySearchCopyNext(idSearchRef, &identityRef);
+ if (status != noErr)
+ goto end;
+
+ // get certificate from identity
+ status = SecIdentityCopyCertificate(identityRef, &certificateRef);
+ if (status != noErr)
+ goto end;
+ }
+
+
+ // get private key from identity
+ status = SecIdentityCopyPrivateKey(identityRef, &privateKeyRef);
+ if (status != noErr)
+ goto end;
+
+ // get CSSM_KEY pointer from key ref
+ status = SecKeyGetCSSMKey(privateKeyRef, &cssmKey);
+ if (status != noErr)
+ goto end;
+
+ // get CSSM CSP handle
+ status = SecKeychainGetCSPHandle(keychainRef, &cspHandle);
+ if (status != noErr)
+ goto end;
+
+ // create CSSM credentials to unlock private key for encryption - no UI to be used
+ status = SecKeyGetCredentials(privateKeyRef, CSSM_ACL_AUTHORIZATION_ENCRYPT,
+ kSecCredentialTypeNoUI, &credentials);
+ if (status != noErr)
+ goto end;
+
+ // create asymmetric context for encryption
+ status = CSSM_CSP_CreateAsymmetricContext(cspHandle, CSSM_ALGID_RSA, credentials, cssmKey,
+ CSSM_PADDING_PKCS1, &cssmContextHandle);
+ if (status != noErr)
+ goto end;
+
+ // add mode attribute to use private key for encryption
+ newAttr.AttributeType = CSSM_ATTRIBUTE_MODE;
+ newAttr.AttributeLength = sizeof(uint32);
+ newAttr.Attribute.Data = (CSSM_DATA_PTR)CSSM_ALGMODE_PRIVATE_KEY;
+ status = CSSM_UpdateContextAttributes(cssmContextHandle, 1, &newAttr);
+ if(status != noErr)
+ goto end;
+
+ // and finally - encrypt data
+ clearData.Length = hash->l;
+ clearData.Data = hash->v;
+ cipherData.Length = 0;
+ cipherData.Data = NULL;
+ status = CSSM_EncryptData(cssmContextHandle, &clearData, 1, &cipherData, 1, &bytesEncrypted,
+ &remData);
+ if (status != noErr)
+ goto end;
+
+ if (remData.Length != 0) { // something didn't go right - should be zero
+ status = -1;
+ plog(LLV_ERROR, LOCATION, NULL,
+ "unencrypted data remaining after encrypting hash.\n");
+ goto end;
+ }
+
+ // alloc buffer for result
+ sig = vmalloc(cipherData.Length);
+ if (sig == NULL)
+ goto end;
+
+ sig->v = cipherData.Data;
+
+end:
+ if (certificateRef)
+ CFRelease(certificateRef);
+ if (keychainRef)
+ CFRelease(keychainRef);
+ if (identityRef)
+ CFRelease(identityRef);
+ if (privateKeyRef)
+ CFRelease(privateKeyRef);
+ if (idSearchRef)
+ CFRelease(idSearchRef);
+ if (cssmContextHandle)
+ CSSM_DeleteContext(cssmContextHandle);
+ if (status != noErr) {
+ if (sig) {
+ vfree(sig);
+ sig = NULL;
+ }
+ }
+
+ if (status != noErr && status != -1) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "error %d %s.\n", status, GetSecurityErrorString(status));
+ status = -1;
+ }
+ return sig;
+
+}
+
+
+/*
+ * Retrieve a cert from the keychain
+ */
+vchar_t* crypto_cssm_get_x509cert(CFDataRef persistentCertRef)
+{
+
+ OSStatus status;
+ CSSM_DATA cssmData;
+ vchar_t *cert = NULL;
+ SecIdentityRef identityRef = NULL;
+ SecIdentitySearchRef idSearchRef = NULL;
+ SecKeychainRef keychainRef = NULL;
+ SecCertificateRef certificateRef = NULL;
+
+
+ // get cert ref
+ if (persistentCertRef) {
+ status = SecKeychainItemCopyFromPersistentReference(persistentCertRef, (SecKeychainItemRef*)&certificateRef);
+ if (status != noErr)
+ goto end;
+ } else {
+ // copy system keychain
+ status = CopySystemKeychain(&keychainRef);
+ if (status != noErr)
+ goto end;
+
+ // find first identity in system keychain
+ status = SecIdentitySearchCreate(keychainRef, CSSM_KEYUSE_SIGN, &idSearchRef);
+ if (status != noErr)
+ goto end;
+
+ status = SecIdentitySearchCopyNext(idSearchRef, &identityRef);
+ if (status != noErr)
+ goto end;
+
+ // get certificate from identity
+ status = SecIdentityCopyCertificate(identityRef, &certificateRef);
+ if (status != noErr)
+ goto end;
+
+ }
+
+ // get certificate data
+ cssmData.Length = 0;
+ cssmData.Data = NULL;
+ status = SecCertificateGetData(certificateRef, &cssmData);
+ if (status != noErr)
+ goto end;
+
+ if (cssmData.Length == 0)
+ goto end;
+
+ cert = vmalloc(cssmData.Length);
+ if (cert == NULL)
+ goto end;
+
+ // cssmData struct just points to the data
+ // data must be copied to be returned
+ memcpy(cert->v, cssmData.Data, cssmData.Length);
+
+end:
+ if (certificateRef)
+ CFRelease(certificateRef);
+ if (identityRef)
+ CFRelease(identityRef);
+ if (idSearchRef)
+ CFRelease(idSearchRef);
+ if (keychainRef)
+ CFRelease(keychainRef);
+
+ if (status != noErr && status != -1) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "error %d %s.\n", status, GetSecurityErrorString(status));
+ status = -1;
+ }
+ return cert;
+
+}
+
+
+/*
+ * Find a policy ref by OID
+ */
+static OSStatus FindPolicy(const CSSM_OID *policyOID, SecPolicyRef *policyRef)
+{
+
+ OSStatus status;
+ SecPolicySearchRef searchRef = nil;
+
+ status = SecPolicySearchCreate(CSSM_CERT_X_509v3, policyOID, NULL, &searchRef);
+ if (status != noErr)
+ goto end;
+
+ status = SecPolicySearchCopyNext(searchRef, policyRef);
+
+end:
+ if (searchRef)
+ CFRelease(searchRef);
+
+ if (status != noErr) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "error %d %s.\n", status, GetSecurityErrorString(status));
+ status = -1;
+ }
+ return status;
+}
+
+
+/*
+ * Evaluate the trust of a cert using the policy provided
+ */
+static OSStatus EvaluateCert(SecCertificateRef cert, CFTypeRef policyRef)
+{
+ OSStatus status;
+ SecTrustRef trustRef = 0;
+ SecTrustResultType evalResult;
+
+ SecCertificateRef evalCertArray[1] = { cert };
+
+ CFArrayRef cfCertRef = CFArrayCreate((CFAllocatorRef) NULL, (void*)evalCertArray, 1,
+ &kCFTypeArrayCallBacks);
+
+ if (!cfCertRef) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "unable to create CFArray.\n");
+ return -1;
+ }
+
+ status = SecTrustCreateWithCertificates(cfCertRef, policyRef, &trustRef);
+ if (status != noErr)
+ goto end;
+
+ status = SecTrustEvaluate(trustRef, &evalResult);
+ if (status != noErr)
+ goto end;
+
+ if (evalResult != kSecTrustResultProceed && evalResult != kSecTrustResultUnspecified) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "error evaluating certificate.\n");
+ status = -1;
+ }
+
+
+end:
+ if (cfCertRef)
+ CFRelease(cfCertRef);
+ if (trustRef)
+ CFRelease(trustRef);
+
+ if (status != noErr && status != -1) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "error %d %s.\n", status, GetSecurityErrorString(status));
+ status = -1;
+ }
+ return status;
+}
+
+
+/*
+ * Copy the system keychain
+ */
+static OSStatus CopySystemKeychain(SecKeychainRef *keychainRef)
+{
+
+ OSStatus status;
+
+ status = SecKeychainSetPreferenceDomain(kSecPreferencesDomainSystem);
+ if (status != noErr)
+ goto end;
+
+ status = SecKeychainCopyDomainDefault(kSecPreferencesDomainSystem, keychainRef);
+
+end:
+
+ if (status != noErr) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "error %d %s.\n", status, GetSecurityErrorString(status));
+ status = -1;
+ }
+ return status;
+
+}
+
+
+/*
+ * Return string representation of Security-related OSStatus.
+ */
+const char *
+GetSecurityErrorString(OSStatus err)
+{
+ switch(err) {
+ case noErr:
+ return "noErr";
+ case memFullErr:
+ return "memFullErr";
+ case paramErr:
+ return "paramErr";
+ case unimpErr:
+ return "unimpErr";
+
+ /* SecBase.h: */
+ case errSecNotAvailable:
+ return "errSecNotAvailable";
+ case errSecReadOnly:
+ return "errSecReadOnly";
+ case errSecAuthFailed:
+ return "errSecAuthFailed";
+ case errSecNoSuchKeychain:
+ return "errSecNoSuchKeychain";
+ case errSecInvalidKeychain:
+ return "errSecInvalidKeychain";
+ case errSecDuplicateKeychain:
+ return "errSecDuplicateKeychain";
+ case errSecDuplicateCallback:
+ return "errSecDuplicateCallback";
+ case errSecInvalidCallback:
+ return "errSecInvalidCallback";
+ case errSecDuplicateItem:
+ return "errSecDuplicateItem";
+ case errSecItemNotFound:
+ return "errSecItemNotFound";
+ case errSecBufferTooSmall:
+ return "errSecBufferTooSmall";
+ case errSecDataTooLarge:
+ return "errSecDataTooLarge";
+ case errSecNoSuchAttr:
+ return "errSecNoSuchAttr";
+ case errSecInvalidItemRef:
+ return "errSecInvalidItemRef";
+ case errSecInvalidSearchRef:
+ return "errSecInvalidSearchRef";
+ case errSecNoSuchClass:
+ return "errSecNoSuchClass";
+ case errSecNoDefaultKeychain:
+ return "errSecNoDefaultKeychain";
+ case errSecInteractionNotAllowed:
+ return "errSecInteractionNotAllowed";
+ case errSecReadOnlyAttr:
+ return "errSecReadOnlyAttr";
+ case errSecWrongSecVersion:
+ return "errSecWrongSecVersion";
+ case errSecKeySizeNotAllowed:
+ return "errSecKeySizeNotAllowed";
+ case errSecNoStorageModule:
+ return "errSecNoStorageModule";
+ case errSecNoCertificateModule:
+ return "errSecNoCertificateModule";
+ case errSecNoPolicyModule:
+ return "errSecNoPolicyModule";
+ case errSecInteractionRequired:
+ return "errSecInteractionRequired";
+ case errSecDataNotAvailable:
+ return "errSecDataNotAvailable";
+ case errSecDataNotModifiable:
+ return "errSecDataNotModifiable";
+ case errSecCreateChainFailed:
+ return "errSecCreateChainFailed";
+ case errSecACLNotSimple:
+ return "errSecACLNotSimple";
+ case errSecPolicyNotFound:
+ return "errSecPolicyNotFound";
+ case errSecInvalidTrustSetting:
+ return "errSecInvalidTrustSetting";
+ case errSecNoAccessForItem:
+ return "errSecNoAccessForItem";
+ case errSecInvalidOwnerEdit:
+ return "errSecInvalidOwnerEdit";
+ default:
+ return "<unknown>";
+ }
+}
+
--- /dev/null
+
+/*
+ * Copyright (c) 2001-2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef __CRYPTO_CSSM_H__
+#define __CRYPTO_CSSM_H__
+
+/*
+ * Racoon module for verifying and signing certificates through Security
+ * Framework and CSSM
+ */
+
+#include "vmbuf.h"
+
+
+extern int crypto_cssm_check_x509cert(vchar_t *cert);
+extern vchar_t* crypto_cssm_getsign(CFDataRef persistentCertRef, vchar_t* hash);
+extern vchar_t* crypto_cssm_get_x509cert(CFDataRef persistentCertRef);
+
+
+#endif /* __CRYPTO_CSSM_H__ */
+
#endif
#ifdef HAVE_OPENSSL_X509_H
#include <openssl/x509.h>
+#include <openssl/x509v3.h>
#include <openssl/x509_vfy.h>
#endif
#include <openssl/bn.h>
*/
#ifdef HAVE_SIGNING_C
-static int cb_check_cert __P((int, X509_STORE_CTX *));
-static void eay_setgentype __P((char *, int *));
+static int cb_check_cert_local __P((int, X509_STORE_CTX *));
+static int cb_check_cert_remote __P((int, X509_STORE_CTX *));
static X509 *mem2x509 __P((vchar_t *));
#endif
i = X509_NAME_cmp(a, b);
- end:
+ end:
if (a)
X509_NAME_free(a);
if (b)
* this functions is derived from apps/verify.c in OpenSSL0.9.5
*/
int
-eay_check_x509cert(cert, CApath)
+eay_check_x509cert(cert, CApath, local)
vchar_t *cert;
char *CApath;
+ int local;
{
X509_STORE *cert_ctx = NULL;
X509_LOOKUP *lookup = NULL;
cert_ctx = X509_STORE_new();
if (cert_ctx == NULL)
goto end;
- X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert);
+
+ if (local)
+ X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert_local);
+ else
+ X509_STORE_set_verify_cb_func(cert_ctx, cb_check_cert_remote);
lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());
if (lookup == NULL)
if (csc == NULL)
goto end;
X509_STORE_CTX_init(csc, cert_ctx, x509, NULL);
+
+#if OPENSSL_VERSION_NUMBER >= 0x00907000L
+ X509_STORE_CTX_set_flags(csc, X509_V_FLAG_CRL_CHECK);
+ X509_STORE_CTX_set_flags(csc, X509_V_FLAG_CRL_CHECK_ALL);
+#endif
+
error = X509_verify_cert(csc);
X509_STORE_CTX_cleanup(csc);
#else
*/
error = error ? 0 : -1;
-end:
+ end:
if (error)
printf("%s\n", eay_strerror());
if (cert_ctx != NULL)
/*
* callback function for verifing certificate.
- * this function is derived from cb() in openssl/apps/s_server.c
+ * Derived from cb() in openssl/apps/s_server.c
+ *
+ * This one is called for certificates obtained from
+ * 'peers_certfile' directive.
*/
static int
-cb_check_cert(ok, ctx)
+cb_check_cert_local(ok, ctx)
int ok;
X509_STORE_CTX *ctx;
{
if (!ok) {
X509_NAME_oneline(
- X509_get_subject_name(ctx->current_cert),
+ X509_get_subject_name(ctx->current_cert),
buf,
256);
- /*
- * since we are just checking the certificates, it is
- * ok if they are self signed. But we should still warn
- * the user.
- */
- switch (ctx->error) {
- case X509_V_ERR_CERT_HAS_EXPIRED:
- case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
+ /*
+ * since we are just checking the certificates, it is
+ * ok if they are self signed. But we should still warn
+ * the user.
+ */
+ switch (ctx->error) {
+ case X509_V_ERR_CERT_HAS_EXPIRED:
+ case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
#if OPENSSL_VERSION_NUMBER >= 0x00905100L
- case X509_V_ERR_INVALID_CA:
- case X509_V_ERR_PATH_LENGTH_EXCEEDED:
- case X509_V_ERR_INVALID_PURPOSE:
+ case X509_V_ERR_INVALID_PURPOSE:
+ case X509_V_ERR_UNABLE_TO_GET_CRL:
#endif
- ok = 1;
- log_tag = LLV_WARNING;
- break;
- default:
- log_tag = LLV_ERROR;
- }
+ ok = 1;
+ log_tag = LLV_WARNING;
+ break;
+
+ default:
+ log_tag = LLV_ERROR;
+ }
+
+
+#ifndef EAYDEBUG
+ plog(log_tag, LOCATION, NULL,
+ "%s(%d) at depth:%d SubjectName:%s\n",
+ X509_verify_cert_error_string(ctx->error),
+ ctx->error,
+ ctx->error_depth,
+ buf);
+#else
+ printf("%d: %s(%d) at depth:%d SubjectName:%s\n",
+ log_tag,
+ X509_verify_cert_error_string(ctx->error),
+ ctx->error,
+ ctx->error_depth,
+ buf);
+#endif
+ }
+ ERR_clear_error();
+
+ return ok;
+}
+
+/*
+ * Similar to cb_check_cert_local() but this one is called
+ * for certificates obtained from the IKE payload.
+ */
+static int
+cb_check_cert_remote(ok, ctx)
+ int ok;
+ X509_STORE_CTX *ctx;
+{
+ char buf[256];
+ int log_tag;
+
+ if (!ok) {
+ X509_NAME_oneline(
+ X509_get_subject_name(ctx->current_cert),
+ buf,
+ 256);
+ switch (ctx->error) {
+ case X509_V_ERR_UNABLE_TO_GET_CRL:
+ ok = 1;
+ log_tag = LLV_WARNING;
+ break;
+ default:
+ log_tag = LLV_ERROR;
+ }
#ifndef EAYDEBUG
- plog(log_tag, LOCATION, NULL,
- "%s(%d) at depth:%d SubjectName:%s\n",
- X509_verify_cert_error_string(ctx->error),
- ctx->error,
- ctx->error_depth,
- buf);
+ plog(log_tag, LOCATION, NULL,
+ "%s(%d) at depth:%d SubjectName:%s\n",
+ X509_verify_cert_error_string(ctx->error),
+ ctx->error,
+ ctx->error_depth,
+ buf);
#else
- printf("%d: %s(%d) at depth:%d SubjectName:%s\n",
- log_tag,
- X509_verify_cert_error_string(ctx->error),
- ctx->error,
- ctx->error_depth,
- buf);
+ printf("%d: %s(%d) at depth:%d SubjectName:%s\n",
+ log_tag,
+ X509_verify_cert_error_string(ctx->error),
+ ctx->error,
+ ctx->error_depth,
+ buf);
#endif
}
ERR_clear_error();
/* get the name */
bp = name->v;
len = i2d_X509_NAME(x509->cert_info->subject, &bp);
-
+
error = 0;
end:
return name;
}
+/*
+ * Get the common name from a cert
+ */
+#define EAY_MAX_CN_LEN 256
+vchar_t *
+eay_get_x509_common_name(cert)
+ vchar_t *cert;
+{
+ X509 *x509 = NULL;
+ X509_NAME *name;
+ vchar_t *commonName = NULL;
+
+ commonName = vmalloc(EAY_MAX_CN_LEN);
+ if (commonName == NULL) {
+ plog(LLV_ERROR, LOCATION, NULL, "no memory\n");
+ return NULL;
+ }
+
+ x509 = mem2x509(cert);
+ if (x509 == NULL) {
+ vfree(commonName);
+ return NULL;
+ }
+
+ name = X509_get_subject_name(x509);
+ X509_NAME_get_text_by_NID(name, NID_commonName, commonName->v, EAY_MAX_CN_LEN);
+
+ commonName->l = strlen(commonName->v);
+
+ if (x509)
+ X509_free(x509);
+ return commonName;
+}
+
/*
* get the subjectAltName from X509 certificate.
- * the name is terminated by '\0'.
+ * the name must be terminated by '\0'.
*/
-#include <openssl/x509v3.h>
int
-eay_get_x509subjectaltname(cert, altname, type, pos)
+eay_get_x509subjectaltname(cert, altname, type, pos, len)
vchar_t *cert;
char **altname;
int *type;
int pos;
+ int *len;
{
X509 *x509 = NULL;
- X509_EXTENSION *ext;
- X509V3_EXT_METHOD *method = NULL;
- STACK_OF(GENERAL_NAME) *name;
- CONF_VALUE *cval = NULL;
- STACK_OF(CONF_VALUE) *nval = NULL;
- u_char *bp;
- int i, len;
+ int i;
+ GENERAL_NAMES *gens;
+ GENERAL_NAME *gen;
int error = -1;
*altname = NULL;
*type = GENT_OTHERNAME;
- bp = cert->v;
-
x509 = mem2x509(cert);
if (x509 == NULL)
goto end;
- i = X509_get_ext_by_NID(x509, NID_subject_alt_name, -1);
- if (i < 0)
- goto end;
- ext = X509_get_ext(x509, i);
- method = X509V3_EXT_get(ext);
- if(!method)
- goto end;
-
- bp = ext->value->data;
- name = method->d2i(NULL, &bp, ext->value->length);
- if(!name)
- goto end;
-
- nval = method->i2v(method, name, NULL);
- method->ext_free(name);
- name = NULL;
- if(!nval)
+ gens = X509_get_ext_d2i(x509, NID_subject_alt_name, NULL, NULL);
+ if (gens == NULL)
goto end;
- for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
- /* skip the name */
+ for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
if (i + 1 != pos)
continue;
- cval = sk_CONF_VALUE_value(nval, i);
- len = strlen(cval->value) + 1; /* '\0' included */
- *altname = racoon_malloc(len);
- if (!*altname) {
- sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
- goto end;
- }
- strlcpy(*altname, cval->value, len);
-
- /* set type of the name */
- eay_setgentype(cval->name, type);
+ break;
+ }
+
+ /* there is no data at "pos" */
+ if (i == sk_GENERAL_NAME_num(gens))
+ goto end;
+
+ gen = sk_GENERAL_NAME_value(gens, i);
+
+ /* make sure the data is terminated by '\0'. */
+ if (gen->d.ia5->data[gen->d.ia5->length] != '\0') {
+#ifndef EAYDEBUG
+ plog(LLV_ERROR, LOCATION, NULL,
+ "data is not terminated by '\0'.");
+#endif
+ hexdump(gen->d.ia5->data, gen->d.ia5->length + 1);
+ goto end;
}
- sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
-
+ *len = gen->d.ia5->length + 1;
+ *altname = racoon_malloc(*len);
+ if (!*altname)
+ goto end;
+
+ strlcpy(*altname, gen->d.ia5->data, *len);
+ *type = gen->type;
+
error = 0;
end:
return error;
}
-static void
-eay_setgentype(name, type)
- char *name;
- int *type;
-{
- /* XXX It's needed effective code */
- if(!memcmp(name, "email", strlen("email"))) {
- *type = GENT_EMAIL;
- } else if(!memcmp(name, "URI", strlen("URI"))) {
- *type = GENT_URI;
- } else if(!memcmp(name, "DNS", strlen("DNS"))) {
- *type = GENT_DNS;
- } else if(!memcmp(name, "RID", strlen("RID"))) {
- *type = GENT_RID;
- } else if(!memcmp(name, "IP", strlen("IP"))) {
- *type = GENT_IPADD;
- } else {
- *type = GENT_OTHERNAME;
- }
-}
/*
* decode a X509 certificate and make a readable text terminated '\n'.
evp = X509_get_pubkey(x509);
if (!evp) {
+#ifndef EAYDEBUG
plog(LLV_ERROR, LOCATION, NULL, "X509_get_pubkey: %s\n", eay_strerror());
+#endif
return -1;
}
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+#ifndef __CRYPTO_OPENSSL_H__
+#define __CRYPTO_OPENSSL_H__
#ifdef HAVE_OPENSSL_EVP_H
#include <openssl/evp.h>
#ifdef HAVE_SIGNING_C
/* X509 Certificate */
-#define GENT_OTHERNAME 0
-#define GENT_EMAIL 1
-#define GENT_DNS 2
-#define GENT_X400 3
-#define GENT_DIRNAME 4
-#define GENT_EDIPARTY 5
-#define GENT_URI 6
-#define GENT_IPADD 7
-#define GENT_RID 8
+#include <openssl/x509v3.h>
+
+#define GENT_OTHERNAME GEN_OTHERNAME
+#define GENT_EMAIL GEN_EMAIL
+#define GENT_DNS GEN_DNS
+#define GENT_X400 GEN_X400
+#define GENT_DIRNAME GEN_DIRNAME
+#define GENT_EDIPARTY GEN_EDIPARTY
+#define GENT_URI GEN_URI
+#define GENT_IPADD GEN_IPADD
+#define GENT_RID GEN_RID
+
extern vchar_t *eay_str2asn1dn __P((char *, int));
extern int eay_cmp_asn1dn __P((vchar_t *, vchar_t *));
-extern int eay_check_x509cert __P((vchar_t *, char *));
+extern int eay_check_x509cert __P((vchar_t *, char *, int));
extern vchar_t *eay_get_x509asn1subjectname __P((vchar_t *));
-extern int eay_get_x509subjectaltname __P((vchar_t *, char **, int *, int));
+extern vchar_t *eay_get_x509_common_name __P((vchar_t *));
+extern int eay_get_x509subjectaltname __P((vchar_t *, char **, int *, int, int *));
extern char *eay_get_x509text __P((vchar_t *));
extern vchar_t *eay_get_x509cert __P((char *));
extern vchar_t *eay_get_x509sign __P((vchar_t *, vchar_t *, vchar_t *));
#define CBC_BLOCKLEN 8
#define IPSEC_ENCRYPTKEYLEN 8
+
+
+#endif /* __CRYPTO_OPENSSL_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+
/* define by main.c */
extern int f_local;
extern int vflag;
+
+
+#endif /* __DEBUG_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __DHGROUP_H__
+#define __DHGROUP_H__
+
+
#define OAKLEY_PRIME_MODP768 \
"FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" \
"29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" \
extern struct dhgroup dh_modp4096;
extern struct dhgroup dh_modp6144;
extern struct dhgroup dh_modp8192;
+
+
+#endif /* __DHGROUP_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __DNSSEC_H__
+#define __DNSSEC_H__
+
extern cert_t *dnssec_getcert __P((vchar_t *));
+
+#endif /* __DNSSEC_H__ */
+
* Debugging malloc glue for Racoon.
*/
-#ifndef _GCMALLOC_H_DEFINED
-#define _GCMALLOC_H_DEFINED
+#ifndef __GCMALLOC_H__
+#define __GCMALLOC_H__
/* ElectricFence needs no special handling. */
#endif
#endif /* DEBUG_RECORD_MALLOCATION */
-#endif /* _GCMALLOC_H_DEFINED */
+#endif /* __GCMALLOC_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __GRABMYADDR_H__
+#define __GRABMYADDR_H__
+
+
struct myaddrs {
struct myaddrs *next;
struct sockaddr *addr;
extern void delmyaddr __P((struct myaddrs *));
extern int initmyaddr __P((void));
extern int getsockmyaddr __P((struct sockaddr *));
+
+
+#endif /* __GRABMYADDR_H__ */
+
* POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef __GSSAPI_H__
+#define __GSSAPI_H__
+
+
#include <gssapi/gssapi.h>
#define GSSAPI_DEF_NAME "ike"
int gssapi_id_rcvd __P((struct ph1handle *));
void gssapi_free_state __P((struct ph1handle *));
vchar_t *gssapi_get_default_id __P((struct ph1handle *));
+
+
+#endif /* __GSSAPI_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __HANDLER_H__
+#define __HANDLER_H__
+
/* Phase 1 handler */
/*
* main mode:
extern int add_recvdpkt __P((struct sockaddr *, struct sockaddr *,
vchar_t *, vchar_t *));
extern void init_recvdpkt __P((void));
+
+#endif /* __HANDLER_H__ */
+
struct ph1handle *iph1;
{
struct ipsecdoi_id_b *id_b;
+ struct sockaddr *sa;
+ caddr_t sa1, sa2;
if (iph1->id_p == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
case IDTYPE_ASN1DN:
ident.v = (caddr_t)(id_b + 1);
ident.l = ident0->l;
- if (eay_cmp_asn1dn(ident0, &ident)) {
- plog(LLV_WARNING, LOCATION, NULL,
- "ID value mismatched.\n");
- if (iph1->rmconf->verify_identifier)
- return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
+ if (eay_cmp_asn1dn(ident0, &ident))
+ goto err;
+ break;
+ case IDTYPE_ADDRESS:
+ sa = (struct sockaddr *)ident0->v;
+ sa2 = (caddr_t)(id_b + 1);
+ switch (sa->sa_family) {
+ case AF_INET:
+ if (iph1->id_p->l - sizeof(*id_b) != sizeof(struct in_addr))
+ goto err;
+
+ sa1 = (caddr_t)&((struct sockaddr_in *)sa)->sin_addr;
+ if (memcmp(sa1, sa2, sizeof(struct in_addr)) != 0)
+ goto err;
+ break;
+#ifdef INET6
+ case AF_INET6:
+ if (iph1->id_p->l - sizeof(*id_b) != sizeof(struct in6_addr))
+ goto err;
+ sa1 = (caddr_t)&((struct sockaddr_in6 *)sa)->sin6_addr;
+ if (memcmp(sa1, sa2, sizeof(struct in6_addr)) != 0)
+ goto err;
+ break;
+#endif
+ default:
+ goto err;
}
break;
default:
if (memcmp(ident0->v, id_b + 1, ident0->l)) {
+err:
plog(LLV_WARNING, LOCATION, NULL,
"ID value mismatched.\n");
- if (iph1->rmconf->verify_identifier)
+ if (iph1->rmconf->verify_identifier) {
+ vfree(ident0);
return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
+ }
}
break;
}
* SUCH DAMAGE.
*/
+#ifndef __IPSEC_DOI_H__
+#define __IPSEC_DOI_H__
+
/* refered to RFC2407 */
#define IPSEC_DOI 1
#define IPSECDOI_ID_KEY_ID 11
/* compressing doi type, it's internal use. */
-#define IDTYPE_FQDN 0
+#define IDTYPE_FQDN 0
#define IDTYPE_USERFQDN 1
#define IDTYPE_KEYID 2
#define IDTYPE_ADDRESS 3
#define SECRETTYPE_KEY 1
#define SECRETTYPE_KEYCHAIN 2
+/* verification modules */
+#define VERIFICATION_MODULE_OPENSSL 0
+#define VERIFICATION_MODULE_SEC_FRAMEWORK 1
+
+/* verification options */
+#define VERIFICATION_OPTION_NONE 0
+#define VERIFICATION_OPTION_PEERS_IDENTIFIER 1
+#define VERIFICATION_OPTION_OPEN_DIR 2
+
/* The use for checking proposal payload. This is not exchange type. */
#define IPSECDOI_TYPE_PH1 0
#define IPSECDOI_TYPE_PH2 1
extern int idtype2doi __P((int));
extern int doi2idtype __P((int));
+
+#endif /* __IPSEC_DOI_H__ */
+
static int isakmp_ph2begin_r __P((struct ph1handle *, vchar_t *));
static int etypesw1 __P((int));
static int etypesw2 __P((int));
+static void isakmp_free_addrs __P((void));
+
/*
* isakmp packet handler
goto end;
}
+ remote_len = sizeof(remote);
+
/* read real message */
if ((buf = vmalloc(ntohl(isakmp.len))) == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
if (errno == EINTR)
continue;
plog(LLV_ERROR, LOCATION, NULL,
- "failed to receive isakmp packet\n");
+ "failed to read isakmp packet from socket %d, len=%d\n", so_isakmp, buf->l);
+ error = -2; /* serious problem with socket */
goto end;
}
goto end;
}
+ remote_len = sizeof(remote);
+
/* read real message */
if ((buf = vmalloc(ntohl(isakmp->len) + 4)) == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
if (errno == EINTR)
continue;
plog(LLV_ERROR, LOCATION, NULL,
- "failed to receive isakmp packet\n");
+ "failed to read isakmp packet from socket %d, len=%d\n", so_isakmp, buf->l);
+ error = -2; /* serious problem with socket */
goto end;
}
return -1;
}
- /* when using commit bit, status will be reached here. */
- if (iph2->status == PHASE2ST_ADDSA)
- return 0;
-
/* free resend buffer */
if (iph2->sendbuf == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
/* turn off schedule */
if (iph2->scr)
SCHED_KILL(iph2->scr);
+
+ /* when using commit bit, status will be reached here. */
+ if (iph2->status == PHASE2ST_ADDSA)
+ return 0;
/* send */
plog(LLV_DEBUG, LOCATION, NULL, "===\n");
void
isakmp_close()
{
- struct myaddrs *p, *next;
+ isakmp_close_sockets();
+ isakmp_free_addrs();
+}
- for (p = lcconf->myaddrs; p; p = next) {
- next = p->next;
+void
+isakmp_close_sockets()
+{
+ struct myaddrs *p;
- if (!p->addr) {
- racoon_free(p);
+ for (p = lcconf->myaddrs; p; p = p->next) {
+
+ if (!p->addr)
continue;
+
+ if (p->sock >= 0) {
+ close(p->sock);
+ p->sock = -1;
}
- close(p->sock);
+
#ifdef IKE_NAT_T
- if (p->nattsock >= 0) close(p->nattsock);
+ if (p->nattsock >= 0) {
+ close(p->nattsock);
+ p->nattsock = -1;
+ }
#endif
- racoon_free(p->addr);
+
+ }
+
+}
+
+void
+isakmp_free_addrs()
+{
+ struct myaddrs *p, *next;
+
+ for (p = lcconf->myaddrs; p; p = next) {
+ next = p->next;
+
+ if (p->addr)
+ racoon_free(p->addr);
racoon_free(p);
}
lcconf->myaddrs = NULL;
+
}
+
// close sockets for addresses that have gone away
void
isakmp_close_unused()
return -1;
}
+ if (iph2->ph1 == 0) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "internal error - attempt to re-send phase2 with no phase1 bound.\n");
+ iph2->retry_counter = -1;
+ remph2(iph2);
+ delph2(iph2);
+ return -1;
+ }
+
if (isakmp_send(iph2->ph1, iph2->sendbuf) < 0)
return -1;
* SUCH DAMAGE.
*/
+#ifndef __ISAKMP_H__
+#define __ISAKMP_H__
+
/* refer to RFC 2408 */
/* must include <netinet/in.h> first. */
/* SPI(es) */
} __attribute__((__packed__));
+
+#endif /* __ISAKMP_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __ISAKMP_AGG_H__
+#define __ISAKMP_AGG_H__
+
+
extern int agg_i1send __P((struct ph1handle *, vchar_t *));
extern int agg_i2recv __P((struct ph1handle *, vchar_t *));
extern int agg_i2send __P((struct ph1handle *, vchar_t *));
extern int agg_r1send __P((struct ph1handle *, vchar_t *));
extern int agg_r2recv __P((struct ph1handle *, vchar_t *));
extern int agg_r2send __P((struct ph1handle *, vchar_t *));
+
+#endif /* __ISAKMP_AGG_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __ISAKMP_BASE_H__
+#define __ISAKMP_BASE_H__
+
extern int base_i1send __P((struct ph1handle *, vchar_t *));
extern int base_i2recv __P((struct ph1handle *, vchar_t *));
extern int base_i2send __P((struct ph1handle *, vchar_t *));
extern int base_r1send __P((struct ph1handle *, vchar_t *));
extern int base_r2recv __P((struct ph1handle *, vchar_t *));
extern int base_r2send __P((struct ph1handle *, vchar_t *));
+
+
+#endif /* __ISAKMP_BASE_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __ISAKMP_IDENT_H__
+#define __ISAKMP_IDENT_H__
+
extern int ident_i1send __P((struct ph1handle *, vchar_t *));
extern int ident_i2recv __P((struct ph1handle *, vchar_t *));
extern int ident_i2send __P((struct ph1handle *, vchar_t *));
extern int ident_r2send __P((struct ph1handle *, vchar_t *));
extern int ident_r3recv __P((struct ph1handle *, vchar_t *));
extern int ident_r3send __P((struct ph1handle *, vchar_t *));
+
+
+#endif /* __ISAKMP_IDENT_H__ */
+
#include <sys/socket.h>
#include <net/pfkeyv2.h>
-#include <netkey/keydb.h>
#include <netkey/key_var.h>
#include <netinet/in.h>
#ifdef IPV6_INRIA_VERSION
* SUCH DAMAGE.
*/
+#ifndef __ISAKMP_INF_H__
+#define __ISAKMP_INF_H__
+
struct saproto;
extern int isakmp_info_recv __P((struct ph1handle *, vchar_t *));
extern int isakmp_info_send_d1 __P((struct ph1handle *));
struct saproto *, vchar_t *));
extern void isakmp_check_notify __P((struct isakmp_gen *, struct ph1handle *));
+
+#endif /* __ISAKMP_INF_H__ */
+
// if natd_record matches source, returns 1.
// if natd_record matches desination, returns 2.
// if natd_record doesn't match any entries, returns 0.
+
+#ifndef __ISAKMP_NATD_H__
+#define __ISAKMP_NATD_H__
+
typedef enum
{
natd_match_none = 0,
natd_match_t natd_matches(struct ph1handle* iph1, struct isakmp_gen *natd_record);
int natd_create(struct ph1handle* iph1);
-int natd_hasnat(const struct ph1handle* iph1);
\ No newline at end of file
+int natd_hasnat(const struct ph1handle* iph1);
+
+
+#endif /* __ISAKMP_NATD_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __ISAKMP_NEWG_H__
+#define __ISAKMP_NEWG_H__
+
+
extern int isakmp_newgroup_r __P((struct ph1handle *, vchar_t *));
+
+#endif /* __ISAKMP_NEWG_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __ISAKMP_QUICK_H__
+#define __ISAKMP_QUICK_H__
+
+
extern int quick_i1prep __P((struct ph2handle *, vchar_t *));
extern int quick_i1send __P((struct ph2handle *, vchar_t *));
extern int quick_i2recv __P((struct ph2handle *, vchar_t *));
extern int quick_r3recv __P((struct ph2handle *, vchar_t *));
extern int quick_r3send __P((struct ph2handle *, vchar_t *));
extern int quick_r3prep __P((struct ph2handle *, vchar_t *));
+
+#endif /* __ISAKMP_QUICK_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __ISAKMP_VAR_H__
+#define __ISAKMP_VAR_H__
+
#define PORT_ISAKMP 500
#define PORT_ISAKMP_NATT 4500
extern const char *isakmp_pindex __P((const isakmp_index *, const u_int32_t));
extern int isakmp_open __P((void));
extern void isakmp_close __P((void));
+extern void isakmp_close_sockets __P((void));
extern void isakmp_close_unused __P((void));
extern int isakmp_send __P((struct ph1handle *, vchar_t *));
extern int copy_ph1addresses __P(( struct ph1handle *,
struct remoteconf *, struct sockaddr *, struct sockaddr *));
extern void log_ph1established __P((const struct ph1handle *));
+
+
+#endif /* __ISAKMP_VAR_H__ */
+
#include <net/route.h>
#include <netkey/key_var.h>
-#include <netkey/key_debug.h>
#include <netinet/in.h>
#include <netinet6/ipsec.h>
* SUCH DAMAGE.
*/
+#ifndef __LIBPFKEY_H__
+#define __LIBPFKEY_H__
+
struct sadb_msg;
extern void pfkey_sadump __P((struct sadb_msg *));
extern void pfkey_spdump __P((struct sadb_msg *));
int pfkey_send __P((int, struct sadb_msg *, int));
int pfkey_align __P((struct sadb_msg *, caddr_t *));
int pfkey_check __P((caddr_t *));
+
+
+#endif /* __LIBPFKEY_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __LOCALCONF_H__
+#define __LOCALCONF_H__
+
/* local configuration */
#define LC_DEFAULT_CF SYSCONFDIR "/racoon.conf"
extern void getpathname __P((char *, int, int, const char *));
extern int sittype2doi __P((int));
extern int doitype2doi __P((int));
+
+
+#endif /* __LOCALCONF_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __LOGGER_H__
+#define __LOGGER_H__
+
struct log {
int head;
int siz;
extern int log_vaprint __P((struct log *, const char *, va_list));
extern int log_close __P((struct log *));
extern void log_free __P((struct log *));
+
+#endif /* __LOGGER_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __MISC_H__
+#define __MISC_H__
+
+
#define BIT2STR(b) bit2str(b, sizeof(b)<<3)
#ifdef HAVE_FUNCTION_MACRO
extern int getfsize __P((char *));
struct timeval;
extern double timedelta __P((struct timeval *, struct timeval *));
+
+
+#endif /* __MISC_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __NETDB_DNSSEC_H__
+#define __NETDB_DNSSEC_H__
+
#ifndef T_CERT
#define T_CERT 37 /* defined by RFC2538 section 2 */
#endif
extern void freecertinfo __P((struct certinfo *));
extern int getcertsbyname __P((char *, struct certinfo **));
+
+
+#endif /* __NETDB_DNSSEC_H__ */
+
#include <sys/param.h>
#include <sys/socket.h> /* XXX for subjectaltname */
#include <netinet/in.h> /* XXX for subjectaltname */
+#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include "sainfo.h"
#include "proposal.h"
#include "crypto_openssl.h"
+#include "crypto_cssm.h"
+#include "open_dir.h"
#include "dnssec.h"
#include "sockmisc.h"
#include "strnames.h"
static int oakley_compute_keymat_x __P((struct ph2handle *, int, int));
#ifdef HAVE_SIGNING_C
static int get_cert_fromlocal __P((struct ph1handle *, int));
-static int oakley_check_certid __P((struct ph1handle *iph1));
+static int oakley_check_certid(u_int8_t idtype, int idlen, void* id, cert_t* cert_p);
static int check_typeofcertname __P((int, int));
static cert_t *save_certbuf __P((struct isakmp_gen *));
#endif
return ISAKMP_INTERNAL_ERROR;
}
- /* compare ID payload and certificate name */
- if (iph1->rmconf->verify_cert &&
- (error = oakley_check_certid(iph1)) != 0)
- return error;
+ /* check cert ID */
+ if (iph1->rmconf->verify_cert) {
+
+ struct ipsecdoi_id_b *id_b;
+ int idlen;
+
+ if (iph1->id_p == NULL || iph1->cert_p == NULL) {
+ plog(LLV_ERROR, LOCATION, NULL, "no ID or CERT found.\n");
+ return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
+ }
+
+ id_b = (struct ipsecdoi_id_b *)iph1->id_p->v;
+ idlen = iph1->id_p->l - sizeof(*id_b);
+
+ if ((error = oakley_check_certid(id_b->type, idlen, id_b + 1, iph1->cert_p)) != 0)
+ return error;
+ }
/* verify certificate */
if (iph1->rmconf->verify_cert
&& iph1->rmconf->getcert_method == ISAKMP_GETCERT_PAYLOAD) {
switch (iph1->rmconf->certtype) {
case ISAKMP_CERT_X509SIGN:
- error = eay_check_x509cert(&iph1->cert_p->cert,
- lcconf->pathinfo[LC_PATHTYPE_CERT]);
+ if (iph1->rmconf->cert_verification == VERIFICATION_MODULE_SEC_FRAMEWORK)
+ error = crypto_cssm_check_x509cert(&iph1->cert_p->cert);
+ else
+ error = eay_check_x509cert(&iph1->cert_p->cert,
+ lcconf->pathinfo[LC_PATHTYPE_CERT], 0);
break;
default:
plog(LLV_ERROR, LOCATION, NULL,
"the peer's certificate is not verified.\n");
return ISAKMP_NTYPE_INVALID_CERT_AUTHORITY;
}
+
}
+
+ /* check configured peers identifier against cert IDs */
+ /* allows checking of specified ID against multiple ids in the cert */
+ /* such as multiple domain names */
+ if (iph1->rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER) {
+ u_int8_t doi_type = 255;
+ void *peers_id = NULL;
+ int peers_id_len = 0;
+
+ if (iph1->rmconf->idvtype_p == IDTYPE_ADDRESS) {
+ switch (((struct sockaddr *)(iph1->rmconf->idv_p->v))->sa_family) {
+ case AF_INET:
+ doi_type = IPSECDOI_ID_IPV4_ADDR;
+ peers_id_len = sizeof(struct in_addr);
+ peers_id = &(((struct sockaddr_in *)(iph1->rmconf->idv_p->v))->sin_addr.s_addr);
+ break;
+#ifdef INET6
+ case AF_INET6:
+ doi_type = IPSECDOI_ID_IPV6_ADDR;
+ peers_id_len = sizeof(struct in6_addr);
+ peers_id = &(((struct sockaddr_in6 *)(iph1->rmconf->idv_p->v))->sin6_addr.s6_addr);
+ break;
+#endif
+ default:
+ plog(LLV_ERROR, LOCATION, NULL,
+ "unknown address type for peers identifier.\n");
+ return ISAKMP_NTYPE_AUTHENTICATION_FAILED;
+ break;
+ }
+
+ } else {
+ doi_type = idtype2doi(iph1->rmconf->idvtype_p);
+ peers_id = iph1->rmconf->idv_p->v;
+ peers_id_len = iph1->rmconf->idv_p->l;
+ }
+ if ((error = oakley_check_certid(doi_type, peers_id_len,
+ peers_id, iph1->cert_p)) != 0)
+ return error;
+ }
+
+ if (iph1->rmconf->cert_verification_option == VERIFICATION_OPTION_OPEN_DIR) {
+
+ vchar_t *user_id = NULL;
+
+ user_id = eay_get_x509_common_name(&iph1->cert_p->cert);
+
+ // the following functions will check if user_id == 0
+ if (open_dir_authorize_id(user_id, iph1->rmconf->open_dir_auth_group) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "the peer is not authorized for access.\n");
+ return ISAKMP_NTYPE_AUTHENTICATION_FAILED;
+ }
+ vfree(user_id);
+ }
+
plog(LLV_DEBUG, LOCATION, NULL, "CERT validated\n");
+
/* compute hash */
switch (iph1->etype) {
certfile = iph1->rmconf->peerscertfile;
certpl = &iph1->cert_p;
}
- if (!certfile) {
+ if (!certfile && iph1->rmconf->identity_in_keychain == 0) {
plog(LLV_ERROR, LOCATION, NULL, "no CERT defined.\n");
return 0;
}
switch (iph1->rmconf->certtype) {
- case ISAKMP_CERT_X509SIGN:
- case ISAKMP_CERT_DNS:
- /* make public file name */
- getpathname(path, sizeof(path), LC_PATHTYPE_CERT, certfile);
- cert = eay_get_x509cert(path);
- if (cert) {
- char *p = NULL;
- p = eay_get_x509text(cert);
- plog(LLV_DEBUG, LOCATION, NULL, "%s", p ? p : "\n");
- racoon_free(p);
- };
- break;
-
- default:
- plog(LLV_ERROR, LOCATION, NULL,
- "not supported certtype %d\n",
- iph1->rmconf->certtype);
- goto end;
+ case ISAKMP_CERT_X509SIGN:
+ if (iph1->rmconf->identity_in_keychain) {
+ cert = crypto_cssm_get_x509cert(iph1->rmconf->keychainCertRef);
+ break;
+ } // else fall thru
+ case ISAKMP_CERT_DNS:
+ /* make public file name */
+ getpathname(path, sizeof(path), LC_PATHTYPE_CERT, certfile);
+ cert = eay_get_x509cert(path);
+ break;
+
+ default:
+ plog(LLV_ERROR, LOCATION, NULL,
+ "not supported certtype %d\n",
+ iph1->rmconf->certtype);
+ goto end;
}
-
- if (!cert) {
+
+ if (cert) {
+ char *p = NULL;
+ p = eay_get_x509text(cert);
+ plog(LLV_DEBUG, LOCATION, NULL, "%s", p ? p : "\n");
+ racoon_free(p);
+ } else {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get %s CERT.\n",
my ? "my" : "peers");
switch (iph1->rmconf->certtype) {
case ISAKMP_CERT_X509SIGN:
+ // cert in keychain - use cssm to sign
+ if (iph1->rmconf->identity_in_keychain) {
+ iph1->sig = crypto_cssm_getsign(iph1->rmconf->keychainCertRef, iph1->hash);
+ break;
+ } // else fall thru
case ISAKMP_CERT_DNS:
if (iph1->rmconf->myprivfile == NULL) {
plog(LLV_ERROR, LOCATION, NULL, "no cert defined.\n");
iph1->sig = eay_get_x509sign(iph1->hash,
privkey, &iph1->cert->cert);
+
break;
default:
goto end;
* compare certificate name and ID value.
*/
static int
-oakley_check_certid(iph1)
- struct ph1handle *iph1;
+oakley_check_certid(u_int8_t idtype, int idlen, void* id, cert_t* cert_p)
{
- struct ipsecdoi_id_b *id_b;
vchar_t *name = NULL;
char *altname = NULL;
- int idlen, type;
+ int type, len;
int error;
- if (iph1->id_p == NULL || iph1->cert_p == NULL) {
- plog(LLV_ERROR, LOCATION, NULL, "no ID nor CERT found.\n");
- return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
- }
-
- id_b = (struct ipsecdoi_id_b *)iph1->id_p->v;
- idlen = iph1->id_p->l - sizeof(*id_b);
-
- switch (id_b->type) {
+ switch (idtype) {
case IPSECDOI_ID_DER_ASN1_DN:
- name = eay_get_x509asn1subjectname(&iph1->cert_p->cert);
+ name = eay_get_x509asn1subjectname(&cert_p->cert);
if (!name) {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get subjectName\n");
vfree(name);
return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
}
- error = memcmp(id_b + 1, name->v, idlen);
+ error = memcmp(id, name->v, idlen);
vfree(name);
if (error != 0) {
plog(LLV_ERROR, LOCATION, NULL,
return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
}
return 0;
- case IPSECDOI_ID_IPV4_ADDR:
+ case IPSECDOI_ID_IPV4_ADDR:
case IPSECDOI_ID_IPV6_ADDR:
{
- /*
- * converting to binary from string because openssl return
- * a string even if object is a binary.
- * XXX fix it ! access by ASN.1 directly without.
- */
- struct addrinfo hints, *res;
- caddr_t a = NULL;
+
+ /*
+ * Openssl returns the IPAddress as an ASN1 octet string (binary format)
+ * followed by a trailing NULL. 5 bytes for IPv4 and 17 bytes for IPv6
+ */
+ #define SUBJ_ALT_NAME_IPV4_ADDRESS_LEN 5
+ #define SUBJ_ALT_NAME_IPV6_ADDRESS_LEN 17
+
int pos;
+
+ if (idtype == IPSECDOI_ID_IPV4_ADDR && idlen != sizeof(struct in_addr)
+ || idtype == IPSECDOI_ID_IPV6_ADDR && idlen != sizeof(struct in6_addr)) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "invalid address length passed.\n");
+ return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
+ }
for (pos = 1; ; pos++) {
- if (eay_get_x509subjectaltname(&iph1->cert_p->cert,
- &altname, &type, pos) !=0) {
+ if (eay_get_x509subjectaltname(&cert_p->cert, &altname, &type, pos, &len) !=0) {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get subjectAltName\n");
return ISAKMP_NTYPE_INVALID_CERTIFICATE;
/* it's the end condition of the loop. */
if (!altname) {
- plog(LLV_ERROR, LOCATION, NULL,
- "no proper subjectAltName.\n");
- return ISAKMP_NTYPE_INVALID_CERTIFICATE;
+ return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
}
- if (check_typeofcertname(id_b->type, type) == 0)
- break;
-
- /* next name */
- racoon_free(altname);
- altname = NULL;
- }
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_RAW;
- hints.ai_flags = AI_NUMERICHOST;
- error = getaddrinfo(altname, NULL, &hints, &res);
- if (error != 0) {
- plog(LLV_ERROR, LOCATION, NULL,
- "no proper subjectAltName.\n");
- racoon_free(altname);
- return ISAKMP_NTYPE_INVALID_CERTIFICATE;
- }
- switch (res->ai_family) {
- case AF_INET:
- a = (caddr_t)&((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
- break;
+ if (check_typeofcertname(idtype, type) != 0) {
+ /* wrong type - skip this one */
+ racoon_free(altname);
+ altname = NULL;
+ continue;
+ }
+
+ if (len == SUBJ_ALT_NAME_IPV4_ADDRESS_LEN) { /* IPv4 */
+ if (idtype != IPSECDOI_ID_IPV4_ADDR) {
+ /* wrong IP address type - skip this one */
+ racoon_free(altname);
+ altname = NULL;
+ continue;
+ }
+ }
#ifdef INET6
- case AF_INET6:
- a = (caddr_t)&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr.s6_addr;
- break;
+ else if (len == SUBJ_ALT_NAME_IPV6_ADDRESS_LEN) { /* IPv6 */
+ if (idtype != IPSECDOI_ID_IPV6_ADDR) {
+ /* wrong IP address type - skip this one */
+ racoon_free(altname);
+ altname = NULL;
+ continue;
+ }
+ }
#endif
- default:
- plog(LLV_ERROR, LOCATION, NULL,
- "family not supported: %d.\n", res->ai_family);
+ else {
+ /* invalid IP address length in certificate - bad or bogus certificate */
+ plog(LLV_ERROR, LOCATION, NULL,
+ "invalid IP address in certificate.\n");
+ racoon_free(altname);
+ altname = NULL;
+ return ISAKMP_NTYPE_INVALID_CERTIFICATE;
+ }
+
+ /* compare the addresses */
+ error = memcmp(id, altname, idlen);
racoon_free(altname);
- freeaddrinfo(res);
- return ISAKMP_NTYPE_INVALID_CERTIFICATE;
- }
- error = memcmp(id_b + 1, a, idlen);
- freeaddrinfo(res);
- vfree(name);
- if (error != 0) {
- plog(LLV_ERROR, LOCATION, NULL,
- "ID mismatched with subjectAltName.\n");
- return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
+ if (error != 0) {
+ plog(LLV_ERROR, LOCATION, NULL,
+ "ID mismatched with subjectAltName.\n");
+ return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
+ }
+ return 0;
}
- return 0;
}
case IPSECDOI_ID_FQDN:
case IPSECDOI_ID_USER_FQDN:
int pos;
for (pos = 1; ; pos++) {
- if (eay_get_x509subjectaltname(&iph1->cert_p->cert,
- &altname, &type, pos) != 0){
+ if (eay_get_x509subjectaltname(&cert_p->cert, &altname, &type, pos, &len) != 0) {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get subjectAltName\n");
return ISAKMP_NTYPE_INVALID_CERTIFICATE;
/* it's the end condition of the loop. */
if (!altname) {
- plog(LLV_ERROR, LOCATION, NULL,
- "no proper subjectAltName.\n");
- return ISAKMP_NTYPE_INVALID_CERTIFICATE;
+ return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
}
- if (check_typeofcertname(id_b->type, type) == 0)
- break;
+ if (check_typeofcertname(idtype, type) != 0) {
+ /* wrong general type - skip this one */
+ racoon_free(altname);
+ altname = NULL;
+ continue;
+ }
- /* next name */
- racoon_free(altname);
- altname = NULL;
- }
- if (idlen != strlen(altname)) {
- plog(LLV_ERROR, LOCATION, NULL,
- "Invalid ID length in phase 1.\n");
- racoon_free(altname);
- return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
- }
- if (check_typeofcertname(id_b->type, type) != 0) {
- plog(LLV_ERROR, LOCATION, NULL,
- "ID type mismatched. ID: %s CERT: %s.\n",
- s_ipsecdoi_ident(id_b->type),
- s_ipsecdoi_ident(type));
- racoon_free(altname);
- return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
- }
- error = memcmp(id_b + 1, altname, idlen);
- if (error) {
- plog(LLV_ERROR, LOCATION, NULL, "ID mismatched.\n");
+ if (idlen != strlen(altname)) {
+ /* wrong length - skip this one */
+ racoon_free(altname);
+ altname = NULL;
+ continue;
+ }
+ error = memcmp(id, altname, idlen);
racoon_free(altname);
- return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
+ if (error) {
+ plog(LLV_ERROR, LOCATION, NULL, "ID mismatched.\n");
+ return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
+ }
+ return 0;
}
- racoon_free(altname);
- return 0;
}
default:
plog(LLV_ERROR, LOCATION, NULL,
"Inpropper ID type passed: %s.\n",
- s_ipsecdoi_ident(id_b->type));
+ s_ipsecdoi_ident(idtype));
return ISAKMP_NTYPE_INVALID_ID_INFORMATION;
- }
+ }
/*NOTREACHED*/
}
* SUCH DAMAGE.
*/
+#ifndef __OAKLEY_H__
+#define __OAKLEY_H__
+
+
/* refer to RFC 2409 */
/* Attribute Classes */
vchar_t *, vchar_t *, vchar_t *));
extern vchar_t *oakley_do_encrypt __P((struct ph1handle *,
vchar_t *, vchar_t *, vchar_t *));
+
+#endif /* __OAKLEY_H__ */
+
--- /dev/null
+/*
+ * Copyright (c) 2001-2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include <DirectoryService/DirServices.h>
+#include <DirectoryService/DirServicesUtils.h>
+#include <DirectoryService/DirServicesConst.h>
+#include <CoreFoundation/CFString.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+
+#include "vmbuf.h"
+#include "remoteconf.h"
+#include "plog.h"
+#include "misc.h"
+#include "gcmalloc.h"
+#include "open_dir.h"
+
+#define BUF_LEN 1024
+
+
+static tDirStatus open_dir_get_search_node_ref(tDirReference dirRef, unsigned long index,
+ tDirNodeReference *searchNodeRef, unsigned long *count);
+static tDirStatus open_dir_get_user_attr(tDirReference dirRef, tDirNodeReference searchNodeRef, char *user_name,
+ char *attr, tAttributeValueEntryPtr *attr_value);
+static tDirStatus open_dir_check_group_membership(tDirReference dirRef, tDirNodeReference searchNodeRef,
+ char *group_name, char *user_name, char *userGID, int *authorized);
+
+
+//----------------------------------------------------------------------
+// open_dir_authorize_id
+//----------------------------------------------------------------------
+int open_dir_authorize_id(vchar_t *id, vchar_t *group)
+{
+
+ tDirReference dirRef;
+ tDirStatus dsResult = eDSNoErr;
+ int authorized = 0;
+ tDirNodeReference searchNodeRef;
+ tAttributeValueEntryPtr groupID = NULL;
+ tAttributeValueEntryPtr recordName = NULL;
+ unsigned long searchNodeCount;
+ char* user_name = NULL;
+ char* group_name = NULL;
+
+ if (id == 0 || id->l < 1) {
+ plog(LLV_ERROR, LOCATION, NULL, "invalid user name.\n");
+ goto end;
+ }
+ user_name = racoon_malloc(id->l + 1);
+ if (user_name == NULL) {
+ plog(LLV_ERROR, LOCATION, NULL, "out of memory - unable to allocate space for user name.\n");
+ goto end;
+ }
+ bcopy(id->v, user_name, id->l);
+ *(user_name + id->l) = 0;
+
+ if (group && group->l > 0) {
+ group_name = racoon_malloc(group->l + 1);
+ if (group_name == NULL) {
+ plog(LLV_NOTIFY, LOCATION, NULL, "out of memeory - unable to allocate space for group name.\n");
+ goto end;
+ }
+ bcopy(group->v, group_name, group->l);
+ *(group_name + group->l) = 0;
+ }
+
+ if ((dsResult = dsOpenDirService(&dirRef)) == eDSNoErr) {
+ // get the search node ref
+ if ((dsResult = open_dir_get_search_node_ref(dirRef, 1, &searchNodeRef, &searchNodeCount)) == eDSNoErr) {
+ // get the user's primary group ID
+ if (dsResult = open_dir_get_user_attr(dirRef, searchNodeRef, user_name, kDSNAttrRecordName, &recordName) == eDSNoErr) {
+ if (recordName != 0) {
+ if (group_name != 0) {
+ if ((dsResult = open_dir_get_user_attr(dirRef, searchNodeRef, user_name, kDS1AttrPrimaryGroupID, &groupID)) == eDSNoErr) {
+ // check if user is member of the group
+ dsResult = open_dir_check_group_membership(dirRef, searchNodeRef, group_name,
+ recordName->fAttributeValueData.fBufferData, groupID->fAttributeValueData.fBufferData, &authorized);
+ }
+ } else
+ authorized = 1; // no group required - user record found
+ }
+ }
+ if (groupID)
+ dsDeallocAttributeValueEntry(dirRef, groupID);
+ if (recordName)
+ dsDeallocAttributeValueEntry(dirRef, recordName);
+ dsCloseDirNode(searchNodeRef); // close the search node
+ }
+ dsCloseDirService(dirRef);
+ }
+
+end:
+ if (authorized)
+ plog(LLV_NOTIFY, LOCATION, NULL, "User '%s' authorized for access\n", user_name);
+ else
+ plog(LLV_NOTIFY, LOCATION, NULL, "User '%s' not authorized for access\n", user_name);
+ if (user_name)
+ free(user_name);
+ if (group_name)
+ free(group_name);
+ return authorized;
+}
+
+
+//----------------------------------------------------------------------
+// open_dir_get_search_node_ref
+//----------------------------------------------------------------------
+static tDirStatus open_dir_get_search_node_ref(tDirReference dirRef, unsigned long index,
+ tDirNodeReference *searchNodeRef, unsigned long *count)
+{
+ tDirStatus dsResult = -1;
+ tDataBufferPtr searchNodeDataBufferPtr = 0;
+ tDataListPtr searchNodeNameDataListPtr = 0;
+
+ unsigned long outNodeCount;
+ tContextData continueData = 0;
+
+ *searchNodeRef = 0;
+ *count = 0;
+
+ // allocate required buffers and data lists
+ if ((searchNodeDataBufferPtr = dsDataBufferAllocate(dirRef, BUF_LEN)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n");
+ goto cleanup;
+ }
+ if ((searchNodeNameDataListPtr = dsDataListAllocate(dirRef)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n");
+ goto cleanup;
+ }
+
+ // find authentication search node(s)
+ if ((dsResult = dsFindDirNodes(dirRef, searchNodeDataBufferPtr, 0, eDSAuthenticationSearchNodeName,
+ &outNodeCount, &continueData)) == eDSNoErr) {
+ if (outNodeCount != 0) {
+
+ // get the seach node name and open the node
+ if ((dsResult = dsGetDirNodeName(dirRef, searchNodeDataBufferPtr, index,
+ &searchNodeNameDataListPtr)) == eDSNoErr) {
+ if ((dsResult = dsOpenDirNode(dirRef, searchNodeNameDataListPtr, searchNodeRef)) == eDSNoErr) {
+ *count = outNodeCount;
+ }
+ }
+ }
+ if (continueData)
+ dsReleaseContinueData(dirRef, continueData);
+ }
+
+cleanup:
+ if (searchNodeDataBufferPtr)
+ dsDataBufferDeAllocate(dirRef, searchNodeDataBufferPtr);
+ if (searchNodeNameDataListPtr)
+ dsDataListDeallocate(dirRef, searchNodeNameDataListPtr);
+
+ return dsResult;
+}
+
+//----------------------------------------------------------------------
+// open_dir_get_user_attr
+//----------------------------------------------------------------------
+static tDirStatus open_dir_get_user_attr(tDirReference dirRef, tDirNodeReference searchNodeRef, char *user_name,
+ char *attr, tAttributeValueEntryPtr *attr_value)
+{
+
+ tDirStatus dsResult = -1;
+
+ tDataBufferPtr userRcdDataBufferPtr = 0;
+ tDataListPtr recordNameDataListPtr = 0;
+ tDataListPtr recordTypeDataListPtr = 0;
+ tDataListPtr attrTypeDataListPtr = 0;
+ tContextData continueData = 0;
+
+ unsigned long outRecordCount;
+ int userRcdFound = 0;
+ u_int32_t userRecordIndex, attrIndex;
+
+ *attr_value = 0;
+
+ if ((userRcdDataBufferPtr = dsDataBufferAllocate(dirRef, BUF_LEN)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n");
+ goto cleanup;
+ }
+ if ((recordNameDataListPtr = dsBuildListFromStrings(dirRef, user_name, 0)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n");
+ goto cleanup;
+ }
+ if ((recordTypeDataListPtr = dsBuildListFromStrings(dirRef, kDSStdRecordTypeUsers, 0)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n");
+ goto cleanup;
+ }
+ if ((attrTypeDataListPtr = dsBuildListFromStrings(dirRef, kDSNAttrRecordName, kDS1AttrDistinguishedName, attr, 0)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n");
+ goto cleanup;
+ }
+
+ // find the user record(s), extracting the user name and requested attribute
+ do {
+ dsResult = dsGetRecordList(searchNodeRef, userRcdDataBufferPtr, recordNameDataListPtr, eDSExact,
+ recordTypeDataListPtr, attrTypeDataListPtr, 0, &outRecordCount, &continueData);
+
+ // if buffer too small - allocate a larger one
+ if (dsResult == eDSBufferTooSmall) {
+ u_int32_t size = userRcdDataBufferPtr->fBufferSize * 2;
+
+ dsDataBufferDeAllocate(dirRef, userRcdDataBufferPtr);
+ if ((userRcdDataBufferPtr = dsDataBufferAllocate(dirRef, size)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n");
+ dsResult = -1;
+ goto cleanup;
+ }
+ }
+ } while (dsResult == eDSBufferTooSmall);
+
+ if (dsResult == eDSNoErr) {
+ // for each user record
+ for (userRecordIndex = 1; (userRecordIndex <= outRecordCount) && (dsResult == eDSNoErr)
+ && (userRcdFound == 0); userRecordIndex++) {
+
+ tAttributeListRef attrListRef;
+ tRecordEntryPtr userRcdEntryPtr;
+
+ // get the user record entry from the data buffer
+ if ((dsResult = dsGetRecordEntry(searchNodeRef, userRcdDataBufferPtr, userRecordIndex,
+ &attrListRef, &userRcdEntryPtr)) == eDSNoErr) {
+ // for each attribute
+ for (attrIndex = 1; (attrIndex <= userRcdEntryPtr->fRecordAttributeCount)
+ && (dsResult == eDSNoErr); attrIndex++) {
+
+ tAttributeValueListRef attrValueListRef;
+ tAttributeEntryPtr attrInfoPtr;
+ tAttributeValueEntryPtr attrValuePtr;
+
+ if ((dsResult = dsGetAttributeEntry(searchNodeRef, userRcdDataBufferPtr,
+ attrListRef, attrIndex, &attrValueListRef, &attrInfoPtr)) == eDSNoErr) {
+ if ((dsResult = dsGetAttributeValue(searchNodeRef, userRcdDataBufferPtr, 1,
+ attrValueListRef, &attrValuePtr)) == eDSNoErr) {
+
+ // check for user record name or attribute searching for
+ if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, kDSNAttrRecordName)) {
+ if (!strcmp(attrValuePtr->fAttributeValueData.fBufferData, user_name))
+ userRcdFound = 1;
+ }
+ if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, kDS1AttrDistinguishedName)) {
+ if (!strcmp(attrValuePtr->fAttributeValueData.fBufferData, user_name))
+ userRcdFound = 1;
+ }
+ if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, attr)) {
+ *attr_value = attrValuePtr; // return the attribute value
+ attrValuePtr = 0; // set to zero so we don't deallocate it
+ }
+ if (attrValuePtr)
+ dsDeallocAttributeValueEntry(dirRef, attrValuePtr);
+ }
+ dsCloseAttributeValueList(attrValueListRef);
+ dsDeallocAttributeEntry(dirRef, attrInfoPtr);
+ }
+ }
+ // make sure we've processed both attributes and we have a match on user name
+ if(userRcdFound == 0 || *attr_value == 0) {
+ userRcdFound = 0;
+ if (*attr_value)
+ dsDeallocAttributeValueEntry(dirRef, *attr_value);
+ *attr_value = 0;
+ }
+ dsCloseAttributeList(attrListRef);
+ dsDeallocRecordEntry(dirRef, userRcdEntryPtr);
+ }
+ }
+ }
+
+cleanup:
+ if (continueData)
+ dsReleaseContinueData(searchNodeRef, continueData);
+ if (userRcdDataBufferPtr)
+ dsDataBufferDeAllocate(dirRef, userRcdDataBufferPtr);
+ if (recordNameDataListPtr)
+ dsDataListDeallocate(dirRef, recordNameDataListPtr);
+ if (recordTypeDataListPtr)
+ dsDataListDeallocate(dirRef, recordTypeDataListPtr);
+ if (attrTypeDataListPtr)
+ dsDataListDeallocate(dirRef, attrTypeDataListPtr);
+
+ return dsResult;
+
+}
+
+
+//----------------------------------------------------------------------
+// open_dir_check_group_membership
+//----------------------------------------------------------------------
+static tDirStatus open_dir_check_group_membership(tDirReference dirRef, tDirNodeReference searchNodeRef,
+ char *group_name, char *user_name, char *userGID, int *authorized)
+{
+ tDirStatus dsResult = -1;
+
+ tDataBufferPtr groupRcdDataBufferPtr = 0;
+ tDataListPtr recordNameDataListPtr = 0;
+ tDataListPtr recordTypeDataListPtr = 0;
+ tDataListPtr attrTypeDataListPtr = 0;
+ tContextData continueData = 0;
+
+ unsigned long outRecordCount;
+ u_int32_t attrIndex, valueIndex;
+
+ *authorized = 0;
+
+ if ((groupRcdDataBufferPtr = dsDataBufferAllocate(dirRef, BUF_LEN)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n");
+ goto cleanup;
+ }
+ if ((recordNameDataListPtr = dsBuildListFromStrings(dirRef, group_name, 0)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n");
+ goto cleanup;
+ }
+ if ((recordTypeDataListPtr = dsBuildListFromStrings(dirRef, kDSStdRecordTypeGroups, 0)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n");
+ goto cleanup;
+ }
+ if ((attrTypeDataListPtr = dsBuildListFromStrings(dirRef, kDS1AttrPrimaryGroupID, kDSNAttrGroupMembership, 0)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataList\n");
+ goto cleanup;
+ }
+
+ // find the group record, extracting the group ID and group membership attribute
+ do {
+ dsResult = dsGetRecordList(searchNodeRef, groupRcdDataBufferPtr, recordNameDataListPtr, eDSExact,
+ recordTypeDataListPtr, attrTypeDataListPtr, 0, &outRecordCount, &continueData);
+ // if buffer too small - allocate a larger one
+ if (dsResult == eDSBufferTooSmall) {
+ u_int32_t size = groupRcdDataBufferPtr->fBufferSize * 2;
+
+ dsDataBufferDeAllocate(dirRef, groupRcdDataBufferPtr);
+ if ((groupRcdDataBufferPtr = dsDataBufferAllocate(dirRef, size)) == 0) {
+ plog(LLV_ERROR, LOCATION, NULL, "Could not allocate tDataBuffer\n");
+ dsResult = -1;
+ goto cleanup;
+ }
+ }
+ } while (dsResult == eDSBufferTooSmall);
+
+ if (dsResult == eDSNoErr) {
+
+ tAttributeListRef attrListRef;
+ tRecordEntryPtr groupRcdEntryPtr;
+
+ // get the group record entry
+ if ((dsResult = dsGetRecordEntry(searchNodeRef, groupRcdDataBufferPtr, 1, &attrListRef, &groupRcdEntryPtr)) == eDSNoErr) {
+
+ // for each attribute
+ for (attrIndex = 1; (attrIndex <= groupRcdEntryPtr->fRecordAttributeCount) && (dsResult == eDSNoErr)
+ && (*authorized == 0); attrIndex++) {
+
+ tAttributeValueListRef attrValueListRef;
+ tAttributeEntryPtr attrInfoPtr;
+ tAttributeValueEntryPtr attrValuePtr;
+
+ if ((dsResult = dsGetAttributeEntry(searchNodeRef, groupRcdDataBufferPtr, attrListRef,
+ attrIndex, &attrValueListRef, &attrInfoPtr)) == eDSNoErr) {
+
+ // group ID attribute ?
+ if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, kDS1AttrPrimaryGroupID)) {
+ if ((dsResult = dsGetAttributeValue(searchNodeRef, groupRcdDataBufferPtr, 1,
+ attrValueListRef, &attrValuePtr)) == eDSNoErr) {
+
+ // check for match on primary group ID
+ if (!strcmp(attrValuePtr->fAttributeValueData.fBufferData, userGID))
+ *authorized = 1;
+ dsDeallocAttributeValueEntry(dirRef, attrValuePtr);
+ }
+ } else if (!strcmp(attrInfoPtr->fAttributeSignature.fBufferData, kDSNAttrGroupMembership)) {
+ // for each value check for user's name in the group
+ for (valueIndex = 1; (valueIndex <= attrInfoPtr->fAttributeValueCount)
+ && (dsResult == eDSNoErr) && (*authorized == 0); valueIndex++) {
+
+ if ((dsResult = dsGetAttributeValue(searchNodeRef, groupRcdDataBufferPtr,
+ valueIndex, attrValueListRef, &attrValuePtr)) == eDSNoErr) {
+ if (!strcmp(attrValuePtr->fAttributeValueData.fBufferData, user_name))
+ *authorized = 1;
+ dsDeallocAttributeValueEntry(dirRef, attrValuePtr);
+ }
+ }
+ }
+ dsCloseAttributeValueList(attrValueListRef);
+ dsDeallocAttributeEntry(dirRef, attrInfoPtr);
+ }
+ }
+ dsCloseAttributeList(attrListRef);
+ dsDeallocRecordEntry(dirRef, groupRcdEntryPtr);
+ }
+ }
+
+cleanup:
+ if (continueData)
+ dsReleaseContinueData(searchNodeRef, continueData);
+ if (groupRcdDataBufferPtr)
+ dsDataBufferDeAllocate(dirRef, groupRcdDataBufferPtr);
+ if (recordNameDataListPtr)
+ dsDataListDeallocate(dirRef, recordNameDataListPtr);
+ if (recordTypeDataListPtr)
+ dsDataListDeallocate(dirRef, recordTypeDataListPtr);
+ if (attrTypeDataListPtr)
+ dsDataListDeallocate(dirRef, attrTypeDataListPtr);
+
+ return dsResult;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2001-2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef __OPEN_DIR_H__
+#define __OPEN_DIR_H__
+
+extern int open_dir_authorize_id(vchar_t *id, vchar_t *group);
+
+
+#endif /* __OPEN_DIR_H__ */
+
#include <net/route.h>
#include <net/pfkeyv2.h>
-#include <netkey/key_debug.h>
#include <netinet/in.h>
#ifdef IPV6_INRIA_VERSION
iph2->ph1->remote->sa_family == AF_INET)
{
flags |= SADB_X_EXT_NATT;
- port = ((struct sockaddr_in*)iph2->ph1->remote)->sin_port;
+ port = ntohs(((struct sockaddr_in*)iph2->ph1->remote)->sin_port);
}
#endif
iph2->ph1->remote->sa_family == AF_INET)
{
flags |= SADB_X_EXT_NATT;
- port = ((struct sockaddr_in*)iph2->ph1->remote)->sin_port;
+ port = ntohs(((struct sockaddr_in*)iph2->ph1->remote)->sin_port);
/* If we're the side behind the NAT, send keepalives */
if ((iph2->ph1->natt_flags & natt_no_local_nat) == 0)
|| mhp[SADB_EXT_ADDRESS_SRC] == NULL
|| mhp[SADB_EXT_ADDRESS_DST] == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
- "inappropriate sadb acquire message passed.\n");
+ "inappropriate sadb delete message passed.\n");
return -1;
}
msg = (struct sadb_msg *)mhp[0];
/* sanity check */
if (mhp[0] == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
- "inappropriate sadb acquire message passed.\n");
+ "inappropriate sadb flush message passed.\n");
return -1;
}
* SUCH DAMAGE.
*/
+#ifndef __PFKEY_H__
+#define __PFKEY_H__
+
+
struct pfkey_satype {
u_int8_t ps_satype;
const char *ps_name;
extern u_int32_t pk_getseq __P((void));
extern const char *sadbsecas2str
__P((struct sockaddr *, struct sockaddr *, int, u_int32_t, int));
+
+
+#endif /* __PFKEY_H__ */
+
#include <netinet6/ipsec.h>
#include <net/pfkeyv2.h>
#include <netkey/key_var.h>
-#include <netkey/key_debug.h>
#include <netinet/in.h>
#include <netinet6/ipsec.h>
* SUCH DAMAGE.
*/
+#ifndef __PLOG_H__
+#define __PLOG_H__
+
#define LC_DEFAULT_LOGF "/var/log/racoon.log"
#ifdef HAVE_STDARG_H
extern void plogdump __P((int, void *, size_t));
extern void ploginit __P((void));
extern void plogset __P((char *));
+
+#endif /* __PLOG_H__ */
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+#ifndef __POLICY_H__
+#define __POLICY_H__
+
#include <sys/queue.h>
extern struct ipsecrequest *newipsecreq __P((void));
extern const char *spidx2str __P((const struct policyindex *));
+
+
+#endif /* __POLICY_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __PROPOSAL_H__
+#define __PROPOSAL_H__
+
#include <sys/queue.h>
/*
extern int set_proposal_from_policy __P((struct ph2handle *,
struct secpolicy *, struct secpolicy *));
extern int set_proposal_from_proposal __P((struct ph2handle *));
+
+#endif /* __PROPOSAL_H__ */
+
delrmconf(rmconf)
struct remoteconf *rmconf;
{
+
if (rmconf->etypes)
deletypes(rmconf->etypes);
if (rmconf->dhgrp)
racoon_free(rmconf->remote);
if (rmconf->shared_secret)
vfree(rmconf->shared_secret);
-
+ if (rmconf->keychainCertRef)
+ CFRelease(rmconf->keychainCertRef);
+ if (rmconf->open_dir_auth_group)
+ vfree(rmconf->open_dir_auth_group);
+
racoon_free(rmconf);
}
* SUCH DAMAGE.
*/
+#ifndef __REMOTECONF_H__
+#define __REMOTECONF_H__
+
/* remote configuration */
#include <sys/queue.h>
+#include <CoreFoundation/CFData.h>
+
struct etypes {
int type;
/* if family is AF_UNSPEC, that is
* for anonymous configuration. */
- struct etypes *etypes; /* exchange type list. the head
- * is a type to be sent first. */
+ struct etypes *etypes; /* exchange type list. the head
+ * is a type to be sent first. */
int doitype; /* doi type */
int sittype; /* situation type */
int idvtype; /* my identifier type */
- vchar_t *idv; /* my identifier */
+ vchar_t *idv; /* my identifier */
int idvtype_p; /* peer's identifier type */
vchar_t *idv_p; /* peer's identifier */
int secrettype; /* type of secret [use, key, keychain] */
- vchar_t *shared_secret; /* shared secret */
-
+ vchar_t *shared_secret; /* shared secret */
+ vchar_t *open_dir_auth_group; /* group to be used to authorize user */
+
int certtype; /* certificate type if need */
+ int identity_in_keychain; /* cert and private key is in the keychain */
+ CFDataRef keychainCertRef; /* peristant keychain ref for cert */
char *mycertfile; /* file name of my certificate */
char *myprivfile; /* file name of my private key file */
- char *peerscertfile; /* file name of peer's certifcate */
+ char *peerscertfile; /* file name of peer's certifcate */
+
int getcert_method; /* the way to get peer's certificate */
int send_cert; /* send to CERT or not */
int send_cr; /* send to CR or not */
int verify_cert; /* verify a CERT strictly */
- int verify_identifier; /* vefify the peer's identifier */
+ int cert_verification; /* openssl or security framework */
+ int cert_verification_option; /* nothing, peers identifier, or open_dir */
+ int verify_identifier; /* vefify the peer's identifier */
int nonce_size; /* the number of bytes of nonce */
int keepalive; /* XXX may not use */
int passive; /* never initiate */
int support_mip6; /* support mip6 */
int gen_policy; /* generate policy if no policy found */
int ini_contact; /* initial contact */
- int pcheck_level; /* level of propocl checking */
+ int pcheck_level; /* level of protocol checking */
int dh_group; /* use it when only aggressive mode */
- struct dhgroup *dhgrp; /* use it when only aggressive mode */
- /* avobe two cann't be defined by user*/
+ struct dhgroup *dhgrp; /* use it when only aggressive mode */
+ /* above two can't be defined by user*/
int retry_counter; /* times to retry. */
int retry_interval; /* interval each retry. */
- /* above 2 values are copied from localconf. */
+ /* above 2 values are copied from localconf. */
- struct isakmpsa *proposal; /* proposal list */
+ struct isakmpsa *proposal; /* proposal list */
LIST_ENTRY(remoteconf) chain; /* next remote conf */
};
extern struct isakmpsa *newisakmpsa __P((void));
extern void insisakmpsa __P((struct isakmpsa *, struct remoteconf *));
extern const char *rm2str __P((const struct remoteconf *));
+
+#endif /* __REMOTECONF_H__ */
+
* #define INTERMEDIATE_VALUE_KAT to generate the Intermediate Value Known Answer Test.
*/
-#ifndef __RIJNDAEL_ALG_FST_H
-#define __RIJNDAEL_ALG_FST_H
+#ifndef __RIJNDAEL_ALG_FST_H__
+#define __RIJNDAEL_ALG_FST_H__
#define RIJNDAEL_MAXKC (256/32)
#define RIJNDAEL_MAXROUNDS 14
int rijndaelDecryptRound(u_int8_t a[4][4], u_int8_t rk[RIJNDAEL_MAXROUNDS+1][4][4], int ROUNDS, int rounds);
#endif /* INTERMEDIATE_VALUE_KAT */
-#endif /* __RIJNDAEL_ALG_FST_H */
+#endif /* __RIJNDAEL_ALG_FST_H__ */
+
* #define INTERMEDIATE_VALUE_KAT to generate the Intermediate Value Known Answer Test.
*/
-#ifndef __RIJNDAEL_API_FST_H
-#define __RIJNDAEL_API_FST_H
+#ifndef __RIJNDAEL_API_FST_H__
+#define __RIJNDAEL_API_FST_H__
#include <rijndael-alg-fst.h>
u_int8_t *input, int inputLen, u_int8_t *outBuffer, int Rounds);
#endif /* INTERMEDIATE_VALUE_KAT */
-#endif /* __RIJNDAEL_API_FST_H */
+#endif /* __RIJNDAEL_API_FST_H__ */
+
/* $KAME: rijndael.h,v 1.2 2000/10/02 17:14:27 itojun Exp $ */
+#ifndef __RIJNDAEL_H__
+#define __RIJNDAEL_H__
+
#include <rijndael-api-fst.h>
+
+
+#endif /* __RIJNDAEL_H__ */
+
/* $KAME: rijndael_local.h,v 1.3 2000/10/02 17:14:27 itojun Exp $ */
+#ifndef __RIJNDAEL_LOCAL_H__
+#define __RIJNDAEL_LOCAL_H__
+
/* the file should not be used from outside */
typedef u_int8_t BYTE;
typedef u_int8_t word8;
#define MAXKC RIJNDAEL_MAXKC
#define MAXROUNDS RIJNDAEL_MAXROUNDS
+
+
+#endif /* __RIJNDAEL_LOCAL_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __SAFEFILE_H__
+#define __SAFEFILE_H__
+
extern int safefile __P((const char *, int));
+
+#endif /* __SAFEFILE_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __SAINFO_H__
+#define __SAINFO_H__
+
#include <sys/queue.h>
/* SA info */
extern void delsainfoalg __P((struct sainfoalg *));
extern void inssainfoalg __P((struct sainfoalg **, struct sainfoalg *));
extern const char * sainfo2str __P((const struct sainfo *));
+
+#endif /* __SAINFO_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __SCHEDULE_H__
+#define __SCHEDULE_H__
+
#include <sys/queue.h>
/* scheduling table */
int sched_dump __P((caddr_t *, int *));
void sched_init __P((void));
void sched_scrub_param __P((void *));
+
+#endif /* __SCHEDULE_H__ */
+
continue;
if (FD_ISSET(p->sock, &rfds))
- isakmp_handler(p->sock);
+ if ((error = isakmp_handler(p->sock)) == -2)
+ break;
+
+
#ifdef IKE_NAT_T
if (p->nattsock >= 0 && FD_ISSET(p->nattsock, &rfds))
- isakmp_natt_handler(p->nattsock);
+ if ((error = isakmp_natt_handler(p->nattsock)) == -2)
+ break;
#endif
}
+ if (error == -2) {
+ if (lcconf->autograbaddr) {
+ /* serious socket problem - close all listening sockets and re-open */
+ isakmp_close();
+ initfds();
+ sched_new(5, check_rtsock, NULL);
+ continue;
+ } else {
+ isakmp_close_sockets();
+ isakmp_open();
+ }
+
+ }
if (FD_ISSET(lcconf->sock_pfkey, &rfds))
pfkey_handler();
* SUCH DAMAGE.
*/
+#ifndef __SESSION_H__
+#define __SESSION_H__
+
extern int session __P((void));
extern RETSIGTYPE signal_handler __P((int));
+
+
+#endif /* __SESSION_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __SOCKMISC_H__
+#define __SOCKMISC_H__
+
extern const int niflags;
extern int cmpsaddrwop __P((struct sockaddr *, struct sockaddr *));
extern struct sockaddr *str2saddr __P((char *, char *));
extern void mask_sockaddr __P((struct sockaddr *, const struct sockaddr *,
size_t));
+
+#endif /* __SOCKMISC_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __STR2VAL_H__
+#define __STR2VAL_H__
+
extern caddr_t val2str __P((const char *, size_t));
extern char *str2val __P((const char *, int, size_t *));
+
+
+#endif /* __STR2VAL_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __STRNAMES_H__
+#define __STRNAMES_H__
+
extern char * s_isakmp_state __P((int, int, int));
extern char *s_isakmp_certtype __P((int));
extern char *s_isakmp_etype __P((int));
extern char *s_pfkey_satype __P((int));
extern char *s_direction __P((int));
extern char *s_proto __P((int));
+
+#endif /* __STRNAMES_H__ */
+
* SUCH DAMAGE.
*/
-#if !defined(_VAR_H_)
-#define _VAR_H_
+#ifndef __VAR_H__
+#define __VAR_H__
#define MAX3(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#include "gcmalloc.h"
-#endif /*!defined(_VAR_H_)*/
+#endif /* __VAR_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __VENDORID_H__
+#define __VENDORID_H__
+
/* The unknown vendor ID. */
#define VENDORID_UNKNOWN -1
vchar_t *set_vendorid __P((int));
int check_vendorid __P((struct isakmp_gen *));
+
+
+#endif /* __VENDORID_H__ */
+
* SUCH DAMAGE.
*/
+#ifndef __VMBUF_H__
+#define __VMBUF_H__
+
/*
* bp v
* v v
extern vchar_t *vrealloc __P((vchar_t *, size_t));
extern void vfree __P((vchar_t *));
extern vchar_t *vdup __P((vchar_t *));
+
+
+#endif /* __VMBUF_H__ */
+
CFILES = rarpd.c
-OTHERSRCS = Makefile.dist Makefile.preamble rarpd.8
+OTHERSRCS = Makefile.dist Makefile.preamble rarpd.8 Makefile.postamble
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
--- /dev/null
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 rarpd.8 $(DSTROOT)/usr/share/man/man8/rarpd.8
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
after_install::
$(CHFLAGS) schg $(DSTROOT)$(INSTALLDIR)/$(NAME)
+ mkdir -p $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 rcp.1 $(DSTROOT)/usr/share/man/man1/rcp.1
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
CFILES = rexecd.c
-OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rexecd.8
+OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rexecd.8 exec.plist
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
# owned by the top-level Makefile API and no context has been set up for where
# derived files should go.
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 rexecd.8 $(DSTROOT)/usr/share/man/man8/rexecd.8
+ mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons"
+ cp exec.plist "$(DSTROOT)/System/Library/LaunchDaemons/"
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Disabled</key>
+ <true/>
+ <key>Label</key>
+ <string>com.apple.rexecd</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/libexec/rexecd</string>
+ </array>
+ <key>inetdCompatibility</key>
+ <dict>
+ <key>Wait</key>
+ <false/>
+ </dict>
+ <key>Sockets</key>
+ <dict>
+ <key>Listeners</key>
+ <dict>
+ <key>SockServiceName</key>
+ <string>exec</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
INSTALL_PERMISSIONS = 4755 # If set, 'install' chmod's executable to this
+
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 rlogin.1 $(DSTROOT)/usr/share/man/man1/rlogin.1
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
CFILES = rlogind.c
-OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rlogind.8
+OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rlogind.8 login.plist
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
VPATH += :../rlogin.tproj
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 rlogind.8 $(DSTROOT)/usr/share/man/man8/rlogind.8
+ mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons"
+ cp login.plist "$(DSTROOT)/System/Library/LaunchDaemons/"
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Disabled</key>
+ <true/>
+ <key>Label</key>
+ <string>com.apple.rlogind</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/libexec/rlogind</string>
+ </array>
+ <key>inetdCompatibility</key>
+ <dict>
+ <key>Wait</key>
+ <false/>
+ </dict>
+ <key>Sockets</key>
+ <dict>
+ <key>Listeners</key>
+ <dict>
+ <key>SockServiceName</key>
+ <string>login</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
getstr(term+ENVSIZE, sizeof(term)-ENVSIZE, "Terminal type too long");
pwd = getpwnam(lusername);
- if (pwd == NULL)
+ if (pwd == NULL) {
+ syslog(LOG_ERR,
+ "rlogin denied for user %s: getpwnam() failed\n",
+ lusername);
return (-1);
- if (pwd->pw_uid == 0)
+ }
+ if (pwd->pw_uid == 0 && strcmp("root", lusername))
+ {
+ syslog(LOG_ALERT,
+ "rlogin denied for non-root user %s with uid 0\n",
+ lusername);
return (-1);
- /* XXX why don't we syslog() failure? */
+ }
return (iruserok(dest->sin_addr.s_addr, 0, rusername, lusername));
}
PROF_LIBS = $(LIBS)
+HEADER_PATHS =\
+ -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/
NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
PROF_LIBS = $(LIBS)
+HEADER_PATHS =\
+ -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/
NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
static struct timeval lastlog;
static char *savetracename;
+static int iftraceinit();
+
traceinit(ifp)
register struct interface *ifp;
{
- static int iftraceinit();
if (iftraceinit(ifp, &ifp->int_input) &&
iftraceinit(ifp, &ifp->int_output))
fprintf(stderr, "traceinit: can't init %s\n", ifp->int_name);
}
-static
+
iftraceinit(ifp, ifd)
struct interface *ifp;
register struct ifdebug *ifd;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
client_request(void)
{
LOCKD_MSG msg;
-/*
- * select on FIFOs can currently hang, so we'll use
- * the nfslockdwait syscall instead for now.
- */
-#define USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT 1
-#ifndef USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT
fd_set rdset;
-#endif
int fd, nr, ret;
pid_t child;
mode_t old_umask;
}
for (;;) {
-#ifndef USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT
/* Wait for contact... fifo's return EAGAIN when read with
* no data
*/
FD_ZERO(&rdset);
FD_SET(fd, &rdset);
(void)select(fd + 1, &rdset, NULL, NULL, NULL);
-#endif
/* Read the fixed length message. */
if ((nr = read(fd, &msg, sizeof(msg))) == sizeof(msg)) {
syslog(LOG_ERR, "read: %s: %m", _PATH_LCKFIFO);
goto err;
}
-#ifdef USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT
- else
- nfsclnt(NFSCLNT_LOCKDWAIT, NULL);
-#endif
} else if (nr != 0) {
syslog(LOG_ERR,
"%s: discard %d bytes", _PATH_LCKFIFO, nr);
}
-#ifdef USE_NFSLOCKDWAIT_INSTEAD_OF_SELECT
- else
- nfsclnt(NFSCLNT_LOCKDWAIT, NULL);
-#endif
}
/* Reached only on error. */
show(LOCKD_MSG *mp)
{
static char hex[] = "0123456789abcdef";
- struct fid *fidp;
- fsid_t *fsidp;
size_t len;
u_int8_t *p, *t, buf[NFS_SMALLFH*3+1];
syslog(LOG_DEBUG, "process ID: %lu\n", (long)mp->lm_fl.l_pid);
- fsidp = (fsid_t *)&mp->lm_fh;
- fidp = (struct fid *)((u_int8_t *)&mp->lm_fh + sizeof(fsid_t));
-
for (t = buf, p = (u_int8_t *)mp->lm_fh,
len = mp->lm_fh_len;
len > 0; ++p, --len) {
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/resource.h>
+#include <sys/sysctl.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
struct sigaction sigalarm;
int grace_period = 30;
struct rlimit rlp;
+ int mib[6];
+ int oldstate;
+ int oldsize;
+ int newstate;
while ((ch = getopt(argc, argv, "d:g:wx:")) != (-1)) {
switch (ch) {
signal(SIGHUP, handle_sig_cleanup);
signal(SIGQUIT, handle_sig_cleanup);
+
+
openlog("rpc.lockd", debug_level == 99 ? LOG_PERROR : 0, LOG_DAEMON);
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROCDELAYTERM;
+
+ oldstate = 0;
+ oldsize = 4;
+ newstate = 1;
+
+ if (sysctl(mib, 2, &oldstate, &oldsize, &newstate, 4) < 0) {
+ syslog(LOG_INFO, "cannot mark pid for delayed termination");
+ }
+
if (claim_pid_file("/var/run/lockd.pid", 0) < 0) {
syslog(LOG_ERR, "cannot claim pid file");
exit(1);
enum partialfilelock_status { PFL_GRANTED=0, PFL_GRANTED_DUPLICATE, PFL_DENIED,
PFL_NFSDENIED, PFL_NFSBLOCKED, PFL_NFSDENIED_NOLOCK, PFL_NFSRESERR,
- PFL_HWDENIED, PFL_HWBLOCKED, PFL_HWDENIED_NOLOCK, PFL_HWRESERR};
+ PFL_HWDENIED, PFL_HWBLOCKED, PFL_HWDENIED_NOLOCK, PFL_HWRESERR,
+ PFL_HWDENIED_STALEFH, PFL_HWDENIED_READONLY };
enum LFLAGS {LEDGE_LEFT, LEDGE_LBOUNDARY, LEDGE_INSIDE, LEDGE_RBOUNDARY, LEDGE_RIGHT};
enum RFLAGS {REDGE_LEFT, REDGE_LBOUNDARY, REDGE_INSIDE, REDGE_RBOUNDARY, REDGE_RIGHT};
void clear_partialfilelock(const char *hostname);
enum partialfilelock_status test_partialfilelock(
const struct file_lock *fl, struct file_lock **conflicting_fl);
-enum nlm_stats do_test(struct file_lock *fl,
- struct file_lock **conflicting_fl);
-enum nlm_stats do_unlock(struct file_lock *fl);
-enum nlm_stats do_lock(struct file_lock *fl);
+enum nlm4_stats do_test(struct file_lock *fl, struct file_lock **conflicting_fl);
+enum nlm4_stats do_unlock(struct file_lock *fl);
+enum nlm4_stats do_lock(struct file_lock *fl);
void do_clear(const char *hostname);
{
struct monfile *imf,*nmf;
int lflags, flerror;
+ fhandle_t fh;
/* Scan to see if filehandle already present */
LIST_FOREACH(imf, &monfilelist_head, monfilelist) {
return (HW_RESERR);
}
+ if (fl->filehandle.n_len > NFS_MAX_FH_SIZE) {
+ debuglog("hwlock: bad fh length %d (from %16s): %32s\n",
+ fl->filehandle.n_len, fl->client_name, strerror(errno));
+ free(nmf->filehandle.n_bytes);
+ free(nmf);
+ return (HW_STALEFH);
+ }
+ fh.fh_len = fl->filehandle.n_len;
+ bcopy(fl->filehandle.n_bytes, fh.fh_data, fh.fh_len);
+
/* XXX: Is O_RDWR always the correct mode? */
- nmf->fd = fhopen((fhandle_t *)fl->filehandle.n_bytes, O_RDWR);
+ nmf->fd = fhopen(&fh, O_RDWR);
if (nmf->fd < 0) {
debuglog("fhopen failed (from %16s): %32s\n",
fl->client_name, strerror(errno));
do_unlock(ifl);
/* ifl is NO LONGER VALID AT THIS POINT */
}
+ } else if (pflstatus == PFL_HWDENIED_STALEFH) {
+ /*
+ * Uh oh...
+ * It would be nice if we could inform the client of
+ * this error. Unfortunately, there's no way to do
+ * that in the NLM protocol (can't send "granted"
+ * message with an error and there's no "never going
+ * to be granted" message).
+ *
+ * Since there's no chance of this blocked request ever
+ * succeeding, we drop the lock request rather than
+ * needlessly keeping it around just to rot forever in
+ * the blocked lock list.
+ *
+ * Hopefully, if the client is still waiting for the lock,
+ * they will resend the request (and get an error then).
+ *
+ * XXX Note: PFL_HWDENIED_READONLY could potentially
+ * be handled this way as well, although that would
+ * only be an issue if a file system changed from
+ * read-write to read-only out from under a blocked
+ * lock request, and that's far less likely than a
+ * file disappearing out from under such a request.
+ */
+ deallocate_file_lock(ifl);
+ /* ifl is NO LONGER VALID AT THIS POINT */
} else {
/* Reinsert lock back into same place in blocked list */
debuglog("Replacing blocked lock\n");
LIST_INSERT_HEAD(&blockedlocklist_head, ifl, nfslocklist);
}
- if (pflstatus == PFL_GRANTED || pflstatus == PFL_GRANTED_DUPLICATE) {
- /* If ifl was permanently removed from the list, (e.g the */
- /* lock was granted), pfl should remain where it's at. */
+ if (pflstatus == PFL_GRANTED || pflstatus == PFL_GRANTED_DUPLICATE ||
+ pflstatus == PFL_HWDENIED_STALEFH) {
+ /* If ifl was permanently removed from the list, (e.g it */
+ /* was granted or dropped), pfl should remain where it's at. */
} else {
/* If ifl was left in the list, (e.g it was reinserted back */
/* in place), pfl should simply be moved forward to be ifl */
debuglog("HW DENIED\n");
retval = PFL_HWDENIED;
break;
+ case HW_DENIED_NOLOCK:
+ debuglog("HW DENIED NOLOCK\n");
+ retval = PFL_HWDENIED_NOLOCK;
+ break;
+ case HW_STALEFH:
+ debuglog("HW STALE FH\n");
+ retval = PFL_HWDENIED_STALEFH;
+ break;
+ case HW_READONLY:
+ debuglog("HW READONLY\n");
+ retval = PFL_HWDENIED_READONLY;
+ break;
default:
debuglog("Unmatched hwstatus %d\n",hwstatus);
break;
clear_partialfilelock(const char *hostname)
{
struct file_lock *ifl, *nfl;
+ enum partialfilelock_status pfsret;
/* Clear blocking file lock list */
clear_blockingfilelock(hostname);
* would mess up the iteration. Thus, a next element
* must be used explicitly
*/
-
+restart:
ifl = LIST_FIRST(&nfslocklist_head);
while (ifl != NULL) {
if (strncmp(hostname, ifl->client_name, SM_MAXSTRLEN) == 0) {
/* Unlock destroys ifl out from underneath */
- unlock_partialfilelock(ifl);
+ pfsret = unlock_partialfilelock(ifl);
+ if (pfsret != PFL_GRANTED) {
+ /* Uh oh... there was some sort of problem. */
+ /* If we restart the loop, we may get */
+ /* stuck here forever getting errors. */
+ /* So, let's just abort the whole scan. */
+ syslog(LOG_WARNING, "lock clearing for %s failed: %d",
+ hostname, pfsret);
+ break;
+ }
/* ifl is NO LONGER VALID AT THIS POINT */
+ /* Note: the unlock may deallocate several existing locks. */
+ /* Therefore, we need to restart the scanning of the list, */
+ /* because nfl could be pointing to a freed lock. */
+ goto restart;
}
ifl = nfl;
}
* the few return codes which the nlm subsystems wishes to trasmit
*/
-enum nlm_stats
+enum nlm4_stats
do_test(struct file_lock *fl, struct file_lock **conflicting_fl)
{
enum partialfilelock_status pfsret;
- enum nlm_stats retval;
+ enum nlm4_stats retval;
debuglog("Entering do_test...\n");
* convinced that this should be abstracted out and bounced up a level
*/
-enum nlm_stats
+enum nlm4_stats
do_lock(struct file_lock *fl)
{
enum partialfilelock_status pfsret;
- enum nlm_stats retval;
+ enum nlm4_stats retval;
debuglog("Entering do_lock...\n");
break;
case PFL_NFSRESERR:
case PFL_HWRESERR:
+ case PFL_NFSDENIED_NOLOCK:
+ case PFL_HWDENIED_NOLOCK:
debuglog("PFL lock resource alocation fail\n");
dump_filelock(fl);
retval = (fl->flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks;
break;
+ case PFL_HWDENIED_STALEFH:
+ debuglog("PFL_NFS lock denied STALEFH");
+ dump_filelock(fl);
+ retval = (fl->flags & LOCK_V4) ? nlm4_stale_fh : nlm_denied;
+ break;
+ case PFL_HWDENIED_READONLY:
+ debuglog("PFL_NFS lock denied READONLY");
+ dump_filelock(fl);
+ retval = (fl->flags & LOCK_V4) ? nlm4_rofs : nlm_denied;
+ break;
default:
debuglog("PFL lock *FAILED*");
dump_filelock(fl);
return retval;
}
-enum nlm_stats
+enum nlm4_stats
do_unlock(struct file_lock *fl)
{
enum partialfilelock_status pfsret;
- enum nlm_stats retval;
+ enum nlm4_stats retval;
debuglog("Entering do_unlock...\n");
pfsret = unlock_partialfilelock(fl);
{
struct file_lock test_fl, *conflicting_fl;
- if (lock->fh.n_len != sizeof(fhandle_t)) {
- debuglog("received fhandle size %d, local size %d",
- lock->fh.n_len, (int)sizeof(fhandle_t));
+ if (lock->fh.n_len > NFS_MAX_FH_SIZE) {
+ debuglog("received fhandle size %d, max size %d",
+ lock->fh.n_len, NFS_MAX_FH_SIZE);
return NULL;
}
* will do the blocking lock.
*/
-enum nlm_stats
+enum nlm4_stats
getlock(nlm4_lockargs *lckarg, struct svc_req *rqstp, const int flags)
{
struct file_lock *newfl;
- enum nlm_stats retval;
+ enum nlm4_stats retval;
debuglog("Entering getlock...\n");
return (flags & LOCK_V4) ?
nlm4_denied_grace_period : nlm_denied_grace_period;
- if (lckarg->alock.fh.n_len != sizeof(fhandle_t)) {
- debuglog("received fhandle size %d, local size %d",
- lckarg->alock.fh.n_len, (int)sizeof(fhandle_t));
+ if (lckarg->alock.fh.n_len > NFS_MAX_FH_SIZE) {
+ debuglog("received fhandle size %d, max size %d",
+ lckarg->alock.fh.n_len, NFS_MAX_FH_SIZE);
return (flags & LOCK_V4) ? nlm4_failed : nlm_denied;
}
/* unlock a filehandle */
-enum nlm_stats
+enum nlm4_stats
unlock(nlm4_lock *lock, const int flags)
{
struct file_lock fl;
- enum nlm_stats err;
+ enum nlm4_stats err;
debuglog("Entering unlock...\n");
- if (lock->fh.n_len != sizeof(fhandle_t)) {
- debuglog("received fhandle size %d, local size %d",
- lock->fh.n_len, (int)sizeof(fhandle_t));
+ if (lock->fh.n_len > NFS_MAX_FH_SIZE) {
+ debuglog("received fhandle size %d, max size %d",
+ lock->fh.n_len, NFS_MAX_FH_SIZE);
return (flags & LOCK_V4) ? nlm4_failed : nlm_denied;
}
}
/* cancel a blocked lock request */
-enum nlm_stats
+enum nlm4_stats
cancellock(nlm4_cancargs *args, const int flags)
{
struct file_lock *ifl, *nfl;
- enum nlm_stats err;
+ enum nlm4_stats err;
debuglog("Entering cancellock...\n");
- if (args->alock.fh.n_len != sizeof(fhandle_t)) {
- debuglog("received fhandle size %d, local size %d",
- args->alock.fh.n_len, (int)sizeof(fhandle_t));
+ if (args->alock.fh.n_len > NFS_MAX_FH_SIZE) {
+ debuglog("received fhandle size %d, max size %d",
+ args->alock.fh.n_len, NFS_MAX_FH_SIZE);
return (flags & LOCK_V4) ? nlm4_failed : nlm_denied;
}
siglock();
- err = nlm_denied;
+ err = (flags & LOCK_V4) ? nlm4_denied : nlm_denied;
/*
* scan blocked lock list for matching request and remove/destroy
/* got it */
remove_blockingfilelock(ifl);
deallocate_file_lock(ifl);
- err = nlm_granted;
+ err = (flags & LOCK_V4) ? nlm4_granted : nlm_granted;
break;
}
/*
* getshare: try to acquire a share reservation
*/
-enum nlm_stats
+enum nlm4_stats
getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags)
{
struct sharefile *shrfile;
nlm_denied_grace_period;
}
- if (shrarg->share.fh.n_len != sizeof(fhandle_t)) {
- debuglog("received fhandle size %d, local size %d",
- shrarg->share.fh.n_len, (int)sizeof(fhandle_t));
+ if (shrarg->share.fh.n_len > NFS_MAX_FH_SIZE) {
+ debuglog("received fhandle size %d, max size %d",
+ shrarg->share.fh.n_len, NFS_MAX_FH_SIZE);
return (flags & LOCK_V4) ? nlm4_failed : nlm_denied;
}
/* if share file not found, create a new share file */
if (!shrfile) {
+ fhandle_t fh;
int fd;
- fd = fhopen((fhandle_t *)shrarg->share.fh.n_bytes, O_RDONLY);
+ fh.fh_len = shrarg->share.fh.n_len;
+ bcopy(shrarg->share.fh.n_bytes, fh.fh_data, fh.fh_len);
+ fd = fhopen(&fh, O_RDONLY);
if (fd < 0) {
debuglog("fhopen failed (from %16s): %32s\n",
shrarg->share.caller_name, strerror(errno));
if (!shrfile) {
debuglog("getshare failed: can't allocate sharefile\n");
close(fd);
- return (flags & LOCK_V4) ? nlm4_failed : nlm_denied;
+ return (flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks;
}
shrfile->filehandle.n_len = shrarg->share.fh.n_len;
shrfile->filehandle.n_bytes = malloc(shrarg->share.fh.n_len);
debuglog("getshare failed: can't allocate sharefile filehandle\n");
free(shrfile);
close(fd);
- return (flags & LOCK_V4) ? nlm4_failed : nlm_denied;
+ return (flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks;
}
bcopy(shrarg->share.fh.n_bytes, shrfile->filehandle.n_bytes,
shrarg->share.fh.n_len);
sh->mode = shrarg->share.mode;
sh->access = shrarg->share.access;
debuglog("getshare: updated existing share\n");
- return nlm_granted;
+ return (flags & LOCK_V4) ? nlm4_granted : nlm_granted;
}
if (((shrarg->share.mode & sh->access) != 0) ||
((shrarg->share.access & sh->mode) != 0)) {
/* share request conflicts with existing share */
debuglog("getshare: conflicts with existing share\n");
- return nlm_denied;
+ return (flags & LOCK_V4) ? nlm4_denied : nlm_denied;
}
}
free(shrfile->filehandle.n_bytes);
free(shrfile);
}
- return (flags & LOCK_V4) ? nlm4_failed : nlm_denied;
+ return (flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks;
}
bzero(sh, sizeof(*sh) - sizeof(sh->client_name));
sh->oh.n_len = shrarg->share.oh.n_len;
free(shrfile->filehandle.n_bytes);
free(shrfile);
}
- return (flags & LOCK_V4) ? nlm4_failed : nlm_denied;
+ return (flags & LOCK_V4) ? nlm4_denied_nolocks : nlm_denied_nolocks;
}
memcpy(sh->client_name, shrarg->share.caller_name, n);
sh->client_name[n] = 0;
debuglog("Exiting getshare...\n");
- return nlm_granted;
+ return (flags & LOCK_V4) ? nlm4_granted : nlm_granted;
}
/* remove a share reservation */
-enum nlm_stats
+enum nlm4_stats
unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags)
{
struct sharefile *shrfile;
debuglog("Entering unshare...\n");
- if (shrarg->share.fh.n_len != sizeof(fhandle_t)) {
- debuglog("received fhandle size %d, local size %d",
- shrarg->share.fh.n_len, (int)sizeof(fhandle_t));
+ if (shrarg->share.fh.n_len > NFS_MAX_FH_SIZE) {
+ debuglog("received fhandle size %d, max size %d",
+ shrarg->share.fh.n_len, NFS_MAX_FH_SIZE);
return (flags & LOCK_V4) ? nlm4_failed : nlm_denied;
}
/* if share file not found, return success (per spec) */
if (!shrfile) {
debuglog("unshare: no such share file\n");
- return nlm_granted;
+ return (flags & LOCK_V4) ? nlm4_granted : nlm_granted;
}
/* find share */
/* if share not found, return success (per spec) */
if (!sh) {
debuglog("unshare: no such share\n");
- return nlm_granted;
+ return (flags & LOCK_V4) ? nlm4_granted : nlm_granted;
}
/* remove share from file and deallocate */
debuglog("Exiting unshare...\n");
- return nlm_granted;
+ return (flags & LOCK_V4) ? nlm4_granted : nlm_granted;
}
/*
struct file_lock *ifl, *nfl;
struct sharefile *shrfile, *nshrfile;
struct file_share *ifs, *nfs;
+ enum partialfilelock_status pfsret;
/* clear non-monitored blocking file locks */
ifl = LIST_FIRST(&blockedlocklist_head);
}
/* clear non-monitored file locks */
+restart:
ifl = LIST_FIRST(&nfslocklist_head);
while (ifl != NULL) {
nfl = LIST_NEXT(ifl, nfslocklist);
if (((ifl->flags & LOCK_MON) == 0) &&
(strncmp(hostname, ifl->client_name, SM_MAXSTRLEN) == 0)) {
/* Unlock destroys ifl out from underneath */
- unlock_partialfilelock(ifl);
+ pfsret = unlock_partialfilelock(ifl);
+ if (pfsret != PFL_GRANTED) {
+ /* Uh oh... there was some sort of problem. */
+ /* If we restart the loop, we may get */
+ /* stuck here forever getting errors. */
+ /* So, let's just abort the whole scan. */
+ syslog(LOG_WARNING, "unmonitored lock clearing for %s failed: %d",
+ hostname, pfsret);
+ break;
+ }
/* ifl is NO LONGER VALID AT THIS POINT */
+ /* Note: the unlock may deallocate several existing locks. */
+ /* Therefore, we need to restart the scanning of the list, */
+ /* because nfl could be pointing to a freed lock. */
+ goto restart;
}
ifl = nfl;
#ifndef LOCKD_LOCK_H
#define LOCKD_LOCK_H
struct nlm4_holder * testlock(struct nlm4_lock *lock, bool_t exclusive, int flags);
-enum nlm_stats getlock(nlm4_lockargs *lckarg, struct svc_req *rqstp, const int flags);
-enum nlm_stats unlock(nlm4_lock *lock, const int flags);
-enum nlm_stats cancellock(nlm4_cancargs *args, const int flags);
+enum nlm4_stats getlock(nlm4_lockargs *lckarg, struct svc_req *rqstp, const int flags);
+enum nlm4_stats unlock(nlm4_lock *lock, const int flags);
+enum nlm4_stats cancellock(nlm4_cancargs *args, const int flags);
int lock_answer(int version, netobj *netcookie, nlm4_lock *lock, int flags, int result);
-enum nlm_stats getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags);
-enum nlm_stats unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags);
+enum nlm4_stats getshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags);
+enum nlm4_stats unshare(nlm_shareargs *shrarg, struct svc_req *rqstp, const int flags);
void do_free_all(const char *hostname);
void granted_failed(nlm4_res *arg);
hp = find_host(arg->mon_name, FALSE);
if (!hp)
{
- /* Never heard of this host - why is it notifying us? */
- syslog(LOG_DEBUG, "Unsolicited notification from host %s", arg->mon_name);
- return (&dummy);
+ /*
+ * Hmmm... We've never heard of this host.
+ * It's possible the host just didn't give us the right hostname.
+ * Let's try the IP address the request came from and any hostnames it has.
+ */
+ struct sockaddr_in *claddr;
+ if ((claddr = svc_getcaller(req->rq_xprt))) {
+ struct hostent *he;
+ he = gethostbyaddr((char*)&claddr->sin_addr, sizeof(claddr->sin_addr), AF_INET);
+ if (he) {
+ char **np = he->h_aliases;
+ hp = find_host(he->h_name, FALSE);
+ while (!hp && *np) {
+ hp = find_host(*np, FALSE);
+ if (!hp)
+ np++;
+ }
+ }
+ if (hp)
+ syslog(LOG_DEBUG, "Notification from host %s found as %s",
+ arg->mon_name, hp->hostname);
+ }
+ if (!hp) {
+ /* Never heard of this host - why is it notifying us? */
+ syslog(LOG_DEBUG, "Unsolicited notification from host %s", arg->mon_name);
+ return (&dummy);
+ }
}
lp = hp->monList;
if (!lp) return (&dummy); /* We know this host, but have no */
while (lp)
{
- tx_arg.mon_name = arg->mon_name;
+ tx_arg.mon_name = hp->hostname;
tx_arg.state = arg->state;
memcpy(tx_arg.priv, lp->notifyData, sizeof(tx_arg.priv));
cli = clnt_create(lp->notifyHost, lp->notifyProg, lp->notifyVers, "udp");
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/sysctl.h>
#include "statd.h"
int debug = 0; /* Controls syslog() calls for debug messages */
SVCXPRT *transp;
struct sigaction sa;
int c;
- struct timespec ts;
+ int mib[6];
+ int oldstate;
+ int oldsize;
+ int newstate;
+
while ((c = getopt(argc, argv, "dn")) != EOF)
switch (c) {
/* protocol assumes that it will run immediately at boot time. */
daemon(0, 0);
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROCDELAYTERM;
+
+ oldstate = 0;
+ oldsize = 4;
+ newstate = 1;
+
+ if (sysctl(mib, 2, &oldstate, &oldsize, &newstate, 4) < 0) {
+ syslog(LOG_INFO, "cannot mark pid for delayed termination");
+ }
+
+
if (claim_pid_file("/var/run/statd.pid", 0) < 0)
errx(1, "rpc.statd already running");
- /* start portmapper, in case it hasn't been started yet */
- system("portmap");
- /* sleep a little to give portmap a chance to start */
- /* (better to sleep 50ms now than to timeout on portmap calls) */
- ts.tv_sec = 0;
- ts.tv_nsec = 50*1000*1000;
- nanosleep(&ts, NULL);
-
(void)pmap_unset(SM_PROG, SM_VERS);
transp = svcudp_create(RPC_ANYSOCK);
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
after_install::
$(CHFLAGS) schg $(DSTROOT)$(INSTALLDIR)/$(NAME)
+ install -d $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 rsh.1 $(DSTROOT)/usr/share/man/man1/rsh.1
CFILES = rshd.c
-OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rshd.8
+OTHERSRCS = Makefile.preamble Makefile Makefile.postamble rshd.8 shell.plist
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
VPATH += :../rlogin.tproj
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 rshd.8 $(DSTROOT)/usr/share/man/man8/rshd.8
+ mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons"
+ cp shell.plist "$(DSTROOT)/System/Library/LaunchDaemons/"
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Disabled</key>
+ <true/>
+ <key>Label</key>
+ <string>com.apple.rshd</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/libexec/rshd</string>
+ </array>
+ <key>inetdCompatibility</key>
+ <dict>
+ <key>Wait</key>
+ <false/>
+ </dict>
+ <key>Sockets</key>
+ <dict>
+ <key>Listeners</key>
+ <dict>
+ <key>SockServiceName</key>
+ <string>shell</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
PROF_LIBS = $(LIBS)
+HEADER_PATHS =\
+ -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/
NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD
PROF_LIBS = $(LIBS)
+HEADER_PATHS =\
+ -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/
NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD
#
# Note: on MS Windows, executables, have an extension, so rules and dependencies
# for generated tools should use $(EXECUTABLE_EXT) on the end.
+
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 ruptime.1 $(DSTROOT)/usr/share/man/man1/ruptime.1
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
#
# Note: on MS Windows, executables, have an extension, so rules and dependencies
# for generated tools should use $(EXECUTABLE_EXT) on the end.
+
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 rwho.1 $(DSTROOT)/usr/share/man/man1/rwho.1
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
# Makefile API), which are rules that get invoked before and after the install
# target runs. Such rules should be specified with the '::' syntax rather than
# a single colon.
+
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 rwhod.8 $(DSTROOT)/usr/share/man/man8/rwhod.8
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
DEBUG_LIBS = $(LIBS)
PROF_LIBS = $(LIBS)
+HEADER_PATHS =\
+ -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/
NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc
WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc
CFILES = slattach.c
-OTHERSRCS = Makefile.preamble Makefile Makefile.dist slattach.8
+OTHERSRCS = Makefile.preamble Makefile Makefile.dist slattach.8 Makefile.postamble
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
--- /dev/null
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 slattach.8 $(DSTROOT)/usr/share/man/man8
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
char *ProgramName = "stdethers";
-extern int ether_line(char *, struct ether_addr *, char *);
-
#ifndef NTOA_FIX
#define NTOA(x) (char *)ether_ntoa(x)
#else
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
+++ /dev/null
-#
-# Generated by the NeXT Project Builder.
-#
-# NOTE: Do NOT change this file -- Project Builder maintains it.
-#
-# Put all of your customizations in files called Makefile.preamble
-# and Makefile.postamble (both optional), and Makefile will include them.
-#
-
-NAME = syslogd
-
-PROJECTVERSION = 2.8
-PROJECT_TYPE = Tool
-
-HFILES = pathnames.h ttymsg.h
-
-CFILES = ttymsg.c syslogd.c
-
-OTHERSRCS = Makefile.preamble Makefile Makefile.postamble syslogd.8\
- syslog.conf.5
-
-
-MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
-CODE_GEN_STYLE = DYNAMIC
-MAKEFILE = tool.make
-NEXTSTEP_INSTALLDIR = /usr/sbin
-WINDOWS_INSTALLDIR = /usr/sbin
-PDO_UNIX_INSTALLDIR = /usr/sbin
-LIBS =
-DEBUG_LIBS = $(LIBS)
-PROF_LIBS = $(LIBS)
-
-
-
-
-NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc
-WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc
-PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc
-NEXTSTEP_JAVA_COMPILER = /usr/bin/javac
-WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe
-PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac
-
-include $(MAKEFILEDIR)/platform.make
-
--include Makefile.preamble
-
-include $(MAKEFILEDIR)/$(MAKEFILE)
-
--include Makefile.postamble
-
--include Makefile.dependencies
+++ /dev/null
-###############################################################################
-# NeXT Makefile.postamble Template
-# Copyright 1993, NeXT Computer, Inc.
-#
-# This Makefile is used for configuring the standard app makefiles associated
-# with ProjectBuilder.
-#
-# Use this template to set attributes for a project, sub-project, bundle, or
-# palette. Each node in the project's tree of sub-projects and bundles
-# should have it's own Makefile.preamble and Makefile.postamble. Additional
-# rules (e.g., after_install) that are defined by the developer should be
-# defined in this file.
-#
-###############################################################################
-#
-# Here are the variables exported by the common "app" makefiles that can be
-# used in any customizations you make to the template below:
-#
-# PRODUCT_ROOT - Name of top-level app-wrapper (e.g., Webster.app)
-# OFILE_DIR - Directory into which .o object files are generated.
-# (Note that this name is calculated based on the target
-# architectures specified in Project Builder).
-# DERIVED_SRC_DIR - Directory used for all other derived files
-# ALL_CFLAGS - All the flags passed to the cc(1) driver for compilations
-#
-# NAME - name of application, bundle, subproject, palette, etc.
-# LANGUAGE - langage in which the project is written (default "English")
-# ENGLISH - boolean flag set iff $(LANGUAGE) = "English"
-# JAPANESE - boolean flag set iff $(LANGUAGE) = "Japanese"
-# LOCAL_RESOURCES - localized resources (e.g. nib's, images) of project
-# GLOBAL_RESOURCES - non-localized resources of project
-# PROJECTVERSION - version of ProjectBuilder that output Makefile
-# APPICON - application icon file
-# DOCICONS - dock icon files
-# ICONSECTIONS - Specifies icon sections when linking executable
-#
-# CLASSES - Class implementation files in project.
-# HFILES - Header files in project.
-# MFILES - Other Objective-C source files in project.
-# CFILES - Other C source files in project.
-# PSWFILES - .psw files in the project
-# PSWMFILES - .pswm files in the project
-# SUBPROJECTS - Subprojects of this project
-# BUNDLES - Bundle subprojects of this project
-# OTHERSRCS - Other miscellaneous sources of this project
-# OTHERLINKED - Source files not matching a standard source extention
-#
-# LIBS - Libraries to link with when making app target
-# DEBUG_LIBS - Libraries to link with when making debug target
-# PROF_LIBS - Libraries to link with when making profile target
-# OTHERLINKEDOFILES - Other relocatable files to (always) link in.
-#
-# APP_MAKEFILE_DIR - Directory in which to find generic set of Makefiles
-# MAKEFILEDIR - Directory in which to find $(MAKEFILE)
-# MAKEFILE - Top level mechanism Makefile (e.g., app.make, bundle.make)
-# INSTALLDIR - Directory app will be installed into by 'install' target
-
-
-# Change defaults assumed by the standard app makefiles here. Edit the
-# following default values as appropriate. (Note that if no Makefile.postamble
-# exists, these values will have defaults set in common.make).
-
-# Add Makefile.preamble, Makefile.postamble, and Makefile.dependencies here if
-# you would like changes to them to invalidate previous builds. The project
-# depends on $(MAKEFILES) so that changes to Makefiles will trigger a re-build.
-#MAKEFILES = Makefile
-
-# Optimization flag passed to compiler:
-#OPTIMIZATION_CFLAG = -O
-
-# Flags always passed to compiler:
-#COMMON_CFLAGS = $(PROJECT_SPECIFIC_CFLAGS) -g -Wall
-
-# Flags passed to compiler in normal 'app' compiles:
-#NORMAL_CFLAGS = $(COMMON_CFLAGS) $(OPTIMIZATION_CFLAG)
-
-# Flags passed to compiler in 'debug' compiles:
-#DEBUG_CFLAGS = $(COMMON_CFLAGS) -DDEBUG
-
-# Flags passed to compiler in 'profile' compiles
-#PROFILE_CFLAGS = $(COMMON_CFLAGS) -pg $(OPTIMIZATION_CFLAG) -DPROFILE
-
-# Flags passed to yacc
-#YFLAGS = -d
-
-# Ownership and permissions of files installed by 'install' target
-#INSTALL_AS_USER = root # User to chown app to
-#INSTALL_AS_GROUP = wheel # Group to chgrp app to
-#INSTALL_PERMISSIONS = # If set, 'install' chmod's executable to this
-
-# Options to strip for bundles, apps with bundles, and apps without bundles,
-# respectively.
-#RELOCATABLE_STRIP_OPTS = -x -u
-#DYLD_APP_STRIP_OPTS = -A -n
-#APP_STRIP_OPTS =
-#TOOL_STRIP_OPTS =
-#LIBRARY_STRIP_OPTS = -x -S # Note: -S strips debugging symbols
-# (Note: APP_STRIP_OPTS and TOOL_STRIP_OPTS default to empty, but
-# developers doing their own dynamic loading should set this to
-# $(DYLD_APP_STRIP_OPTS)).
-STRIPFLAGS =
-
-
-#########################################################################
-# Put rules to extend the behavior of the standard Makefiles here. Typical
-# user-defined rules are before_install and after_install (please don't
-# redefine things like install or app, as they are owned by the top-level
-# Makefile API), which are rules that get invoked before and after the install
-# target runs. Such rules should be specified with the '::' syntax rather than
-# a single colon.
-VPATH += :../wall.tproj
-
-# a rule with which to install the man page
-install-man-page:
- install -d $(DSTROOT)/usr/share/man/man5
- install -d $(DSTROOT)/usr/share/man/man8
- install -c -m 444 syslog.conf.5 $(DSTROOT)/usr/share/man/man5/syslog.conf.5
- install -c -m 444 syslogd.8 $(DSTROOT)/usr/share/man/man8/syslogd.8
+++ /dev/null
-###############################################################################
-# NeXT Makefile.preamble Template
-# Copyright 1993, NeXT Computer, Inc.
-#
-# This Makefile is used for configuring the standard app makefiles associated
-# with ProjectBuilder.
-#
-# Use this template to set attributes for a project, sub-project, bundle, or
-# palette. Each node in the project's tree of sub-projects and bundles
-# should have it's own Makefile.preamble and Makefile.postamble.
-#
-###############################################################################
-## Configure the flags passed to $(CC) here. These flags will also be
-## inherited by all nested sub-projects and bundles. Put your -I, -D, -U, and
-## -L flags here. To change the default flags that get passed to ${CC}
-## (e.g. change -O to -O2), see Makefile.postamble.
-
-# Flags passed to compiler (in addition to -g, -O, etc)
-OTHER_CFLAGS = -DINET6 -Dsocklen_t=int
-# Flags passed to ld (in addition to -ObjC, etc.)
-OTHER_LDFLAGS =
-
-BUNDLELDFLAGS = # use iff project is a bundle
-PALETTELDFLAGS = # use iff project is a palette
-
-## Specify which headers in this project should be published to the outside
-## world in a flat header directory given in PUBLIC_HEADER_DIR (which will be
-## prepended by DSTROOT, below. Any subset of these public headers can be
-## precompiled automatically after installation, with extra user-defined flags.
-PUBLIC_HEADER_DIR =
-PUBLIC_HEADERS =
-PUBLIC_PRECOMPILED_HEADERS =
-PUBLIC_PRECOMPILED_HEADERS_CFLAGS =
-
-## Configure what is linked in at each level here. Libraries are only used in
-## the final 'app' linking step. Final 'app' linking is only done via the
-## 'app', 'debug', and 'profile' targets when they are invoked for
-## the top-level app.
-
-# Additional libs to link apps against ('app' target)
-#OTHER_LIBS =
-# Additional libs to link apps against ('debug' target)
-OTHER_DEBUG_LIBS =
-# Additional libs to link apps against ('profile' target)
-OTHER_PROF_LIBS =
-
-# More 'app' libraries when $(JAPANESE) = "YES"
-OTHER_JAPANESE_LIBS =
-# More 'debug' libraries when $(JAPANESE) = "YES"
-OTHER_JAPANESE_DEBUG_LIBS =
-# More 'profile' libs when $(JAPANESE) = "YES"
-OTHER_JAPANESE_PROF_LIBS =
-
-# If this is a bundle, and you *know* the enclosing application will not
-# be linking with a library which you require in your bundle code, then
-# mention it here so that it gets linked into the bundle. Note that this
-# is wasteful but sometimes necessary.
-BUNDLE_LIBS =
-
-## Configure how things get built here. Additional dependencies, sourcefiles,
-## derived files, and build order should be specified here.
-
-# Other dependencies of this project
-OTHER_PRODUCT_DEPENDS =
-# Built *before* building subprojects/bundles
-OTHER_INITIAL_TARGETS =
-# Other source files maintained by .pre/postamble
-OTHER_SOURCEFILES =
-# Additional files to be removed by `make clean'
-OTHER_GARBAGE =
-# Precompiled headers to be built before any compilation occurs (e.g., draw.p)
-PRECOMPS =
-
-# Targets to be built before installation
-OTHER_INSTALL_DEPENDS =
-
-# A virtual root directory (other than /) to be prepended to the $(INSTALLDIR)
-# passed from ProjectBuilder.
-DSTROOT =
-
-# Set the following to "YES" if you want the old behavior of recursively
-# cleaning all nested subprojects during 'make clean'.
-CLEAN_ALL_SUBPROJECTS =
-
-## Add more obscure source files here to cause them to be automatically
-## processed by the appropriate tool. Note that these files should also be
-## added to "Supporting Files" in ProjectBuilder. The desired .o files that
-## result from these files should also be added to OTHER_OFILES above so they
-## will be linked in.
-
-# .msg files that should have msgwrap run on them
-MSGFILES =
-# .defs files that should have mig run on them
-DEFSFILES =
-# .mig files (no .defs files) that should have mig run on them
-MIGFILES =
-
-## Add additional Help directories here (add them to the project as "Other
-## Resources" in Project Builder) so that they will be compressed into .store
-## files and copied into the app wrapper. If the help directories themselves
-## need to also be in the app wrapper, then a cp command will need to be added
-## in an after_install target.
-OTHER_HELP_DIRS =
-
-# Don't add more rules here unless you want the first one to be the default
-# target for make! Put all your targets in Makefile.postamble.
-
-# To include a version string, project source must exist in a directory named
-# $(NAME).%d[.%d][.%d] and the following line must be uncommented.
-
-OTHER_GENERATED_OFILES = $(VERS_OFILE)
-
-#OTHER_OFILES = ttymsg.o
-
-# to allow installing man page after main install
-AFTER_INSTALL += install-man-page
-
--include ../Makefile.include
+++ /dev/null
-{
- DOCICONFILES = ();
- FILESTABLE = {
- C_FILES = ();
- H_FILES = (pathnames.h);
- OTHER_LIBS = ();
- OTHER_LINKED = (syslogd.c);
- OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, syslogd.8, syslog.conf.5);
- PRECOMPILED_HEADERS = ();
- PROJECT_HEADERS = ();
- PUBLIC_HEADERS = ();
- SUBPROJECTS = ();
- };
- GENERATEMAIN = YES;
- LANGUAGE = English;
- LOCALIZABLE_FILES = {};
- NEXTSTEP_BUILDDIR = "";
- NEXTSTEP_BUILDTOOL = /bin/make;
- NEXTSTEP_COMPILEROPTIONS = "";
- NEXTSTEP_INSTALLDIR = /usr/sbin;
- NEXTSTEP_JAVA_COMPILER = /usr/bin/javac;
- NEXTSTEP_LINKEROPTIONS = "";
- NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc;
- PDO_UNIX_BUILDDIR = "";
- PDO_UNIX_BUILDTOOL = /bin/make;
- PDO_UNIX_COMPILEROPTIONS = "";
- PDO_UNIX_INSTALLDIR = /usr/sbin;
- PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac";
- PDO_UNIX_LINKEROPTIONS = "";
- PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc";
- PROJECTNAME = syslogd;
- PROJECTTYPE = Tool;
- PROJECTVERSION = 2.8;
- WINDOWS_BUILDDIR = "";
- WINDOWS_BUILDTOOL = /bin/make;
- WINDOWS_COMPILEROPTIONS = "";
- WINDOWS_INSTALLDIR = /usr/sbin;
- WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe";
- WINDOWS_LINKEROPTIONS = "";
- WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc";
-}
+++ /dev/null
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pathnames.h 8.1 (Berkeley) 6/6/93
- */
-
-#include <paths.h>
-
-#define _PATH_KLOG "/dev/klog"
-#define _PATH_LOGCONF "/etc/syslog.conf"
-#define _PATH_LOGPID "/var/run/syslog.pid"
+++ /dev/null
-.\" Copyright (c) 1990, 1991, 1993
-.\" The Regents of the University of California. 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 the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" from: @(#)syslog.conf.5 8.1 (Berkeley) 6/9/93
-.\" $NetBSD: syslog.conf.5,v 1.4 1996/01/02 17:41:46 perry Exp $
-.\"
-.Dd June 9, 1993
-.Dt SYSLOG.CONF 5
-.Os
-.Sh NAME
-.Nm syslog.conf
-.Nd
-.Xr syslogd 8
-configuration file
-.Sh DESCRIPTION
-The
-.Nm syslog.conf
-file is the configuration file for the
-.Xr syslogd 8
-program.
-It consists of lines with two fields: the
-.Em selector
-field which specifies the types of messages and priorities to which the
-line applies, and an
-.Em action
-field which specifies the action to be taken if a message
-.Xr syslogd
-receives matches the selection criteria.
-The
-.Em selector
-field is separated from the
-.Em action
-field by one or more tab characters.
-.Pp
-The
-.Em Selectors
-function
-are encoded as a
-.Em facility ,
-a period (``.''), and a
-.Em level ,
-with no intervening white-space.
-Both the
-.Em facility
-and the
-.Em level
-are case insensitive.
-.Pp
-The
-.Em facility
-describes the part of the system generating the message, and is one of
-the following keywords: auth, authpriv, cron, daemon, kern, lpr, mail,
-mark, news, syslog, user, uucp and local0 through local7.
-These keywords (with the exception of mark) correspond to the
-similar
-.Dq Dv LOG_
-values specified to the
-.Xr openlog 3
-and
-.Xr syslog 3
-library routines.
-.Pp
-The
-.Em level
-describes the severity of the message, and is a keyword from the
-following ordered list (higher to lower): emerg, alert, crit, err,
-warning, notice, info and debug.
-These keywords correspond to the
-similar
-.Pq Dv LOG_
-values specified to the
-.Xr syslog
-library routine.
-.Pp
-See
-.Xr syslog 3
-for a further descriptions of both the
-.Em facility
-and
-.Em level
-keywords and their significance.
-.Pp
-If a received message matches the specified
-.Em facility
-and is of the specified
-.Em level
-.Em (or a higher level) ,
-the action specified in the
-.Em action
-field will be taken.
-.Pp
-Multiple
-.Em selectors
-may be specified for a single
-.Em action
-by separating them with semicolon (``;'') characters.
-It is important to note, however, that each
-.Em selector
-can modify the ones preceding it.
-.Pp
-Multiple
-.Em facilities
-may be specified for a single
-.Em level
-by separating them with comma (``,'') characters.
-.Pp
-An asterisk (``*'') can be used to specify all
-.Em facilities
-or all
-.Em levels .
-.Pp
-The special
-.Em facility
-``mark'' receives a message at priority ``info'' every 20 minutes
-(see
-.Xr syslogd 8 ) .
-This is not enabled by a
-.Em facility
-field containing an asterisk.
-.Pp
-The special
-.Em level
-``none'' disables a particular
-.Em facility .
-.Pp
-The
-.Em action
-field of each line specifies the action to be taken when the
-.Em selector
-field selects a message.
-There are four forms:
-.Bl -bullet
-.It
-A pathname (beginning with a leading slash).
-Selected messages are appended to the file.
-.It
-A hostname (preceded by an at (``@'') sign).
-Selected messages are forwarded to the
-.Xr syslogd
-program on the named host.
-.It
-A comma separated list of users.
-Selected messages are written to those users
-if they are logged in.
-.It
-An asterisk.
-Selected messages are written to all logged-in users.
-.El
-.Pp
-Blank lines and lines whose first non-blank character is a hash (``#'')
-character are ignored.
-.Sh EXAMPLES
-.Pp
-A configuration file might appear as follows:
-.Bd -literal
-# Log all kernel messages, authentication messages of
-# level notice or higher and anything of level err or
-# higher to the console.
-# Don't log private authentication messages!
-*.err;kern.*;auth.notice;authpriv.none /dev/console
-
-# Log anything (except mail) of level info or higher.
-# Don't log private authentication messages!
-*.info;mail.none;authpriv.none /var/log/messages
-
-# The authpriv file has restricted access.
-authpriv.* /var/log/secure
-
-# Log all the mail messages in one place.
-mail.* /var/log/maillog
-
-# Everybody gets emergency messages, plus log them on another
-# machine.
-*.emerg *
-*.emerg @arpa.berkeley.edu
-
-# Root and Eric get alert and higher messages.
-*.alert root,eric
-
-# Save mail and news errors of level err and higher in a
-# special file.
-uucp,news.crit /var/log/spoolerr
-.Ed
-.Sh FILES
-.Bl -tag -width /etc/syslog.conf -compact
-.It Pa /etc/syslog.conf
-The
-.Xr syslogd 8
-configuration file.
-.El
-.Sh BUGS
-The effects of multiple selectors are sometimes not intuitive.
-For example ``mail.crit,*.err'' will select ``mail'' facility messages at
-the level of ``err'' or higher, not at the level of ``crit'' or higher.
-.Sh SEE ALSO
-.Xr syslog 3 ,
-.Xr syslogd 8
-.Sh HISTORY
-The
-.Nm
-file appeared in
-.Bx 4.3 ,
-along with
-.Xr syslogd 8 .
+++ /dev/null
-.\" Copyright (c) 1983, 1986, 1991, 1993
-.\" The Regents of the University of California. 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 the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)syslogd.8 8.1 (Berkeley) 6/6/93
-.\" $FreeBSD: src/usr.sbin/syslogd/syslogd.8,v 1.49 2002/12/12 17:26:04 ru Exp $
-.\"
-.Dd November 24, 2001
-.Dt SYSLOGD 8
-.Os
-.Sh NAME
-.Nm syslogd
-.Nd log systems messages
-.Sh SYNOPSIS
-.Nm
-.Op Fl 46Acdknosuv
-.Op Fl a Ar allowed_peer
-.Op Fl b Ar bind_address
-.Op Fl f Ar config_file
-.Op Fl l Ar path
-.Op Fl m Ar mark_interval
-.Op Fl P Ar pid_file
-.Op Fl p Ar log_socket
-.Sh DESCRIPTION
-The
-.Nm
-utility reads and logs messages to the system console, log files, other
-machines and/or users as specified by its configuration file.
-.Pp
-The options are as follows:
-.Bl -tag -width indent
-.It Fl 4
-Force
-.Nm
-to use IPv4 addresses only.
-.It Fl 6
-Force
-.Nm
-to use IPv6 addresses only.
-.It Fl A
-Ordinarily,
-.Nm
-tries to send the message to only one address
-even if the host has more than one A or AAAA record.
-If this option is specified,
-.Nm
-tries to send the message to all addresses.
-.It Fl a Ar allowed_peer
-Allow
-.Ar allowed_peer
-to log to this
-.Nm
-using UDP datagrams. Multiple
-.Fl a
-options may be specified.
-.Pp
-.Ar Allowed_peer
-can be any of the following:
-.Bl -tag -width "ipaddr/masklen[:service]XX"
-.It Xo
-.Sm off
-.Ar ipaddr
-.No / Ar masklen
-.Op : Ar service
-.Sm on
-.Xc
-Accept datagrams from
-.Ar ipaddr
-(in the usual dotted quad notation) with
-.Ar masklen
-bits being taken into account when doing the address comparison.
-.Ar ipaddr
-can be also IPv6 address by enclosing the address with
-.Ql \&[
-and
-.Ql \&] .
-If specified,
-.Ar service
-is the name or number of an UDP service (see
-.Xr services 5 )
-the source packet must belong to. A
-.Ar service
-of
-.Ql \&*
-allows packets being sent from any UDP port. The default
-.Ar service
-is
-.Ql syslog .
-If
-.Ar ipaddr
-is IPv4 address, a missing
-.Ar masklen
-will be substituted by the historic class A or class B netmasks if
-.Ar ipaddr
-belongs into the address range of class A or B, respectively, or
-by 24 otherwise. If
-.Ar ipaddr
-is IPv6 address, a missing
-.Ar masklen
-will be substituted by 128.
-.It Xo
-.Sm off
-.Ar domainname Op : Ar service
-.Sm on
-.Xc
-Accept datagrams where the reverse address lookup yields
-.Ar domainname
-for the sender address. The meaning of
-.Ar service
-is as explained above.
-.It Xo
-.Sm off
-.No * Ar domainname Op : Ar service
-.Sm on
-.Xc
-Same as before, except that any source host whose name
-.Em ends
-in
-.Ar domainname
-will get permission.
-.El
-.Pp
-The
-.Fl a
-options are ignored if the
-.Fl s
-option is also specified.
-.It Fl b Ar bind_address
-Specify one specific IP address or hostname to bind to.
-If a hostname is specified,
-the IPv4 or IPv6 address which corresponds to it is used.
-.It Fl c
-Disable the compression of repeated instances of the same line
-into a single line of the form
-.Dq Li "last message repeated N times"
-when the output is a pipe to another program.
-If specified twice, disable this compression in all cases.
-.It Fl d
-Put
-.Nm
-into debugging mode. This is probably only of use to developers working on
-.Nm .
-.It Fl f
-Specify the pathname of an alternate configuration file;
-the default is
-.Pa /etc/syslog.conf .
-.It Fl k
-Disable the translation of
-messages received with facility
-.Dq kern
-to facility
-.Dq user .
-Usually the
-.Dq kern
-facility is reserved for messages read directly from
-.Pa /dev/klog .
-.It Fl m
-Select the number of minutes between
-.Dq mark
-messages; the default is 20 minutes.
-.It Fl n
-Disable dns query for every request.
-.It Fl o
-Prefix kernel messages with the full kernel boot file as determined by
-.Xr getbootfile 3 .
-Without this, the kernel message prefix is always
-.Dq Li kernel: .
-.It Fl p
-Specify the pathname of an alternate log socket to be used instead;
-the default is
-.Pa /var/run/log .
-.It Fl P
-Specify an alternative file in which to store the process ID.
-The default is
-.Pa /var/run/syslog.pid .
-.It Fl l
-Specify a location where
-.Nm
-should place an additional log socket.
-Up to 19 additional logging sockets can be specified.
-The primary use for this is to place additional log sockets in
-.Pa /var/run/log
-of various chroot filespaces.
-.It Fl s
-Operate in secure mode. Do not log messages from remote machines. If
-specified twice, no network socket will be opened at all, which also
-disables logging to remote machines.
-.It Fl u
-Unique priority logging. Only log messages at the specified priority.
-Without this option, messages at the stated priority or higher are logged.
-This option changes the default comparison from
-.Dq =>
-to
-.Dq = .
-.It Fl v
-Verbose logging. If specified once, the numeric facility and priority are
-logged with each locally-written message. If specified more than once,
-the names of the facility and priority are logged with each locally-written
-message.
-.El
-.Pp
-The
-.Nm
-utility reads its configuration file when it starts up and whenever it
-receives a hangup signal.
-For information on the format of the configuration file,
-see
-.Xr syslog.conf 5 .
-.Pp
-The
-.Nm
-utility reads messages from the
-.Ux
-domain socket
-.Pa /var/run/log ,
-from an Internet domain socket specified in
-.Pa /etc/services ,
-and from the special device
-.Pa /dev/klog
-(to read kernel messages).
-.Pp
-The
-.Nm
-utility creates its process ID file,
-by default
-.Pa /var/run/syslog.pid ,
-and stores its process
-ID there.
-This can be used to kill or reconfigure
-.Nm .
-.Pp
-The message sent to
-.Nm
-should consist of a single line.
-The message can contain a priority code, which should be a preceding
-decimal number in angle braces, for example,
-.Sq Aq 5 .
-This priority code should map into the priorities defined in the
-include file
-.Aq Pa sys/syslog.h .
-.Pp
-For security reasons,
-.Nm
-will not append to log files that do not exist;
-therefore, they must be created manually before running
-.Nm .
-.Sh FILES
-.Bl -tag -width /var/run/syslog.pid -compact
-.It Pa /etc/syslog.conf
-configuration file
-.It Pa /var/run/syslog.pid
-default process ID file
-.It Pa /var/run/log
-name of the
-.Ux
-domain datagram log socket
-.It Pa /dev/klog
-kernel log device
-.El
-.Sh SEE ALSO
-.Xr logger 1 ,
-.Xr syslog 3 ,
-.Xr services 5 ,
-.Xr syslog.conf 5
-.Sh HISTORY
-The
-.Nm
-utility appeared in
-.Bx 4.3 .
-.Pp
-The
-.Fl a ,
-.Fl s ,
-.Fl u ,
-and
-.Fl v
-options are
-.Fx 2.2
-extensions.
-.Sh BUGS
-The ability to log messages received in UDP packets is equivalent to
-an unauthenticated remote disk-filling service, and should probably be
-disabled by default. Some sort of
-.No inter- Ns Nm syslogd
-authentication mechanism ought to be worked out. To prevent the worst
-abuse, use of the
-.Fl a
-option is therefore highly recommended.
-.Pp
-The
-.Fl a
-matching algorithm doesn't pretend to be very efficient; use of numeric
-IP addresses is faster than domain name comparison. Since the allowed
-peer list is being walked linearly, peer groups where frequent messages
-are being anticipated from should be put early into the
-.Fl a
-list.
-.Pp
-The log socket was moved from
-.Pa /dev
-to ease the use of a read-only root file system.
-This may confuse
-some old binaries so that a symbolic link might be used for a
-transitional period.
+++ /dev/null
-/*
- * Copyright (c) 1983, 1988, 1993, 1994
- * The Regents of the University of California. 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1983, 1988, 1993, 1994\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
-#endif
-#endif /* not lint */
-
-/*
- * syslogd -- log system messages
- *
- * This program implements a system log. It takes a series of lines.
- * Each line may have a priority, signified as "<n>" as
- * the first characters of the line. If this is
- * not present, a default priority is used.
- *
- * To kill syslogd, send a signal 15 (terminate). A signal 1 (hup) will
- * cause it to reread its configuration file.
- *
- * Defined Constants:
- *
- * MAXLINE -- the maximimum line length that can be handled.
- * DEFUPRI -- the default priority for user messages
- * DEFSPRI -- the default priority for kernel messages
- *
- * Author: Eric Allman
- * extensive changes by Ralph Campbell
- * more extensive changes by Eric Allman (again)
- * Extension to log by program name as well as facility and priority
- * by Peter da Silva.
- * -u and -v by Harlan Stenn.
- * Priority comparison code by Harlan Stenn.
- */
-
-#define MAXLINE 1024 /* maximum line length */
-#define MAXSVLINE 120 /* maximum saved line length */
-#define DEFUPRI (LOG_USER|LOG_NOTICE)
-#define DEFSPRI (LOG_KERN|LOG_CRIT)
-#define TIMERINTVL 30 /* interval for checking flush, mark */
-#define TTYMSGTIME 1 /* timed out passed to ttymsg */
-
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/queue.h>
-#include <sys/uio.h>
-#include <sys/un.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <sys/syslimits.h>
-#include <grp.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <paths.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sysexits.h>
-#include <unistd.h>
-#include <utmp.h>
-#include <string.h>
-#include <notify.h>
-
-#ifndef NETWORK_CHANGE_NOTIFICATION
-#define NETWORK_CHANGE_NOTIFICATION "com.apple.system.config.network_change"
-#endif
-
-#include "pathnames.h"
-#include "ttymsg.h"
-
-#define SYSLOG_NAMES
-#include <sys/syslog.h>
-
-#ifdef NI_WITHSCOPEID
-static const int withscopeid = NI_WITHSCOPEID;
-#else
-static const int withscopeid;
-#endif
-
-const char *ConfFile = _PATH_LOGCONF;
-const char *PidFile = _PATH_LOGPID;
-const char ctty[] = _PATH_CONSOLE;
-
-#define dprintf if (Debug) printf
-
-#define MAXUNAMES 20 /* maximum number of user names */
-
-#define MAXFUNIX 20
-
-int nfunix = 1;
-const char *funixn[MAXFUNIX] = { _PATH_LOG };
-int funix[MAXFUNIX];
-
-/*
- * Flags to logmsg().
- */
-
-#define IGN_CONS 0x001 /* don't print on console */
-#define SYNC_FILE 0x002 /* do fsync on file after printing */
-#define ADDDATE 0x004 /* add a date to the message */
-#define MARK 0x008 /* this message is a mark */
-#define ISKERNEL 0x010 /* kernel generated message */
-
-/*
- * This structure represents the files that will have log
- * copies printed.
- */
-
-struct filed {
- struct filed *f_next; /* next in linked list */
- short f_type; /* entry type, see below */
- short f_file; /* file descriptor */
- time_t f_time; /* time this was last written */
- char *f_host; /* host from which to recd. */
- u_char f_pmask[LOG_NFACILITIES+1]; /* priority mask */
- u_char f_pcmp[LOG_NFACILITIES+1]; /* compare priority */
-#define PRI_LT 0x1
-#define PRI_EQ 0x2
-#define PRI_GT 0x4
- char *f_program; /* program this applies to */
- union {
- char f_uname[MAXUNAMES][UT_NAMESIZE+1];
- struct {
- char f_hname[MAXHOSTNAMELEN];
- struct addrinfo *f_addr;
-
- } f_forw; /* forwarding address */
- char f_fname[MAXPATHLEN];
- struct {
- char f_pname[MAXPATHLEN];
- pid_t f_pid;
- } f_pipe;
- } f_un;
- char f_prevline[MAXSVLINE]; /* last message logged */
- char f_lasttime[16]; /* time of last occurrence */
- char f_prevhost[MAXHOSTNAMELEN]; /* host from which recd. */
- int f_prevpri; /* pri of f_prevline */
- int f_prevlen; /* length of f_prevline */
- int f_prevcount; /* repetition cnt of prevline */
- u_int f_repeatcount; /* number of "repeated" msgs */
-};
-
-/*
- * Queue of about-to-be dead processes we should watch out for.
- */
-
-TAILQ_HEAD(stailhead, deadq_entry) deadq_head;
-struct stailhead *deadq_headp;
-
-struct deadq_entry {
- pid_t dq_pid;
- int dq_timeout;
- TAILQ_ENTRY(deadq_entry) dq_entries;
-};
-
-/*
- * The timeout to apply to processes waiting on the dead queue. Unit
- * of measure is `mark intervals', i.e. 20 minutes by default.
- * Processes on the dead queue will be terminated after that time.
- */
-
-#define DQ_TIMO_INIT 2
-
-typedef struct deadq_entry *dq_t;
-
-
-/*
- * Struct to hold records of network addresses that are allowed to log
- * to us.
- */
-struct allowedpeer {
- int isnumeric;
- u_short port;
- union {
- struct {
- struct sockaddr_storage addr;
- struct sockaddr_storage mask;
- } numeric;
- char *name;
- } u;
-#define a_addr u.numeric.addr
-#define a_mask u.numeric.mask
-#define a_name u.name
-};
-
-
-/*
- * Intervals at which we flush out "message repeated" messages,
- * in seconds after previous message is logged. After each flush,
- * we move to the next interval until we reach the largest.
- */
-int repeatinterval[] = { 30, 120, 600 }; /* # of secs before flush */
-#define MAXREPEAT ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1)
-#define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount])
-#define BACKOFF(f) { if (++(f)->f_repeatcount > MAXREPEAT) \
- (f)->f_repeatcount = MAXREPEAT; \
- }
-
-/* values for f_type */
-#define F_UNUSED 0 /* unused entry */
-#define F_FILE 1 /* regular file */
-#define F_TTY 2 /* terminal */
-#define F_CONSOLE 3 /* console terminal */
-#define F_FORW 4 /* remote machine */
-#define F_USERS 5 /* list of users */
-#define F_WALL 6 /* everyone logged on */
-#define F_PIPE 7 /* pipe to program */
-#define F_CHECKTTY 8 /* think it's a tty, so check */
-
-const char *TypeNames[9] = {
- "UNUSED", "FILE", "TTY", "CONSOLE",
- "FORW", "USERS", "WALL", "PIPE",
- "CHECKTTY"
-};
-
-static struct filed *Files = NULL; /* Log files that we write to */
-static struct filed consfile; /* Console */
-
-static int Debug = 0; /* debug flag */
-static int resolve = 1; /* resolve hostname */
-static char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */
-static char *LocalDomain = NULL; /* our local domain name */
-static int *finet = NULL; /* Internet datagram socket */
-static int fklog = -1; /* /dev/klog */
-static int Initialized = 0; /* set when we have initialized ourselves */
-static int MarkInterval = 20 * 60; /* interval between marks in seconds */
-static int MarkSeq = 0; /* mark sequence number */
-#ifdef __APPLE__
-static int RcvSockBufSize = 49152; /* Our default receive socket buffer size 3301629*/
-#endif
-static int SecureMode = 0; /* when true, receive only unix domain socks */
-#ifdef INET6
-static int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */
-#else
-static int family = PF_INET; /* protocol family (IPv4 only) */
-#endif
-static int send_to_all = 0; /* send message to all IPv4/IPv6 addresses */
-static int use_bootfile = 0; /* log entire bootfile for every kern msg */
-static int no_compress = 0; /* don't compress messages (1=pipes, 2=all) */
-
-static char bootfile[MAXLINE+1]; /* booted kernel file */
-
-struct allowedpeer *AllowedPeers = NULL; /* List of allowed peers */
-static int NumAllowed = 0; /* Number of entries in AllowedPeers */
-
-static int UniquePriority = 0; /* Only log specified priority? */
-static int LogFacPri = 0; /* Put facility and priority in log message: */
- /* 0=no, 1=numeric, 2=names */
-static int KeepKernFac = 0; /* Keep remotely logged kernel facility */
-static int create_files = 0;
-
-volatile sig_atomic_t MarkSet = 0, WantDie = 0;
-
-static int allowaddr(char *);
-static void cfline(const char *, struct filed *,
- const char *, const char *);
-static const char *cvthname(struct sockaddr *);
-static void deadq_enter(pid_t, const char *);
-static int deadq_remove(pid_t);
-static int decode(const char *, CODE *);
-static void die(int);
-static void dodie(int);
-static void domark(int);
-static void fprintlog(struct filed *, int, const char *);
-static int *socksetup(int, const char *);
-static void init(int);
-static void logerror(const char *);
-static void logmsg(int, const char *, const char *, int);
-static void log_deadchild(pid_t, int, const char *);
-static void markit(void);
-static int skip_message(const char *, const char *);
-static void printline(const char *, char *);
-static void printsys(char *);
-static int p_open(const char *, pid_t *);
-static void readklog(void);
-static void reapchild(int);
-static void usage(void);
-static int validate(struct sockaddr *, const char *);
-static void unmapped(struct sockaddr *);
-static void wallmsg(struct filed *, struct iovec *);
-static int waitdaemon(int, int, int);
-static void timedout(int);
-
-int
-main(int argc, char *argv[])
-{
- int ch, i, fdsrmax = 0, l;
- struct sockaddr_un sunx, fromunix;
- struct sockaddr_storage frominet;
- fd_set *fdsr = NULL;
- FILE *fp;
- char line[MAXLINE + 1];
- const char *bindhostname, *hname;
- struct timeval tv, *tvp;
- struct sigaction sact;
- sigset_t mask;
- pid_t ppid = 1;
- socklen_t len;
- int nctoken = -1;
-
- bindhostname = NULL;
- while ((ch = getopt(argc, argv, "46ACa:b:cdf:kl:m:nop:P:suv")) != -1)
- switch (ch) {
- case '4':
- family = PF_INET;
- break;
-#ifdef INET6
- case '6':
- family = PF_INET6;
- break;
-#endif
- case 'A':
- send_to_all++;
- break;
- case 'C':
- create_files++;
- break;
- case 'a': /* allow specific network addresses only */
- if (allowaddr(optarg) == -1)
- usage();
- break;
- case 'b':
- bindhostname = optarg;
- break;
- case 'c':
- no_compress++;
- break;
- case 'd': /* debug */
- Debug++;
- break;
- case 'f': /* configuration file */
- ConfFile = optarg;
- break;
- case 'k': /* keep remote kern fac */
- KeepKernFac = 1;
- break;
- case 'l':
- if (nfunix < MAXFUNIX)
- funixn[nfunix++] = optarg;
- else
- warnx("out of descriptors, ignoring %s",
- optarg);
- break;
- case 'm': /* mark interval */
- MarkInterval = atoi(optarg) * 60;
- break;
- case 'n':
- resolve = 0;
- break;
- case 'o':
- use_bootfile = 1;
- break;
- case 'p': /* path */
- funixn[0] = optarg;
- break;
- case 'P': /* path for alt. PID */
- PidFile = optarg;
- break;
- case 's': /* no network mode */
- SecureMode++;
- break;
- case 'u': /* only log specified priority */
- UniquePriority++;
- break;
- case 'v': /* log facility and priority */
- LogFacPri++;
- break;
- case '?':
- default:
- usage();
- }
- if ((argc -= optind) != 0)
- usage();
-
- if (!Debug) {
- ppid = waitdaemon(0, 0, 30);
- if (ppid < 0)
- err(1, "could not become daemon");
- } else {
- setlinebuf(stdout);
- }
-
- if (NumAllowed)
- endservent();
-
- consfile.f_type = F_CONSOLE;
- (void)strlcpy(consfile.f_un.f_fname, ctty + sizeof _PATH_DEV - 1,
- sizeof(consfile.f_un.f_fname));
-#ifdef __APPLE__
- /* We lack getbootfile() 3187949 and 3187947 */
- (void)strlcpy(bootfile, "/mach_kernel", sizeof("/mach_kernel"));
-#else
- (void)strlcpy(bootfile, getbootfile(), sizeof(bootfile));
-#endif
- (void)signal(SIGTERM, dodie);
- (void)signal(SIGINT, Debug ? dodie : SIG_IGN);
- (void)signal(SIGQUIT, Debug ? dodie : SIG_IGN);
- /*
- * We don't want the SIGCHLD and SIGHUP handlers to interfere
- * with each other; they are likely candidates for being called
- * simultaneously (SIGHUP closes pipe descriptor, process dies,
- * SIGCHLD happens).
- */
- sigemptyset(&mask);
- sigaddset(&mask, SIGHUP);
- sact.sa_handler = reapchild;
- sact.sa_mask = mask;
- sact.sa_flags = SA_RESTART;
- (void)sigaction(SIGCHLD, &sact, NULL);
- (void)signal(SIGALRM, domark);
- (void)signal(SIGPIPE, SIG_IGN); /* We'll catch EPIPE instead. */
- notify_register_signal(NETWORK_CHANGE_NOTIFICATION, SIGHUP, &nctoken);
- (void)alarm(TIMERINTVL);
-
- TAILQ_INIT(&deadq_head);
-
-#ifndef SUN_LEN
-#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
-#endif
- for (i = 0; i < nfunix; i++) {
- (void)unlink(funixn[i]);
- memset(&sunx, 0, sizeof(sunx));
- sunx.sun_family = AF_UNIX;
- (void)strlcpy(sunx.sun_path, funixn[i], sizeof(sunx.sun_path));
- funix[i] = socket(AF_UNIX, SOCK_DGRAM, 0);
- if (funix[i] < 0 ||
- bind(funix[i], (struct sockaddr *)&sunx,
- SUN_LEN(&sunx)) < 0 ||
- chmod(funixn[i], 0666) < 0) {
- (void)snprintf(line, sizeof line,
- "cannot create %s", funixn[i]);
- logerror(line);
- dprintf("cannot create %s (%d)\n", funixn[i], errno);
- if (i == 0)
- die(0);
- }
-#ifdef __APPLE__
- if (setsockopt(funix[i], SOL_SOCKET, SO_RCVBUF, &RcvSockBufSize, sizeof(int)) < 0)
- logerror("setsockopt funix");
-#endif
- }
- if (SecureMode <= 1)
- finet = socksetup(family, bindhostname);
-
- if (finet) {
- if (SecureMode) {
- for (i = 0; i < *finet; i++) {
- if (shutdown(finet[i+1], SHUT_RD) < 0) {
- logerror("shutdown");
- if (!Debug)
- die(0);
- }
- }
- } else {
- dprintf("listening on inet and/or inet6 socket\n");
- }
- dprintf("sending on inet and/or inet6 socket\n");
- }
-
- if ((fklog = open(_PATH_KLOG, O_RDONLY, 0)) >= 0)
- if (fcntl(fklog, F_SETFL, O_NONBLOCK) < 0)
- fklog = -1;
- if (fklog < 0)
- dprintf("can't open %s (%d)\n", _PATH_KLOG, errno);
-
- /* tuck my process id away */
- fp = fopen(PidFile, "w");
- if (fp != NULL) {
- fprintf(fp, "%d\n", getpid());
- (void)fclose(fp);
- }
-
- dprintf("off & running....\n");
-
- init(0);
- /* prevent SIGHUP and SIGCHLD handlers from running in parallel */
- sigemptyset(&mask);
- sigaddset(&mask, SIGCHLD);
- sact.sa_handler = init;
- sact.sa_mask = mask;
- sact.sa_flags = SA_RESTART;
- (void)sigaction(SIGHUP, &sact, NULL);
-
- tvp = &tv;
- tv.tv_sec = tv.tv_usec = 0;
-
- if (fklog != -1 && fklog > fdsrmax)
- fdsrmax = fklog;
- if (finet && !SecureMode) {
- for (i = 0; i < *finet; i++) {
- if (finet[i+1] != -1 && finet[i+1] > fdsrmax)
- fdsrmax = finet[i+1];
- }
- }
- for (i = 0; i < nfunix; i++) {
- if (funix[i] != -1 && funix[i] > fdsrmax)
- fdsrmax = funix[i];
- }
-
- fdsr = (fd_set *)calloc(howmany(fdsrmax+1, NFDBITS),
- sizeof(fd_mask));
- if (fdsr == NULL)
- errx(1, "calloc fd_set");
-
- for (;;) {
- if (MarkSet)
- markit();
- if (WantDie)
- die(WantDie);
-
- bzero(fdsr, howmany(fdsrmax+1, NFDBITS) *
- sizeof(fd_mask));
-
- if (fklog != -1)
- FD_SET(fklog, fdsr);
- if (finet && !SecureMode) {
- for (i = 0; i < *finet; i++) {
- if (finet[i+1] != -1)
- FD_SET(finet[i+1], fdsr);
- }
- }
- for (i = 0; i < nfunix; i++) {
- if (funix[i] != -1)
- FD_SET(funix[i], fdsr);
- }
-
- i = select(fdsrmax+1, fdsr, NULL, NULL, tvp);
- switch (i) {
- case 0:
- if (tvp) {
- tvp = NULL;
- if (ppid != 1)
- kill(ppid, SIGALRM);
- }
- continue;
- case -1:
- if (errno != EINTR)
- logerror("select");
- continue;
- }
- if (fklog != -1 && FD_ISSET(fklog, fdsr))
- readklog();
- if (finet && !SecureMode) {
- for (i = 0; i < *finet; i++) {
- if (FD_ISSET(finet[i+1], fdsr)) {
- len = sizeof(frominet);
- l = recvfrom(finet[i+1], line, MAXLINE,
- 0, (struct sockaddr *)&frominet,
- &len);
- if (l > 0) {
- line[l] = '\0';
- hname = cvthname((struct sockaddr *)&frominet);
- unmapped((struct sockaddr *)&frominet);
- if (validate((struct sockaddr *)&frominet, hname))
- printline(hname, line);
- } else if (l < 0 && errno != EINTR)
- logerror("recvfrom inet");
- }
- }
- }
- for (i = 0; i < nfunix; i++) {
- if (funix[i] != -1 && FD_ISSET(funix[i], fdsr)) {
- len = sizeof(fromunix);
- l = recvfrom(funix[i], line, MAXLINE, 0,
- (struct sockaddr *)&fromunix, &len);
- if (l > 0) {
- line[l] = '\0';
- printline(LocalHostName, line);
- } else if (l < 0 && errno != EINTR)
- logerror("recvfrom unix");
- }
- }
- }
- if (fdsr)
- free(fdsr);
-}
-
-static void
-unmapped(struct sockaddr *sa)
-{
- struct sockaddr_in6 *sin6;
- struct sockaddr_in sin4;
-
- if (sa->sa_family != AF_INET6)
- return;
- if (sa->sa_len != sizeof(struct sockaddr_in6) ||
- sizeof(sin4) > sa->sa_len)
- return;
- sin6 = (struct sockaddr_in6 *)sa;
- if (!IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
- return;
-
- memset(&sin4, 0, sizeof(sin4));
- sin4.sin_family = AF_INET;
- sin4.sin_len = sizeof(struct sockaddr_in);
- memcpy(&sin4.sin_addr, &sin6->sin6_addr.s6_addr[12],
- sizeof(sin4.sin_addr));
- sin4.sin_port = sin6->sin6_port;
-
- memcpy(sa, &sin4, sin4.sin_len);
-}
-
-static void
-usage(void)
-{
-
- fprintf(stderr, "%s\n%s\n%s\n%s\n",
- "usage: syslogd [-46Acdknosuv] [-a allowed_peer]",
- " [-b bind address] [-f config_file]",
- " [-l log_socket] [-m mark_interval]",
- " [-P pid_file] [-p log_socket]");
- exit(1);
-}
-
-/*
- * Take a raw input line, decode the message, and print the message
- * on the appropriate log files.
- */
-static void
-printline(const char *hname, char *msg)
-{
- int c, pri;
- char *p, *q, line[MAXLINE + 1];
-
- /* test for special codes */
- pri = DEFUPRI;
- p = msg;
- if (*p == '<') {
- pri = 0;
- while (isdigit(*++p))
- pri = 10 * pri + (*p - '0');
- if (*p == '>')
- ++p;
- }
- if (pri &~ (LOG_FACMASK|LOG_PRIMASK))
- pri = DEFUPRI;
-
- /* don't allow users to log kernel messages */
- if (LOG_FAC(pri) == LOG_KERN && !KeepKernFac)
- pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri));
-
- q = line;
-
- while ((c = (unsigned char)*p++) != '\0' &&
- q < &line[sizeof(line) - 4]) {
-#ifdef __APPLE__
- /* Gross installer hack to be removed 3314128 */
- if (LOG_FACMASK&pri != LOG_INSTALL) {
- if ((c & 0x80) && c < 0xA0) {
- c &= 0x7F;
- *q++ = 'M';
- *q++ = '-';
- }
- }
-#endif
- if (isascii(c) && iscntrl(c)) {
- if (c == '\n') {
- *q++ = ' ';
- } else if (c == '\t') {
- *q++ = '\t';
- } else {
- *q++ = '^';
- *q++ = c ^ 0100;
- }
- } else {
- *q++ = c;
- }
- }
- *q = '\0';
-
- logmsg(pri, line, hname, 0);
-}
-
-/*
- * Read /dev/klog while data are available, split into lines.
- */
-static void
-readklog(void)
-{
- char *p, *q, line[MAXLINE + 1];
- int len, i;
-
- len = 0;
- for (;;) {
- i = read(fklog, line + len, MAXLINE - 1 - len);
- if (i > 0) {
- line[i + len] = '\0';
- } else {
- if (i < 0 && errno != EINTR && errno != EAGAIN) {
- logerror("klog");
- fklog = -1;
- }
- break;
- }
-
- for (p = line; (q = strchr(p, '\n')) != NULL; p = q + 1) {
- *q = '\0';
- printsys(p);
- }
- len = strlen(p);
- if (len >= MAXLINE - 1) {
- printsys(p);
- len = 0;
- }
- if (len > 0)
- memmove(line, p, len + 1);
- }
- if (len > 0)
- printsys(line);
-}
-
-/*
- * Take a raw input line from /dev/klog, format similar to syslog().
- */
-static void
-printsys(char *p)
-{
- int pri, flags;
-
- flags = ISKERNEL | SYNC_FILE | ADDDATE; /* fsync after write */
- pri = DEFSPRI;
- if (*p == '<') {
- pri = 0;
- while (isdigit(*++p))
- pri = 10 * pri + (*p - '0');
- if (*p == '>')
- ++p;
-#ifndef __APPLE__
- if ((pri & LOG_FACMASK) == LOG_CONSOLE)
- flags |= IGN_CONS;
-#endif
- } else {
- /* kernel printf's come out on console */
- flags |= IGN_CONS;
- }
- if (pri &~ (LOG_FACMASK|LOG_PRIMASK))
- pri = DEFSPRI;
- logmsg(pri, p, LocalHostName, flags);
-}
-
-static time_t now;
-
-/*
- * Match a program or host name against a specification.
- * Return a non-0 value if the message must be ignored
- * based on the specification.
- */
-static int
-skip_message(const char *name, const char *spec) {
- const char *s;
- char prev, next;
- int exclude = 0;
- /* Behaviour on explicit match */
-
- if (spec == NULL)
- return 0;
- switch (*spec) {
- case '-':
- exclude = 1;
- /*FALLTHROUGH*/
- case '+':
- spec++;
- break;
- default:
- break;
- }
- s = strstr (spec, name);
-
- if (s != NULL) {
- prev = (s == spec ? ',' : *(s - 1));
- next = *(s + strlen (name));
-
- if (prev == ',' && (next == '\0' || next == ','))
- /* Explicit match: skip iff the spec is an
- exclusive one. */
- return exclude;
- }
-
- /* No explicit match for this name: skip the message iff
- the spec is an inclusive one. */
- return !exclude;
-}
-
-/*
- * Log a message to the appropriate log files, users, etc. based on
- * the priority.
- */
-static void
-logmsg(int pri, const char *msg, const char *from, int flags)
-{
- struct filed *f;
- int i, fac, msglen, omask, prilev;
- const char *timestamp;
- char prog[NAME_MAX+1];
- char buf[MAXLINE+1];
-
- dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n",
- pri, flags, from, msg);
-
- omask = sigblock(sigmask(SIGHUP)|sigmask(SIGALRM));
-
- /*
- * Check to see if msg looks non-standard.
- */
- msglen = strlen(msg);
- if (msglen < 16 || msg[3] != ' ' || msg[6] != ' ' ||
- msg[9] != ':' || msg[12] != ':' || msg[15] != ' ')
- flags |= ADDDATE;
-
- (void)time(&now);
- if (flags & ADDDATE) {
- timestamp = ctime(&now) + 4;
- } else {
- timestamp = msg;
- msg += 16;
- msglen -= 16;
- }
-
- /* skip leading blanks */
- while (isspace(*msg)) {
- msg++;
- msglen--;
- }
-
- /* extract facility and priority level */
- if (flags & MARK)
- fac = LOG_NFACILITIES;
- else
- fac = LOG_FAC(pri);
- prilev = LOG_PRI(pri);
-
- /* extract program name */
- for (i = 0; i < NAME_MAX; i++) {
- if (!isprint(msg[i]) || msg[i] == ':' || msg[i] == '[')
- break;
- prog[i] = msg[i];
- }
- prog[i] = 0;
-
- /* add kernel prefix for kernel messages */
- if (flags & ISKERNEL) {
- snprintf(buf, sizeof(buf), "%s: %s",
- use_bootfile ? bootfile : "kernel", msg);
- msg = buf;
- msglen = strlen(buf);
- }
-
- /* log the message to the particular outputs */
- if (!Initialized) {
- f = &consfile;
- f->f_file = open(ctty, O_WRONLY, 0);
-
- if (f->f_file >= 0) {
- fprintlog(f, flags, msg);
- (void)close(f->f_file);
- }
- (void)sigsetmask(omask);
- return;
- }
- for (f = Files; f; f = f->f_next) {
- /* skip messages that are incorrect priority */
- if (!(((f->f_pcmp[fac] & PRI_EQ) && (f->f_pmask[fac] == prilev))
- ||((f->f_pcmp[fac] & PRI_LT) && (f->f_pmask[fac] < prilev))
- ||((f->f_pcmp[fac] & PRI_GT) && (f->f_pmask[fac] > prilev))
- )
- || f->f_pmask[fac] == INTERNAL_NOPRI)
- continue;
-
- /* skip messages with the incorrect hostname */
- if (skip_message(from, f->f_host))
- continue;
-
- /* skip messages with the incorrect program name */
- if (skip_message(prog, f->f_program))
- continue;
-
- /* skip message to console if it has already been printed */
- if (f->f_type == F_CONSOLE && (flags & IGN_CONS))
- continue;
-
- /* don't output marks to recently written files */
- if ((flags & MARK) && (now - f->f_time) < MarkInterval / 2)
- continue;
-
- /*
- * suppress duplicate lines to this file
- */
- if (no_compress - (f->f_type != F_PIPE) < 1 &&
- (flags & MARK) == 0 && msglen == f->f_prevlen &&
- !strcmp(msg, f->f_prevline) &&
- !strcasecmp(from, f->f_prevhost)) {
- (void)strlcpy(f->f_lasttime, timestamp, 16);
- f->f_prevcount++;
- dprintf("msg repeated %d times, %ld sec of %d\n",
- f->f_prevcount, (long)(now - f->f_time),
- repeatinterval[f->f_repeatcount]);
- /*
- * If domark would have logged this by now,
- * flush it now (so we don't hold isolated messages),
- * but back off so we'll flush less often
- * in the future.
- */
- if (now > REPEATTIME(f)) {
- fprintlog(f, flags, (char *)NULL);
- BACKOFF(f);
- }
- } else {
- /* new line, save it */
- if (f->f_prevcount)
- fprintlog(f, 0, (char *)NULL);
- f->f_repeatcount = 0;
- f->f_prevpri = pri;
- (void)strlcpy(f->f_lasttime, timestamp, 16);
- (void)strlcpy(f->f_prevhost, from,
- sizeof(f->f_prevhost));
- if (msglen < MAXSVLINE) {
- f->f_prevlen = msglen;
- (void)strlcpy(f->f_prevline, msg, sizeof(f->f_prevline));
- fprintlog(f, flags, (char *)NULL);
- } else {
- f->f_prevline[0] = 0;
- f->f_prevlen = 0;
- fprintlog(f, flags, msg);
- }
- }
- }
- (void)sigsetmask(omask);
-}
-
-static void
-fprintlog(struct filed *f, int flags, const char *msg)
-{
- struct iovec iov[7];
- struct iovec *v;
- struct addrinfo *r;
- int i, l, lsent = 0;
- char line[MAXLINE + 1], repbuf[80], greetings[200], *wmsg = NULL;
- const char *msgret;
-
- v = iov;
- if (f->f_type == F_WALL) {
- v->iov_base = greetings;
- v->iov_len = snprintf(greetings, sizeof greetings,
- "\r\n\7Message from syslogd@%s at %.24s ...\r\n",
- f->f_prevhost, ctime(&now));
- if (v->iov_len > 0)
- v++;
- v->iov_base = "";
- v->iov_len = 0;
- v++;
- } else {
- v->iov_base = f->f_lasttime;
- v->iov_len = 15;
- v++;
- v->iov_base = " ";
- v->iov_len = 1;
- v++;
- }
-
- if (LogFacPri) {
- static char fp_buf[30]; /* Hollow laugh */
- int fac = f->f_prevpri & LOG_FACMASK;
- int pri = LOG_PRI(f->f_prevpri);
- const char *f_s = NULL;
- char f_n[5]; /* Hollow laugh */
- const char *p_s = NULL;
- char p_n[5]; /* Hollow laugh */
-
- if (LogFacPri > 1) {
- CODE *c;
-
- for (c = facilitynames; c->c_name; c++) {
- if (c->c_val == fac) {
- f_s = c->c_name;
- break;
- }
- }
- for (c = prioritynames; c->c_name; c++) {
- if (c->c_val == pri) {
- p_s = c->c_name;
- break;
- }
- }
- }
- if (!f_s) {
- snprintf(f_n, sizeof f_n, "%d", LOG_FAC(fac));
- f_s = f_n;
- }
- if (!p_s) {
- snprintf(p_n, sizeof p_n, "%d", pri);
- p_s = p_n;
- }
- snprintf(fp_buf, sizeof fp_buf, "<%s.%s> ", f_s, p_s);
- v->iov_base = fp_buf;
- v->iov_len = strlen(fp_buf);
- } else {
- v->iov_base="";
- v->iov_len = 0;
- }
- v++;
-
- v->iov_base = f->f_prevhost;
- v->iov_len = strlen(v->iov_base);
- v++;
- v->iov_base = " ";
- v->iov_len = 1;
- v++;
-
- if (msg) {
- wmsg = strdup(msg); /* XXX iov_base needs a `const' sibling. */
- if (wmsg == NULL) {
- logerror("strdup");
- exit(1);
- }
- v->iov_base = wmsg;
- v->iov_len = strlen(msg);
- } else if (f->f_prevcount > 1) {
- v->iov_base = repbuf;
- v->iov_len = snprintf(repbuf, sizeof repbuf,
- "last message repeated %d times", f->f_prevcount);
- } else {
- v->iov_base = f->f_prevline;
- v->iov_len = f->f_prevlen;
- }
- v++;
-
- if (f->f_file == -1) {
- int oflags = O_WRONLY|O_APPEND;
- struct group *gr;
- struct stat sb;
- int mode = 0640;
- int exists = 0;
-
- if( stat(f->f_un.f_fname, &sb) == 0 ) {
- mode = 0;
- exists++;
- }
- if (create_files && !exists)
- oflags |= O_CREAT;
- if ((f->f_file = open(f->f_un.f_fname, oflags, mode)) < 0) {
- f->f_type = F_UNUSED;
- /* We can no longer log this error, since calling
- * logerror() could bring us back here again.
- * Instead, call dprintf(), which will aid in
- * debugging, but not cause the looping.
- */
- dprintf("Error openning %s", f->f_un.f_fname);
- if (msg) free(wmsg);
- return;
- }
- /* Only chown the file if we created it. If it already
- * existed, leave whatever was there.
- */
- if( !exists ) {
- gr = getgrnam("admin");
- if( gr )
- fchown(f->f_file, 0, gr->gr_gid);
- }
- if (f->f_type == F_CHECKTTY) {
- if (isatty(f->f_file)) {
- if (strcmp(f->f_un.f_fname, ctty) == 0)
- f->f_type = F_CONSOLE;
- else
- f->f_type = F_TTY;
- }
- }
- }
-
- dprintf("Logging to %s", TypeNames[f->f_type]);
- f->f_time = now;
-
- switch (f->f_type) {
- case F_UNUSED:
- dprintf("\n");
- break;
-
- case F_FORW:
- dprintf(" %s\n", f->f_un.f_forw.f_hname);
- /* check for local vs remote messages */
- if (strcasecmp(f->f_prevhost, LocalHostName))
- l = snprintf(line, sizeof line - 1,
- "<%d>%.15s Forwarded from %s: %s",
- f->f_prevpri, iov[0].iov_base, f->f_prevhost,
- iov[5].iov_base);
- else
- l = snprintf(line, sizeof line - 1, "<%d>%.15s %s",
- f->f_prevpri, iov[0].iov_base, iov[5].iov_base);
- if (l < 0)
- l = 0;
- else if (l > MAXLINE)
- l = MAXLINE;
-
- if (finet) {
- for (r = f->f_un.f_forw.f_addr; r; r = r->ai_next) {
- for (i = 0; i < *finet; i++) {
-#if 0
- /*
- * should we check AF first, or just
- * trial and error? FWD
- */
- if (r->ai_family ==
- address_family_of(finet[i+1]))
-#endif
- lsent = sendto(finet[i+1], line, l, 0,
- r->ai_addr, r->ai_addrlen);
- if (lsent == l)
- break;
- }
- if (lsent == l && !send_to_all)
- break;
- }
- dprintf("lsent/l: %d/%d\n", lsent, l);
- if (lsent != l) {
- int e = errno;
- logerror("sendto");
- errno = e;
- switch (errno) {
- case EHOSTUNREACH:
- case EHOSTDOWN:
- break;
- /* case EBADF: */
- /* case EACCES: */
- /* case ENOTSOCK: */
- /* case EFAULT: */
- /* case EMSGSIZE: */
- /* case EAGAIN: */
- /* case ENOBUFS: */
- /* case ECONNREFUSED: */
- default:
- dprintf("removing entry\n");
- (void)close(f->f_file);
- f->f_type = F_UNUSED;
- break;
- }
- }
- }
- break;
-
- case F_FILE:
- dprintf(" %s\n", f->f_un.f_fname);
- v->iov_base = "\n";
- v->iov_len = 1;
- if (writev(f->f_file, iov, 7) < 0) {
- int e = errno;
- (void)close(f->f_file);
- f->f_type = F_UNUSED;
- errno = e;
- logerror(f->f_un.f_fname);
- } else if (flags & SYNC_FILE)
- (void)fsync(f->f_file);
- break;
-
- case F_PIPE:
- dprintf(" %s\n", f->f_un.f_pipe.f_pname);
- v->iov_base = "\n";
- v->iov_len = 1;
- if (f->f_un.f_pipe.f_pid == 0) {
- if ((f->f_file = p_open(f->f_un.f_pipe.f_pname,
- &f->f_un.f_pipe.f_pid)) < 0) {
- f->f_type = F_UNUSED;
- logerror(f->f_un.f_pipe.f_pname);
- break;
- }
- }
- if (writev(f->f_file, iov, 7) < 0) {
- int e = errno;
- (void)close(f->f_file);
- if (f->f_un.f_pipe.f_pid > 0)
- deadq_enter(f->f_un.f_pipe.f_pid,
- f->f_un.f_pipe.f_pname);
- f->f_un.f_pipe.f_pid = 0;
- errno = e;
- logerror(f->f_un.f_pipe.f_pname);
- }
- break;
-
- case F_CONSOLE:
- if (flags & IGN_CONS) {
- dprintf(" (ignored)\n");
- break;
- }
- /* FALLTHROUGH */
-
- case F_TTY:
- dprintf(" %s%s\n", _PATH_DEV, f->f_un.f_fname);
- v->iov_base = "\r\n";
- v->iov_len = 2;
-
- errno = 0; /* ttymsg() only sometimes returns an errno */
- if ((msgret = ttymsg(iov, 7, f->f_un.f_fname, 10))) {
- f->f_type = F_UNUSED;
- logerror(msgret);
- }
- break;
-
- case F_USERS:
- case F_WALL:
- dprintf("\n");
- v->iov_base = "\r\n";
- v->iov_len = 2;
- wallmsg(f, iov);
- break;
- }
- f->f_prevcount = 0;
- if (msg)
- free(wmsg);
-}
-
-/*
- * WALLMSG -- Write a message to the world at large
- *
- * Write the specified message to either the entire
- * world, or a list of approved users.
- */
-static void
-wallmsg(struct filed *f, struct iovec *iov)
-{
- static int reenter; /* avoid calling ourselves */
- FILE *uf;
- struct utmp ut;
- int i;
- const char *p;
- char line[sizeof(ut.ut_line) + 1];
-
- if (reenter++)
- return;
- if ((uf = fopen(_PATH_UTMP, "r")) == NULL) {
- logerror(_PATH_UTMP);
- reenter = 0;
- return;
- }
- /* NOSTRICT */
- while (fread((char *)&ut, sizeof(ut), 1, uf) == 1) {
- if (ut.ut_name[0] == '\0')
- continue;
- (void)strlcpy(line, ut.ut_line, sizeof(line));
- if (f->f_type == F_WALL) {
- if ((p = ttymsg(iov, 7, line, TTYMSGTIME)) != NULL) {
- errno = 0; /* already in msg */
- logerror(p);
- }
- continue;
- }
- /* should we send the message to this user? */
- for (i = 0; i < MAXUNAMES; i++) {
- if (!f->f_un.f_uname[i][0])
- break;
- if (!strncmp(f->f_un.f_uname[i], ut.ut_name,
- UT_NAMESIZE)) {
- if ((p = ttymsg(iov, 7, line, TTYMSGTIME))
- != NULL) {
- errno = 0; /* already in msg */
- logerror(p);
- }
- break;
- }
- }
- }
- (void)fclose(uf);
- reenter = 0;
-}
-
-static void
-reapchild(int signo )
-{
- int status;
- pid_t pid;
- struct filed *f;
-
- while ((pid = wait3(&status, WNOHANG, (struct rusage *)NULL)) > 0) {
- if (!Initialized)
- /* Don't tell while we are initting. */
- continue;
-
- /* First, look if it's a process from the dead queue. */
- if (deadq_remove(pid))
- goto oncemore;
-
- /* Now, look in list of active processes. */
- for (f = Files; f; f = f->f_next)
- if (f->f_type == F_PIPE &&
- f->f_un.f_pipe.f_pid == pid) {
- (void)close(f->f_file);
- f->f_un.f_pipe.f_pid = 0;
- log_deadchild(pid, status,
- f->f_un.f_pipe.f_pname);
- break;
- }
- oncemore:
- continue;
- }
-}
-
-/*
- * Return a printable representation of a host address.
- */
-static const char *
-cvthname(struct sockaddr *f)
-{
- int error;
- sigset_t omask, nmask;
- char *p;
- static char hname[NI_MAXHOST], ip[NI_MAXHOST];
-
- error = getnameinfo((struct sockaddr *)f,
- ((struct sockaddr *)f)->sa_len,
- ip, sizeof ip, NULL, 0,
- NI_NUMERICHOST | withscopeid);
- dprintf("cvthname(%s)\n", ip);
-
- if (error) {
- dprintf("Malformed from address %s\n", gai_strerror(error));
- return ("???");
- }
- if (!resolve)
- return (ip);
-
- sigemptyset(&nmask);
- sigaddset(&nmask, SIGHUP);
- sigprocmask(SIG_BLOCK, &nmask, &omask);
- error = getnameinfo((struct sockaddr *)f,
- ((struct sockaddr *)f)->sa_len,
- hname, sizeof hname, NULL, 0,
- NI_NAMEREQD | withscopeid);
- sigprocmask(SIG_SETMASK, &omask, NULL);
- if (error) {
- dprintf("Host name for your address (%s) unknown\n", ip);
- return (ip);
- }
- /* XXX Not quite correct, but close enough for government work. */
- if ((p = strchr(hname, '.')) && strcasecmp(p + 1, LocalDomain) == 0)
- *p = '\0';
- return (hname);
-}
-
-static void
-dodie(int signo)
-{
-
- WantDie = signo;
-}
-
-static void
-domark(int signo )
-{
-
- MarkSet = 1;
-}
-
-/*
- * Print syslogd errors some place.
- */
-static void
-logerror(const char *type)
-{
- char buf[512];
-
- if (errno)
- (void)snprintf(buf,
- sizeof buf, "syslogd: %s: %s", type, strerror(errno));
- else
- (void)snprintf(buf, sizeof buf, "syslogd: %s", type);
- errno = 0;
- dprintf("%s\n", buf);
- logmsg(LOG_SYSLOG|LOG_ERR, buf, LocalHostName, ADDDATE);
-}
-
-static void
-die(int signo)
-{
- struct filed *f;
- int was_initialized;
- char buf[100];
- int i;
-
- was_initialized = Initialized;
- Initialized = 0; /* Don't log SIGCHLDs. */
- for (f = Files; f != NULL; f = f->f_next) {
- /* flush any pending output */
- if (f->f_prevcount)
- fprintlog(f, 0, (char *)NULL);
- if (f->f_type == F_PIPE)
- (void)close(f->f_file);
- }
- Initialized = was_initialized;
- if (signo) {
- dprintf("syslogd: exiting on signal %d\n", signo);
- (void)snprintf(buf, sizeof(buf), "exiting on signal %d", signo);
- errno = 0;
- logerror(buf);
- }
- for (i = 0; i < nfunix; i++)
- if (funixn[i] && funix[i] != -1)
- (void)unlink(funixn[i]);
- exit(1);
-}
-
-/*
- * INIT -- Initialize syslogd from configuration table
- */
-static void
-init(int signo)
-{
- int i;
- FILE *cf;
- struct filed *f, *next, **nextp;
- char *p;
- char cline[LINE_MAX];
- char prog[NAME_MAX+1];
- char host[MAXHOSTNAMELEN];
- char oldLocalHostName[MAXHOSTNAMELEN];
- char hostMsg[2*MAXHOSTNAMELEN+40];
- char bootfileMsg[LINE_MAX];
-
- dprintf("init\n");
-
- /*
- * Load hostname (may have changed).
- */
- if (signo != 0)
- (void)strlcpy(oldLocalHostName, LocalHostName,
- sizeof(oldLocalHostName));
- if (gethostname(LocalHostName, sizeof(LocalHostName)))
- err(EX_OSERR, "gethostname() failed");
- if ((p = strchr(LocalHostName, '.')) != NULL) {
- *p++ = '\0';
- LocalDomain = p;
- } else {
- LocalDomain = "";
- }
-
- /*
- * Close all open log files.
- */
- Initialized = 0;
- for (f = Files; f != NULL; f = next) {
- /* flush any pending output */
- if (f->f_prevcount)
- fprintlog(f, 0, (char *)NULL);
-
- switch (f->f_type) {
- case F_FILE:
- case F_FORW:
- case F_CONSOLE:
- case F_TTY:
- (void)close(f->f_file);
- break;
- case F_PIPE:
- (void)close(f->f_file);
- if (f->f_un.f_pipe.f_pid > 0)
- deadq_enter(f->f_un.f_pipe.f_pid,
- f->f_un.f_pipe.f_pname);
- f->f_un.f_pipe.f_pid = 0;
- break;
- }
- next = f->f_next;
- if (f->f_program) free(f->f_program);
- if (f->f_host) free(f->f_host);
- free((char *)f);
- }
- Files = NULL;
- nextp = &Files;
-
- /* open the configuration file */
- if ((cf = fopen(ConfFile, "r")) == NULL) {
- dprintf("cannot open %s\n", ConfFile);
- *nextp = (struct filed *)calloc(1, sizeof(*f));
- if (*nextp == NULL) {
- logerror("calloc");
- exit(1);
- }
- cfline("*.ERR\t/dev/console", *nextp, "*", "*");
- (*nextp)->f_next = (struct filed *)calloc(1, sizeof(*f));
- if ((*nextp)->f_next == NULL) {
- logerror("calloc");
- exit(1);
- }
- cfline("*.PANIC\t*", (*nextp)->f_next, "*", "*");
- Initialized = 1;
- return;
- }
-
- /*
- * Foreach line in the conf table, open that file.
- */
- f = NULL;
- (void)strlcpy(host, "*", sizeof(host));
- (void)strlcpy(prog, "*", sizeof(prog));
- while (fgets(cline, sizeof(cline), cf) != NULL) {
- /*
- * check for end-of-section, comments, strip off trailing
- * spaces and newline character. #!prog is treated specially:
- * following lines apply only to that program.
- */
- for (p = cline; isspace(*p); ++p)
- continue;
- if (*p == 0)
- continue;
- if (*p == '#') {
- p++;
- if (*p != '!' && *p != '+' && *p != '-')
- continue;
- }
- if (*p == '+' || *p == '-') {
- host[0] = *p++;
- while (isspace(*p))
- p++;
- if ((!*p) || (*p == '*')) {
- (void)strlcpy(host, "*", sizeof(host));
- continue;
- }
- if (*p == '@')
- p = LocalHostName;
- for (i = 1; i < MAXHOSTNAMELEN - 1; i++) {
- if (!isalnum(*p) && *p != '.' && *p != '-'
- && *p != ',')
- break;
- host[i] = *p++;
- }
- host[i] = '\0';
- continue;
- }
- if (*p == '!') {
- p++;
- while (isspace(*p)) p++;
- if ((!*p) || (*p == '*')) {
- (void)strlcpy(prog, "*", sizeof(prog));
- continue;
- }
- for (i = 0; i < NAME_MAX; i++) {
- if (!isprint(p[i]))
- break;
- prog[i] = p[i];
- }
- prog[i] = 0;
- continue;
- }
- for (p = strchr(cline, '\0'); isspace(*--p);)
- continue;
- *++p = '\0';
- f = (struct filed *)calloc(1, sizeof(*f));
- if (f == NULL) {
- logerror("calloc");
- exit(1);
- }
- *nextp = f;
- nextp = &f->f_next;
- cfline(cline, f, prog, host);
- }
-
- /* close the configuration file */
- (void)fclose(cf);
-
- Initialized = 1;
-
- if (Debug) {
- for (f = Files; f; f = f->f_next) {
- for (i = 0; i <= LOG_NFACILITIES; i++)
- if (f->f_pmask[i] == INTERNAL_NOPRI)
- printf("X ");
- else
- printf("%d ", f->f_pmask[i]);
- printf("%s: ", TypeNames[f->f_type]);
- switch (f->f_type) {
- case F_FILE:
- printf("%s", f->f_un.f_fname);
- break;
-
- case F_CONSOLE:
- case F_TTY:
- printf("%s%s", _PATH_DEV, f->f_un.f_fname);
- break;
-
- case F_FORW:
- printf("%s", f->f_un.f_forw.f_hname);
- break;
-
- case F_PIPE:
- printf("%s", f->f_un.f_pipe.f_pname);
- break;
-
- case F_USERS:
- for (i = 0; i < MAXUNAMES && *f->f_un.f_uname[i]; i++)
- printf("%s, ", f->f_un.f_uname[i]);
- break;
- }
- if (f->f_program)
- printf(" (%s)", f->f_program);
- printf("\n");
- }
- }
-
- logmsg(LOG_SYSLOG|LOG_INFO, "syslogd: restart", LocalHostName, ADDDATE);
- dprintf("syslogd: restarted\n");
- /*
- * Log a change in hostname, but only on a restart.
- */
- if (signo != 0 && strcmp(oldLocalHostName, LocalHostName) != 0) {
- (void)snprintf(hostMsg, sizeof(hostMsg),
- "syslogd: hostname changed, \"%s\" to \"%s\"",
- oldLocalHostName, LocalHostName);
- logmsg(LOG_SYSLOG|LOG_INFO, hostMsg, LocalHostName, ADDDATE);
- dprintf("%s\n", hostMsg);
- }
- /*
- * Log the kernel boot file if we aren't going to use it as
- * the prefix, and if this is *not* a restart.
- */
- if (signo == 0 && !use_bootfile) {
- (void)snprintf(bootfileMsg, sizeof(bootfileMsg),
- "syslogd: kernel boot file is %s", bootfile);
- logmsg(LOG_KERN|LOG_INFO, bootfileMsg, LocalHostName, ADDDATE);
- dprintf("%s\n", bootfileMsg);
- }
-}
-
-/*
- * Crack a configuration file line
- */
-static void
-cfline(const char *line, struct filed *f, const char *prog, const char *host)
-{
- struct addrinfo hints, *res;
- int error, i, pri;
- const char *p, *q;
- char *bp, *port;
- char buf[MAXLINE], ebuf[100];
-
- dprintf("cfline(\"%s\", f, \"%s\", \"%s\")\n", line, prog, host);
-
- errno = 0; /* keep strerror() stuff out of logerror messages */
-
- /* clear out file entry */
- memset(f, 0, sizeof(*f));
- for (i = 0; i <= LOG_NFACILITIES; i++)
- f->f_pmask[i] = INTERNAL_NOPRI;
-
- /* save hostname if any */
- if (host && *host == '*')
- host = NULL;
- if (host) {
- int hl, dl;
-
- f->f_host = strdup(host);
- if (f->f_host == NULL) {
- logerror("strdup");
- exit(1);
- }
- hl = strlen(f->f_host);
- if (f->f_host[hl-1] == '.')
- f->f_host[--hl] = '\0';
- dl = strlen(LocalDomain) + 1;
- if (hl > dl && f->f_host[hl-dl] == '.' &&
- strcasecmp(f->f_host + hl - dl + 1, LocalDomain) == 0)
- f->f_host[hl-dl] = '\0';
- }
-
- /* save program name if any */
- if (prog && *prog == '*')
- prog = NULL;
- if (prog) {
- f->f_program = strdup(prog);
- if (f->f_program == NULL) {
- logerror("strdup");
- exit(1);
- }
- }
-
- /* scan through the list of selectors */
- for (p = line; *p && *p != '\t' && *p != ' ';) {
- int pri_done;
- int pri_cmp;
- int pri_invert;
-
- /* find the end of this facility name list */
- for (q = p; *q && *q != '\t' && *q != ' ' && *q++ != '.'; )
- continue;
-
- /* get the priority comparison */
- pri_cmp = 0;
- pri_done = 0;
- pri_invert = 0;
- if (*q == '!') {
- pri_invert = 1;
- q++;
- }
- while (!pri_done) {
- switch (*q) {
- case '<':
- pri_cmp |= PRI_LT;
- q++;
- break;
- case '=':
- pri_cmp |= PRI_EQ;
- q++;
- break;
- case '>':
- pri_cmp |= PRI_GT;
- q++;
- break;
- default:
- pri_done++;
- break;
- }
- }
-
- /* collect priority name */
- for (bp = buf; *q && !strchr("\t,; ", *q); )
- *bp++ = *q++;
- *bp = '\0';
-
- /* skip cruft */
- while (strchr(",;", *q))
- q++;
-
- /* decode priority name */
- if (*buf == '*') {
- pri = LOG_PRIMASK + 1;
- pri_cmp = PRI_LT | PRI_EQ | PRI_GT;
- } else {
- pri = decode(buf, prioritynames);
- if (pri < 0) {
- (void)snprintf(ebuf, sizeof ebuf,
- "unknown priority name \"%s\"", buf);
- logerror(ebuf);
- return;
- }
- }
- if (!pri_cmp)
- pri_cmp = (UniquePriority)
- ? (PRI_EQ)
- : (PRI_EQ | PRI_GT)
- ;
- if (pri_invert)
- pri_cmp ^= PRI_LT | PRI_EQ | PRI_GT;
-
- /* scan facilities */
- while (*p && !strchr("\t.; ", *p)) {
- for (bp = buf; *p && !strchr("\t,;. ", *p); )
- *bp++ = *p++;
- *bp = '\0';
-
- if (*buf == '*') {
- for (i = 0; i < LOG_NFACILITIES; i++) {
- f->f_pmask[i] = pri;
- f->f_pcmp[i] = pri_cmp;
- }
- } else {
- i = decode(buf, facilitynames);
- if (i < 0) {
- (void)snprintf(ebuf, sizeof ebuf,
- "unknown facility name \"%s\"",
- buf);
- logerror(ebuf);
- return;
- }
- f->f_pmask[i >> 3] = pri;
- f->f_pcmp[i >> 3] = pri_cmp;
- }
- while (*p == ',' || *p == ' ')
- p++;
- }
-
- p = q;
- }
-
- /* skip to action part */
- while (*p == '\t' || *p == ' ')
- p++;
-
- switch (*p) {
- case '@':
- port = (char *)p;
- p = strsep(&port, ":");
- (void)strlcpy(f->f_un.f_forw.f_hname, ++p,
- sizeof(f->f_un.f_forw.f_hname));
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = family;
- hints.ai_socktype = SOCK_DGRAM;
- error = getaddrinfo(f->f_un.f_forw.f_hname, port ? port : "syslog", &hints,
- &res);
- if (error) {
- logerror(gai_strerror(error));
- break;
- }
- f->f_un.f_forw.f_addr = res;
- f->f_type = F_FORW;
- break;
-
- case '/':
- /* Delay opening files until we're ready to log to them */
- f->f_file = -1;
- if (strncmp(p, _PATH_DEV, sizeof(_PATH_DEV)-1) == 0)
- f->f_type = F_CHECKTTY;
- else
- f->f_type = F_FILE;
- (void)strlcpy(f->f_un.f_fname, p, sizeof(f->f_un.f_fname));
- break;
-
- case '|':
- f->f_un.f_pipe.f_pid = 0;
- (void)strlcpy(f->f_un.f_fname, p + 1, sizeof(f->f_un.f_fname));
- f->f_type = F_PIPE;
- break;
-
- case '*':
- f->f_type = F_WALL;
- break;
-
- default:
- for (i = 0; i < MAXUNAMES && *p; i++) {
- for (q = p; *q && *q != ','; )
- q++;
- (void)strncpy(f->f_un.f_uname[i], p, UT_NAMESIZE);
- if ((q - p) > UT_NAMESIZE)
- f->f_un.f_uname[i][UT_NAMESIZE] = '\0';
- else
- f->f_un.f_uname[i][q - p] = '\0';
- while (*q == ',' || *q == ' ')
- q++;
- p = q;
- }
- f->f_type = F_USERS;
- break;
- }
-}
-
-
-/*
- * Decode a symbolic name to a numeric value
- */
-static int
-decode(const char *name, CODE *codetab)
-{
- CODE *c;
- char *p, buf[40];
-
- if (isdigit(*name))
- return (atoi(name));
-
- for (p = buf; *name && p < &buf[sizeof(buf) - 1]; p++, name++) {
- if (isupper(*name))
- *p = tolower(*name);
- else
- *p = *name;
- }
- *p = '\0';
- for (c = codetab; c->c_name; c++)
- if (!strcmp(buf, c->c_name))
- return (c->c_val);
-
- return (-1);
-}
-
-static void
-markit(void)
-{
- struct filed *f;
- dq_t q, next;
-
- now = time((time_t *)NULL);
- MarkSeq += TIMERINTVL;
- if (MarkInterval && (MarkSeq >= MarkInterval)) {
- logmsg(LOG_INFO, "-- MARK --",
- LocalHostName, ADDDATE|MARK);
- MarkSeq = 0;
- }
-
- for (f = Files; f; f = f->f_next) {
- if (f->f_prevcount && now >= REPEATTIME(f)) {
- dprintf("flush %s: repeated %d times, %d sec.\n",
- TypeNames[f->f_type], f->f_prevcount,
- repeatinterval[f->f_repeatcount]);
- fprintlog(f, 0, (char *)NULL);
- BACKOFF(f);
- }
- }
-
- /* Walk the dead queue, and see if we should signal somebody. */
- for (q = TAILQ_FIRST(&deadq_head); q != NULL; q = next) {
- next = TAILQ_NEXT(q, dq_entries);
-
- switch (q->dq_timeout) {
- case 0:
- /* Already signalled once, try harder now. */
- if (kill(q->dq_pid, SIGKILL) != 0)
- (void)deadq_remove(q->dq_pid);
- break;
-
- case 1:
- /*
- * Timed out on dead queue, send terminate
- * signal. Note that we leave the removal
- * from the dead queue to reapchild(), which
- * will also log the event (unless the process
- * didn't even really exist, in case we simply
- * drop it from the dead queue).
- */
- if (kill(q->dq_pid, SIGTERM) != 0)
- (void)deadq_remove(q->dq_pid);
- /* FALLTHROUGH */
-
- default:
- q->dq_timeout--;
- }
- }
- MarkSet = 0;
- (void)alarm(TIMERINTVL);
-}
-
-/*
- * fork off and become a daemon, but wait for the child to come online
- * before returing to the parent, or we get disk thrashing at boot etc.
- * Set a timer so we don't hang forever if it wedges.
- */
-static int
-waitdaemon(int nochdir, int noclose, int maxwait)
-{
- int fd;
- int status;
- pid_t pid, childpid;
-
- switch (childpid = fork()) {
- case -1:
- return (-1);
- case 0:
- break;
- default:
- signal(SIGALRM, timedout);
- alarm(maxwait);
- while ((pid = wait3(&status, 0, NULL)) != -1) {
- if (WIFEXITED(status))
- errx(1, "child pid %d exited with return code %d",
- pid, WEXITSTATUS(status));
- if (WIFSIGNALED(status))
- errx(1, "child pid %d exited on signal %d%s",
- pid, WTERMSIG(status),
- WCOREDUMP(status) ? " (core dumped)" :
- "");
- if (pid == childpid) /* it's gone... */
- break;
- }
- exit(0);
- }
-
- if (setsid() == -1)
- return (-1);
-
- if (!nochdir)
- (void)chdir("/");
-
- if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
- (void)dup2(fd, STDIN_FILENO);
- (void)dup2(fd, STDOUT_FILENO);
- (void)dup2(fd, STDERR_FILENO);
- if (fd > 2)
- (void)close (fd);
- }
- return (getppid());
-}
-
-/*
- * We get a SIGALRM from the child when it's running and finished doing it's
- * fsync()'s or O_SYNC writes for all the boot messages.
- *
- * We also get a signal from the kernel if the timer expires, so check to
- * see what happened.
- */
-static void
-timedout(int sig )
-{
- int left;
- left = alarm(0);
- signal(SIGALRM, SIG_DFL);
- if (left == 0)
- errx(1, "timed out waiting for child");
- else
- _exit(0);
-}
-
-/*
- * Add `s' to the list of allowable peer addresses to accept messages
- * from.
- *
- * `s' is a string in the form:
- *
- * [*]domainname[:{servicename|portnumber|*}]
- *
- * or
- *
- * netaddr/maskbits[:{servicename|portnumber|*}]
- *
- * Returns -1 on error, 0 if the argument was valid.
- */
-static int
-allowaddr(char *s)
-{
- char *cp1, *cp2;
- struct allowedpeer ap;
- struct servent *se;
- int masklen = -1, i;
- struct addrinfo hints, *res;
- struct in_addr *addrp, *maskp;
- u_int32_t *addr6p, *mask6p;
- char ip[NI_MAXHOST];
-
-#ifdef INET6
- if (*s != '[' || (cp1 = strchr(s + 1, ']')) == NULL)
-#endif
- cp1 = s;
- if ((cp1 = strrchr(cp1, ':'))) {
- /* service/port provided */
- *cp1++ = '\0';
- if (strlen(cp1) == 1 && *cp1 == '*')
- /* any port allowed */
- ap.port = 0;
- else if ((se = getservbyname(cp1, "udp"))) {
- ap.port = ntohs(se->s_port);
- } else {
- ap.port = strtol(cp1, &cp2, 0);
- if (*cp2 != '\0')
- return (-1); /* port not numeric */
- }
- } else {
- if ((se = getservbyname("syslog", "udp")))
- ap.port = ntohs(se->s_port);
- else
- /* sanity, should not happen */
- ap.port = 514;
- }
-
- if ((cp1 = strchr(s, '/')) != NULL &&
- strspn(cp1 + 1, "0123456789") == strlen(cp1 + 1)) {
- *cp1 = '\0';
- if ((masklen = atoi(cp1 + 1)) < 0)
- return (-1);
- }
-#ifdef INET6
- if (*s == '[') {
- cp2 = s + strlen(s) - 1;
- if (*cp2 == ']') {
- ++s;
- *cp2 = '\0';
- } else {
- cp2 = NULL;
- }
- } else {
- cp2 = NULL;
- }
-#endif
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_DGRAM;
- hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
- if (getaddrinfo(s, NULL, &hints, &res) == 0) {
- ap.isnumeric = 1;
- memcpy(&ap.a_addr, res->ai_addr, res->ai_addrlen);
- memset(&ap.a_mask, 0, sizeof(ap.a_mask));
- ap.a_mask.ss_family = res->ai_family;
- if (res->ai_family == AF_INET) {
- ap.a_mask.ss_len = sizeof(struct sockaddr_in);
- maskp = &((struct sockaddr_in *)&ap.a_mask)->sin_addr;
- addrp = &((struct sockaddr_in *)&ap.a_addr)->sin_addr;
- if (masklen < 0) {
- /* use default netmask */
- if (IN_CLASSA(ntohl(addrp->s_addr)))
- maskp->s_addr = htonl(IN_CLASSA_NET);
- else if (IN_CLASSB(ntohl(addrp->s_addr)))
- maskp->s_addr = htonl(IN_CLASSB_NET);
- else
- maskp->s_addr = htonl(IN_CLASSC_NET);
- } else if (masklen <= 32) {
- /* convert masklen to netmask */
- if (masklen == 0)
- maskp->s_addr = 0;
- else
- maskp->s_addr = htonl(~((1 << (32 - masklen)) - 1));
- } else {
- freeaddrinfo(res);
- return (-1);
- }
- /* Lose any host bits in the network number. */
- addrp->s_addr &= maskp->s_addr;
- }
-#ifdef INET6
- else if (res->ai_family == AF_INET6 && masklen <= 128) {
- ap.a_mask.ss_len = sizeof(struct sockaddr_in6);
- if (masklen < 0)
- masklen = 128;
- mask6p = (u_int32_t *)&((struct sockaddr_in6 *)&ap.a_mask)->sin6_addr;
- /* convert masklen to netmask */
- while (masklen > 0) {
- if (masklen < 32) {
- *mask6p = htonl(~(0xffffffff >> masklen));
- break;
- }
- *mask6p++ = 0xffffffff;
- masklen -= 32;
- }
- /* Lose any host bits in the network number. */
- mask6p = (u_int32_t *)&((struct sockaddr_in6 *)&ap.a_mask)->sin6_addr;
- addr6p = (u_int32_t *)&((struct sockaddr_in6 *)&ap.a_addr)->sin6_addr;
- for (i = 0; i < 4; i++)
- addr6p[i] &= mask6p[i];
- }
-#endif
- else {
- freeaddrinfo(res);
- return (-1);
- }
- freeaddrinfo(res);
- } else {
- /* arg `s' is domain name */
- ap.isnumeric = 0;
- ap.a_name = s;
- if (cp1)
- *cp1 = '/';
-#ifdef INET6
- if (cp2) {
- *cp2 = ']';
- --s;
- }
-#endif
- }
-
- if (Debug) {
- printf("allowaddr: rule %d: ", NumAllowed);
- if (ap.isnumeric) {
- printf("numeric, ");
- getnameinfo((struct sockaddr *)&ap.a_addr,
- ((struct sockaddr *)&ap.a_addr)->sa_len,
- ip, sizeof ip, NULL, 0,
- NI_NUMERICHOST | withscopeid);
- printf("addr = %s, ", ip);
- getnameinfo((struct sockaddr *)&ap.a_mask,
- ((struct sockaddr *)&ap.a_mask)->sa_len,
- ip, sizeof ip, NULL, 0,
- NI_NUMERICHOST | withscopeid);
- printf("mask = %s; ", ip);
- } else {
- printf("domainname = %s; ", ap.a_name);
- }
- printf("port = %d\n", ap.port);
- }
-
- if ((AllowedPeers = realloc(AllowedPeers,
- ++NumAllowed * sizeof(struct allowedpeer)))
- == NULL) {
- logerror("realloc");
- exit(1);
- }
- memcpy(&AllowedPeers[NumAllowed - 1], &ap, sizeof(struct allowedpeer));
- return (0);
-}
-
-/*
- * Validate that the remote peer has permission to log to us.
- */
-static int
-validate(struct sockaddr *sa, const char *hname)
-{
- int i, j, reject;
- size_t l1, l2;
- char *cp, name[NI_MAXHOST], ip[NI_MAXHOST], port[NI_MAXSERV];
- struct allowedpeer *ap;
- struct sockaddr_in *sin4, *a4p = NULL, *m4p = NULL;
- struct sockaddr_in6 *sin6, *a6p = NULL, *m6p = NULL;
- struct addrinfo hints, *res;
- u_short sport;
-
- if (NumAllowed == 0)
- /* traditional behaviour, allow everything */
- return (1);
-
- (void)strlcpy(name, hname, sizeof(name));
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_DGRAM;
- hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
- if (getaddrinfo(name, NULL, &hints, &res) == 0)
- freeaddrinfo(res);
- else if (strchr(name, '.') == NULL) {
- strlcat(name, ".", sizeof name);
- strlcat(name, LocalDomain, sizeof name);
- }
- if (getnameinfo(sa, sa->sa_len, ip, sizeof ip, port, sizeof port,
- NI_NUMERICHOST | withscopeid | NI_NUMERICSERV) != 0)
- return (0); /* for safety, should not occur */
- dprintf("validate: dgram from IP %s, port %s, name %s;\n",
- ip, port, name);
- sport = atoi(port);
-
- /* now, walk down the list */
- for (i = 0, ap = AllowedPeers; i < NumAllowed; i++, ap++) {
- if (ap->port != 0 && ap->port != sport) {
- dprintf("rejected in rule %d due to port mismatch.\n", i);
- continue;
- }
-
- if (ap->isnumeric) {
- if (ap->a_addr.ss_family != sa->sa_family) {
- dprintf("rejected in rule %d due to address family mismatch.\n", i);
- continue;
- }
- if (ap->a_addr.ss_family == AF_INET) {
- sin4 = (struct sockaddr_in *)sa;
- a4p = (struct sockaddr_in *)&ap->a_addr;
- m4p = (struct sockaddr_in *)&ap->a_mask;
- if ((sin4->sin_addr.s_addr & m4p->sin_addr.s_addr)
- != a4p->sin_addr.s_addr) {
- dprintf("rejected in rule %d due to IP mismatch.\n", i);
- continue;
- }
- }
-#ifdef INET6
- else if (ap->a_addr.ss_family == AF_INET6) {
- sin6 = (struct sockaddr_in6 *)sa;
- a6p = (struct sockaddr_in6 *)&ap->a_addr;
- m6p = (struct sockaddr_in6 *)&ap->a_mask;
-#ifdef NI_WITHSCOPEID
- if (a6p->sin6_scope_id != 0 &&
- sin6->sin6_scope_id != a6p->sin6_scope_id) {
- dprintf("rejected in rule %d due to scope mismatch.\n", i);
- continue;
- }
-#endif
- reject = 0;
- for (j = 0; j < 16; j += 4) {
- if ((*(u_int32_t *)&sin6->sin6_addr.s6_addr[j] & *(u_int32_t *)&m6p->sin6_addr.s6_addr[j])
- != *(u_int32_t *)&a6p->sin6_addr.s6_addr[j]) {
- ++reject;
- break;
- }
- }
- if (reject) {
- dprintf("rejected in rule %d due to IP mismatch.\n", i);
- continue;
- }
- }
-#endif
- else
- continue;
- } else {
- cp = ap->a_name;
- l1 = strlen(name);
- if (*cp == '*') {
- /* allow wildmatch */
- cp++;
- l2 = strlen(cp);
- if (l2 > l1 || memcmp(cp, &name[l1 - l2], l2) != 0) {
- dprintf("rejected in rule %d due to name mismatch.\n", i);
- continue;
- }
- } else {
- /* exact match */
- l2 = strlen(cp);
- if (l2 != l1 || memcmp(cp, name, l1) != 0) {
- dprintf("rejected in rule %d due to name mismatch.\n", i);
- continue;
- }
- }
- }
- dprintf("accepted in rule %d.\n", i);
- return (1); /* hooray! */
- }
- return (0);
-}
-
-/*
- * Fairly similar to popen(3), but returns an open descriptor, as
- * opposed to a FILE *.
- */
-static int
-p_open(const char *prog, pid_t *pid)
-{
- int pfd[2], nulldesc, i;
- sigset_t omask, mask;
- char *argv[4]; /* sh -c cmd NULL */
- char errmsg[200];
-
- if (pipe(pfd) == -1)
- return (-1);
- if ((nulldesc = open(_PATH_DEVNULL, O_RDWR)) == -1)
- /* we are royally screwed anyway */
- return (-1);
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGALRM);
- sigaddset(&mask, SIGHUP);
- sigprocmask(SIG_BLOCK, &mask, &omask);
- switch ((*pid = fork())) {
- case -1:
- sigprocmask(SIG_SETMASK, &omask, 0);
- close(nulldesc);
- return (-1);
-
- case 0:
- /* XXX should check for NULL return */
- argv[0] = strdup("sh");
- argv[1] = strdup("-c");
- argv[2] = strdup(prog);
- argv[3] = NULL;
- if (argv[0] == NULL || argv[1] == NULL || argv[2] == NULL) {
- logerror("strdup");
- exit(1);
- }
-
- alarm(0);
- (void)setsid(); /* Avoid catching SIGHUPs. */
-
- /*
- * Throw away pending signals, and reset signal
- * behaviour to standard values.
- */
- signal(SIGALRM, SIG_IGN);
- signal(SIGHUP, SIG_IGN);
- sigprocmask(SIG_SETMASK, &omask, 0);
- signal(SIGPIPE, SIG_DFL);
- signal(SIGQUIT, SIG_DFL);
- signal(SIGALRM, SIG_DFL);
- signal(SIGHUP, SIG_DFL);
-
- dup2(pfd[0], STDIN_FILENO);
- dup2(nulldesc, STDOUT_FILENO);
- dup2(nulldesc, STDERR_FILENO);
- for (i = getdtablesize(); i > 2; i--)
- (void)close(i);
-
- (void)execvp(_PATH_BSHELL, argv);
- _exit(255);
- }
-
- sigprocmask(SIG_SETMASK, &omask, 0);
- close(nulldesc);
- close(pfd[0]);
- /*
- * Avoid blocking on a hung pipe. With O_NONBLOCK, we are
- * supposed to get an EWOULDBLOCK on writev(2), which is
- * caught by the logic above anyway, which will in turn close
- * the pipe, and fork a new logging subprocess if necessary.
- * The stale subprocess will be killed some time later unless
- * it terminated itself due to closing its input pipe (so we
- * get rid of really dead puppies).
- */
- if (fcntl(pfd[1], F_SETFL, O_NONBLOCK) == -1) {
- /* This is bad. */
- (void)snprintf(errmsg, sizeof errmsg,
- "Warning: cannot change pipe to PID %d to "
- "non-blocking behaviour.",
- (int)*pid);
- logerror(errmsg);
- }
- return (pfd[1]);
-}
-
-static void
-deadq_enter(pid_t pid, const char *name)
-{
- dq_t p;
- int status;
-
- /*
- * Be paranoid, if we can't signal the process, don't enter it
- * into the dead queue (perhaps it's already dead). If possible,
- * we try to fetch and log the child's status.
- */
- if (kill(pid, 0) != 0) {
- if (waitpid(pid, &status, WNOHANG) > 0)
- log_deadchild(pid, status, name);
- return;
- }
-
- p = malloc(sizeof(struct deadq_entry));
- if (p == NULL) {
- logerror("malloc");
- exit(1);
- }
-
- p->dq_pid = pid;
- p->dq_timeout = DQ_TIMO_INIT;
- TAILQ_INSERT_TAIL(&deadq_head, p, dq_entries);
-}
-
-static int
-deadq_remove(pid_t pid)
-{
- dq_t q;
-
- TAILQ_FOREACH(q, &deadq_head, dq_entries) {
- if (q->dq_pid == pid) {
- TAILQ_REMOVE(&deadq_head, q, dq_entries);
- free(q);
- return (1);
- }
- }
-
- return (0);
-}
-
-static void
-log_deadchild(pid_t pid, int status, const char *name)
-{
- int code;
- char buf[256];
- const char *reason;
-
- errno = 0; /* Keep strerror() stuff out of logerror messages. */
- if (WIFSIGNALED(status)) {
- reason = "due to signal";
- code = WTERMSIG(status);
- } else {
- reason = "with status";
- code = WEXITSTATUS(status);
- if (code == 0)
- return;
- }
- (void)snprintf(buf, sizeof buf,
- "Logging subprocess %d (%s) exited %s %d.",
- pid, name, reason, code);
- logerror(buf);
-}
-
-static int *
-socksetup(int af, const char *bindhostname)
-{
- struct addrinfo hints, *res, *r;
- int error, maxs, *s, *socks;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_flags = AI_PASSIVE;
- hints.ai_family = af;
- hints.ai_socktype = SOCK_DGRAM;
- error = getaddrinfo(bindhostname, "syslog", &hints, &res);
- if (error) {
- logerror(gai_strerror(error));
- errno = 0;
- die(0);
- }
-
- /* Count max number of sockets we may open */
- for (maxs = 0, r = res; r; r = r->ai_next, maxs++);
- socks = malloc((maxs+1) * sizeof(int));
- if (socks == NULL) {
- logerror("couldn't allocate memory for sockets");
- die(0);
- }
-
- *socks = 0; /* num of sockets counter at start of array */
- s = socks + 1;
- for (r = res; r; r = r->ai_next) {
- *s = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
- if (*s < 0) {
- logerror("socket");
- continue;
- }
- if (r->ai_family == AF_INET6) {
- int on = 1;
- if (setsockopt(*s, IPPROTO_IPV6, IPV6_V6ONLY,
- (char *)&on, sizeof (on)) < 0) {
- logerror("setsockopt");
- close(*s);
- continue;
- }
- }
- if (bind(*s, r->ai_addr, r->ai_addrlen) < 0) {
- close(*s);
- logerror("bind");
- continue;
- }
-
- (*socks)++;
- s++;
- }
-
- if (*socks == 0) {
- free(socks);
- if (Debug)
- return (NULL);
- else
- die(0);
- }
- if (res)
- freeaddrinfo(res);
-
- return (socks);
-}
+++ /dev/null
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static const char sccsid[] = "@(#)ttymsg.c 8.2 (Berkeley) 11/16/93";
-#endif
-
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "ttymsg.h"
-
-/*
- * Display the contents of a uio structure on a terminal. Used by wall(1),
- * syslogd(8), and talkd(8). Forks and finishes in child if write would block,
- * waiting up to tmout seconds. Returns pointer to error string on unexpected
- * error; string is not newline-terminated. Various "normal" errors are
- * ignored (exclusive-use, lack of permission, etc.).
- */
-const char *
-ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout)
-{
- struct iovec localiov[7];
- ssize_t left, wret;
- int cnt, fd;
- static char device[MAXNAMLEN] = _PATH_DEV;
- static char errbuf[1024];
- int forked;
-
- forked = 0;
- if (iovcnt > (int)(sizeof(localiov) / sizeof(localiov[0])))
- return ("too many iov's (change code in wall/ttymsg.c)");
-
- strlcpy(device + sizeof(_PATH_DEV) - 1, line, sizeof(device));
- if (strchr(device + sizeof(_PATH_DEV) - 1, '/')) {
- /* A slash is an attempt to break security... */
- (void) snprintf(errbuf, sizeof(errbuf),
- "Too many '/' in \"%s\"", device);
- return (errbuf);
- }
-
- /*
- * open will fail on slip lines or exclusive-use lines
- * if not running as root; not an error.
- */
- if ((fd = open(device, O_WRONLY|O_NONBLOCK, 0)) < 0) {
- if (errno == EBUSY || errno == EACCES)
- return (NULL);
- (void) snprintf(errbuf, sizeof(errbuf), "%s: %s", device,
- strerror(errno));
- return (errbuf);
- }
-
- for (cnt = 0, left = 0; cnt < iovcnt; ++cnt)
- left += iov[cnt].iov_len;
-
- for (;;) {
- wret = writev(fd, iov, iovcnt);
- if (wret >= left)
- break;
- if (wret >= 0) {
- left -= wret;
- if (iov != localiov) {
- bcopy(iov, localiov,
- iovcnt * sizeof(struct iovec));
- iov = localiov;
- }
- for (cnt = 0; (size_t)wret >= iov->iov_len; ++cnt) {
- wret -= iov->iov_len;
- ++iov;
- --iovcnt;
- }
- if (wret) {
- iov->iov_base = (char *)iov->iov_base + wret;
- iov->iov_len -= wret;
- }
- continue;
- }
- if (errno == EWOULDBLOCK) {
- int cpid;
-
- if (forked) {
- (void) close(fd);
- _exit(1);
- }
- cpid = fork();
- if (cpid < 0) {
- (void) snprintf(errbuf, sizeof(errbuf),
- "fork: %s", strerror(errno));
- (void) close(fd);
- return (errbuf);
- }
- if (cpid) { /* parent */
- (void) close(fd);
- return (NULL);
- }
- forked++;
- /* wait at most tmout seconds */
- (void) signal(SIGALRM, SIG_DFL);
- (void) signal(SIGTERM, SIG_DFL); /* XXX */
- (void) sigsetmask(0);
- (void) alarm((u_int)tmout);
- (void) fcntl(fd, F_SETFL, 0); /* clear O_NONBLOCK */
- continue;
- }
- /*
- * We get ENODEV on a slip line if we're running as root,
- * and EIO if the line just went away.
- */
- if (errno == ENODEV || errno == EIO)
- break;
- (void) close(fd);
- if (forked)
- _exit(1);
- (void) snprintf(errbuf, sizeof(errbuf),
- "%s: %s", device, strerror(errno));
- return (errbuf);
- }
-
- (void) close(fd);
- if (forked)
- _exit(0);
- return (NULL);
-}
+++ /dev/null
-/* $FreeBSD: src/usr.bin/wall/ttymsg.h,v 1.1 2001/09/09 14:23:31 dd Exp $ */
-
-const char *ttymsg(struct iovec *, int, const char *, int);
CFILES = ctl.c ctl_transact.c display.c get_addrs.c get_names.c\
init_disp.c invite.c io.c look_up.c msgs.c talk.c
-OTHERSRCS = Makefile.preamble Makefile talk.1
+OTHERSRCS = Makefile.preamble Makefile talk.1 Makefile.postamble
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
--- /dev/null
+after_install:
+ mkdir -p $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 talk.1 $(DSTROOT)/usr/share/man/man1/talk.1
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
CFILES = announce.c print.c process.c table.c talkd.c
OTHERSRCS = Makefile Makefile.dist Makefile.postamble Makefile.preamble\
- talkd.8
+ talkd.8 ntalk.plist
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
VPATH += :../wall.tproj
+after_install:
+ mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons"
+ cp ntalk.plist "$(DSTROOT)/System/Library/LaunchDaemons/"
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Disabled</key>
+ <true/>
+ <key>Label</key>
+ <string>com.apple.ntalkd</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/libexec/ntalkd</string>
+ </array>
+ <key>inetdCompatibility</key>
+ <dict>
+ <key>Wait</key>
+ <true/>
+ </dict>
+ <key>Sockets</key>
+ <dict>
+ <key>Listeners</key>
+ <dict>
+ <key>SockServiceName</key>
+ <string>ntalk</string>
+ <key>SockType</key>
+ <string>dgram</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
CFILES = authenc.c commands.c main.c network.c ring.c sys_bsd.c\
telnet.c terminal.c tn3270.c utilities.c
-OTHERSRCS = Makefile.preamble Makefile README telnet.1 Makefile.dist
+OTHERSRCS = Makefile.preamble Makefile README telnet.1 Makefile.dist Makefile.postamble
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
--- /dev/null
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 telnet.1 $(DSTROOT)/usr/share/man/man1
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
-#include <term.h>
#include <unistd.h>
#include <arpa/telnet.h>
}
unsigned char slc_reply[128];
+unsigned char const * const slc_reply_eom = &slc_reply[sizeof(slc_reply)];
unsigned char *slc_replyp;
void
void
slc_add_reply(unsigned char func, unsigned char flags, cc_t value)
{
+ /* A sequence of up to 6 bytes my be written for this member of the SLC
+ * suboption list by this function. The end of negotiation command,
+ * which is written by slc_end_reply(), will require 2 additional
+ * bytes. Do not proceed unless there is sufficient space for these
+ * items.
+ */
+ if (&slc_replyp[6+2] > slc_reply_eom)
+ return;
if ((*slc_replyp++ = func) == IAC)
*slc_replyp++ = IAC;
if ((*slc_replyp++ = flags) == IAC)
return;
}
vp = env_getvalue(ep);
- if (opt_replyp + (vp ? strlen((char *)vp) : 0) +
- strlen((char *)ep) + 6 > opt_replyend)
+ if (opt_replyp + 2*(vp ? strlen((char *)vp) : 0) +
+ 2*strlen((char *)ep) + 6 > opt_replyend)
{
int len;
- opt_replyend += OPT_REPLY_SIZE;
+ opt_replyend += OPT_REPLY_SIZE + 2*strlen((char *)ep) + 2*(vp ? strlen((char *)vp) : 0);
len = opt_replyend - opt_reply;
opt_reply = (unsigned char *)realloc(opt_reply, len);
if (opt_reply == NULL) {
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
CFILES = global.c slc.c state.c sys_term.c telnetd.c\
termstat.c utility.c vasprintf.c strlcpy.c
-OTHERSRCS = Makefile.preamble Makefile Makefile.postamble telnetd.8
+OTHERSRCS = Makefile.preamble Makefile Makefile.postamble telnetd.8 telnet.plist
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
after_install:
install -o root -g wheel -m 755 -d $(DSTROOT)/usr/share/man/man8
install -o root -g wheel -m 644 -c telnetd.8 $(DSTROOT)/usr/share/man/man8
+ mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons"
+ cp telnet.plist "$(DSTROOT)/System/Library/LaunchDaemons/"
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Disabled</key>
+ <true/>
+ <key>Label</key>
+ <string>com.apple.telnetd</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/libexec/telnetd</string>
+ </array>
+ <key>inetdCompatibility</key>
+ <dict>
+ <key>Wait</key>
+ <false/>
+ </dict>
+ <key>Sockets</key>
+ <dict>
+ <key>Listeners</key>
+ <dict>
+ <key>SockServiceName</key>
+ <string>telnet</string>
+ <key>Bonjour</key>
+ <true/>
+ </dict>
+ </dict>
+</dict>
+</plist>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <errno.h>
int
vasprintf(str, fmt, ap)
char **str;
const char *fmt;
- _BSD_VA_LIST_ ap;
+ va_list ap;
{
int ret;
FILE f;
PROJECTVERSION = 2.8
PROJECT_TYPE = Tool
-HFILES = extern.h tftpsubs.h
+HFILES = extern.h tftpsubs.h tftp.h
CFILES = main.c tftp.c tftpsubs.c
-OTHERSRCS = Makefile.preamble Makefile tftp.1
+OTHERSRCS = Makefile.preamble Makefile tftp.1 Makefile.postamble
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
--- /dev/null
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 tftp.1 $(DSTROOT)/usr/share/man/man1
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
+/* $NetBSD: extern.h,v 1.3 2003/08/07 11:16:13 agc Exp $ */
+
/*
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
* 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
*/
void recvfile __P((int, char *, char *));
-void tftp_sendfile __P((int, char *, char *));
+void sendfile __P((int, char *, char *));
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
+/* $NetBSD: main.c,v 1.19 2003/10/02 23:31:52 itojun Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
-
+#include <sys/cdefs.h>
#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1983, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
+ The Regents of the University of California. All rights reserved.\n");
+#if 0
+static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
+#else
+__RCSID("$NetBSD: main.c,v 1.19 2003/10/02 23:31:52 itojun Exp $");
+#endif
#endif /* not lint */
/* Many bug fixes are from Jim Guyton <guyton@rand-unix> */
*/
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/file.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include "tftp.h"
#include <ctype.h>
+#include <fcntl.h>
+#include <err.h>
#include <errno.h>
#include <netdb.h>
#include <setjmp.h>
#include "extern.h"
#define TIMEOUT 5 /* secs between rexmt's */
-
-struct sockaddr_in peeraddr;
+#define LBUFLEN 200 /* size of input buffer */
+#define MAXSEGSIZE 65464
+struct sockaddr_storage peeraddr;
int f;
-short port;
int trace;
int verbose;
+int tsize=0;
+int tout=0;
+int def_blksize=SEGSIZE;
+int blksize=SEGSIZE;
int connected;
char mode[32];
-char line[BUFSIZ];
+char line[LBUFLEN];
int margc;
char *margv[20];
char *prompt = "tftp";
jmp_buf toplevel;
-void intr();
-struct servent *sp;
void get __P((int, char **));
void help __P((int, char **));
void quit __P((int, char **));
void setascii __P((int, char **));
void setbinary __P((int, char **));
+void setpeer0 __P((char *, char *));
void setpeer __P((int, char **));
void setrexmt __P((int, char **));
void settimeout __P((int, char **));
void settrace __P((int, char **));
void setverbose __P((int, char **));
+void setblksize __P((int, char **));
+void settsize __P((int, char **));
+void settimeoutopt __P((int, char **));
void status __P((int, char **));
+char *tail __P((char *));
+int main __P((int, char *[]));
+void intr __P((int));
+struct cmd *getcmd __P((char *));
static __dead void command __P((void));
char vhelp[] = "toggle verbose mode";
char thelp[] = "toggle packet tracing";
+char tshelp[] = "toggle extended tsize option";
+char tohelp[] = "toggle extended timeout option";
+char blhelp[] = "set an alternative blocksize (def. 512)";
char chelp[] = "connect to remote tftp";
char qhelp[] = "exit tftp";
char hhelp[] = "print help information";
{ "get", rhelp, get },
{ "quit", qhelp, quit },
{ "verbose", vhelp, setverbose },
+ { "blksize", blhelp, setblksize },
+ { "tsize", tshelp, settsize },
{ "trace", thelp, settrace },
{ "status", sthelp, status },
{ "binary", bnhelp, setbinary },
{ "ascii", ashelp, setascii },
{ "rexmt", xhelp, setrexmt },
{ "timeout", ihelp, settimeout },
+ { "tout", tohelp, settimeoutopt },
{ "?", hhelp, help },
{ 0 }
};
-struct cmd *getcmd();
-char *tail();
-char *index();
-char *rindex();
-
int
main(argc, argv)
int argc;
char *argv[];
{
- struct sockaddr_in sin;
+ int c;
- sp = getservbyname("tftp", "udp");
- if (sp == 0) {
- fprintf(stderr, "tftp: udp/tftp: unknown service\n");
- exit(1);
- }
- f = socket(AF_INET, SOCK_DGRAM, 0);
- if (f < 0) {
- perror("tftp: socket");
- exit(3);
- }
- bzero((char *)&sin, sizeof(sin));
- sin.sin_family = AF_INET;
- if (bind(f, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- perror("tftp: bind");
- exit(1);
- }
+ f = -1;
strcpy(mode, "netascii");
signal(SIGINT, intr);
- if (argc > 1) {
+
+ setprogname(argv[0]);
+ while ((c = getopt(argc, argv, "e")) != -1) {
+ switch (c) {
+ case 'e':
+ blksize = MAXSEGSIZE;
+ strcpy(mode, "octet");
+ tsize = 1;
+ tout = 1;
+ break;
+ default:
+ printf("usage: %s [-e] host-name [port]\n",
+ getprogname());
+ exit(1);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc >= 1) {
if (setjmp(toplevel) != 0)
exit(0);
+ argc++;
+ argv--;
setpeer(argc, argv);
}
if (setjmp(toplevel) != 0)
(void)putchar('\n');
command();
+ return (0);
}
char hostname[100];
+void
+setpeer0(host, port)
+ char *host;
+ char *port;
+{
+ struct addrinfo hints, *res0, *res;
+ int error, soopt;
+ struct sockaddr_storage ss;
+ char *cause = "unknown";
+
+ if (connected) {
+ close(f);
+ f = -1;
+ }
+ connected = 0;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_UDP;
+ hints.ai_flags = AI_CANONNAME;
+ if (!port)
+ port = "tftp";
+ error = getaddrinfo(host, port, &hints, &res0);
+ if (error) {
+ warnx("%s", gai_strerror(error));
+ return;
+ }
+
+ for (res = res0; res; res = res->ai_next) {
+ if (res->ai_addrlen > sizeof(peeraddr))
+ continue;
+ f = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ if (f < 0) {
+ cause = "socket";
+ continue;
+ }
+
+ memset(&ss, 0, sizeof(ss));
+ ss.ss_family = res->ai_family;
+ ss.ss_len = res->ai_addrlen;
+ if (bind(f, (struct sockaddr *)&ss, ss.ss_len) < 0) {
+ cause = "bind";
+ close(f);
+ f = -1;
+ continue;
+ }
+
+ break;
+ }
+
+ if (f >= 0) {
+ soopt = 65536;
+ if (setsockopt(f, SOL_SOCKET, SO_SNDBUF, &soopt, sizeof(soopt))
+ < 0) {
+ close(f);
+ f = -1;
+ cause = "setsockopt SNDBUF";
+ }
+ if (setsockopt(f, SOL_SOCKET, SO_RCVBUF, &soopt, sizeof(soopt))
+ < 0) {
+ close(f);
+ f = -1;
+ cause = "setsockopt RCVBUF";
+ }
+ }
+
+ if (f < 0)
+ warn("%s", cause);
+ else {
+ /* res->ai_addr <= sizeof(peeraddr) is guaranteed */
+ memcpy(&peeraddr, res->ai_addr, res->ai_addrlen);
+ if (res->ai_canonname) {
+ (void) strlcpy(hostname, res->ai_canonname,
+ sizeof(hostname));
+ } else
+ (void) strlcpy(hostname, host, sizeof(hostname));
+ connected = 1;
+ }
+
+ freeaddrinfo(res0);
+}
+
void
setpeer(argc, argv)
int argc;
char *argv[];
{
- struct hostent *host;
if (argc < 2) {
strcpy(line, "Connect ");
printf("(to) ");
- fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin);
+ fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
makeargv();
argc = margc;
argv = margv;
}
- if (argc > 3) {
- printf("usage: %s host-name [port]\n", argv[0]);
+ if ((argc < 2) || (argc > 3)) {
+ printf("usage: %s [-e] host-name [port]\n", getprogname());
return;
}
- host = gethostbyname(argv[1]);
- if (host) {
- peeraddr.sin_family = host->h_addrtype;
- bcopy(host->h_addr, &peeraddr.sin_addr, host->h_length);
- strcpy(hostname, host->h_name);
- } else {
- peeraddr.sin_family = AF_INET;
- peeraddr.sin_addr.s_addr = inet_addr(argv[1]);
- if (peeraddr.sin_addr.s_addr == -1) {
- connected = 0;
- printf("%s: unknown host\n", argv[1]);
- return;
- }
- strcpy(hostname, argv[1]);
- }
- port = sp->s_port;
- if (argc == 3) {
- port = atoi(argv[2]);
- if (port < 0) {
- printf("%s: bad port number\n", argv[2]);
- connected = 0;
- return;
- }
- port = htons(port);
- }
- connected = 1;
+ if (argc == 2)
+ setpeer0(argv[1], NULL);
+ else
+ setpeer0(argv[1], argv[2]);
}
struct modes {
int argc;
char *argv[];
{
- register struct modes *p;
+ struct modes *p;
char *sep;
if (argc < 2) {
char *argv[];
{
int fd;
- register int n;
- register char *cp, *targ;
+ int n;
+ char *cp, *targ;
if (argc < 2) {
strcpy(line, "send ");
printf("(file) ");
- fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin);
+ fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
makeargv();
argc = margc;
argv = margv;
return;
}
targ = argv[argc - 1];
- if (index(argv[argc - 1], ':')) {
+ if (strrchr(argv[argc - 1], ':')) {
char *cp;
- struct hostent *hp;
for (n = 1; n < argc - 1; n++)
- if (index(argv[n], ':')) {
+ if (strchr(argv[n], ':')) {
putusage(argv[0]);
return;
}
cp = argv[argc - 1];
- targ = index(cp, ':');
+ targ = strrchr(cp, ':');
*targ++ = 0;
- hp = gethostbyname(cp);
- if (hp == NULL) {
- fprintf(stderr, "tftp: %s: ", cp);
- herror((char *)NULL);
- return;
+ if (cp[0] == '[' && cp[strlen(cp) - 1] == ']') {
+ cp[strlen(cp) - 1] = '\0';
+ cp++;
}
- bcopy(hp->h_addr, (caddr_t)&peeraddr.sin_addr, hp->h_length);
- peeraddr.sin_family = hp->h_addrtype;
- connected = 1;
- strcpy(hostname, hp->h_name);
+ setpeer0(cp, NULL);
}
if (!connected) {
printf("No target machine specified.\n");
cp = argc == 2 ? tail(targ) : argv[1];
fd = open(cp, O_RDONLY);
if (fd < 0) {
- fprintf(stderr, "tftp: "); perror(cp);
+ warn("%s", cp);
return;
}
if (verbose)
printf("putting %s to %s:%s [%s]\n",
cp, hostname, targ, mode);
- peeraddr.sin_port = port;
- tftp_sendfile(fd, targ, mode);
+ sendfile(fd, targ, mode);
return;
}
/* this assumes the target is a directory */
/* on a remote unix system. hmmmm. */
- cp = index(targ, '\0');
+ cp = strchr(targ, '\0');
*cp++ = '/';
for (n = 1; n < argc - 1; n++) {
strcpy(cp, tail(argv[n]));
fd = open(argv[n], O_RDONLY);
if (fd < 0) {
- fprintf(stderr, "tftp: "); perror(argv[n]);
+ warn("%s", argv[n]);
continue;
}
if (verbose)
printf("putting %s to %s:%s [%s]\n",
argv[n], hostname, targ, mode);
- peeraddr.sin_port = port;
- tftp_sendfile(fd, targ, mode);
+ sendfile(fd, targ, mode);
}
}
char *argv[];
{
int fd;
- register int n;
- register char *cp;
+ int n;
+ char *cp;
char *src;
if (argc < 2) {
strcpy(line, "get ");
printf("(files) ");
- fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin);
+ fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
makeargv();
argc = margc;
argv = margv;
}
if (!connected) {
for (n = 1; n < argc ; n++)
- if (index(argv[n], ':') == 0) {
+ if (strrchr(argv[n], ':') == 0) {
getusage(argv[0]);
return;
}
}
for (n = 1; n < argc ; n++) {
- src = index(argv[n], ':');
+ src = strrchr(argv[n], ':');
if (src == NULL)
src = argv[n];
else {
- struct hostent *hp;
-
+ char *cp;
*src++ = 0;
- hp = gethostbyname(argv[n]);
- if (hp == NULL) {
- fprintf(stderr, "tftp: %s: ", argv[n]);
- herror((char *)NULL);
- continue;
+ cp = argv[n];
+ if (cp[0] == '[' && cp[strlen(cp) - 1] == ']') {
+ cp[strlen(cp) - 1] = '\0';
+ cp++;
}
- bcopy(hp->h_addr, (caddr_t)&peeraddr.sin_addr,
- hp->h_length);
- peeraddr.sin_family = hp->h_addrtype;
- connected = 1;
- strcpy(hostname, hp->h_name);
+ setpeer0(cp, NULL);
+ if (!connected)
+ continue;
}
if (argc < 4) {
cp = argc == 3 ? argv[2] : tail(src);
fd = creat(cp, 0644);
if (fd < 0) {
- fprintf(stderr, "tftp: "); perror(cp);
+ warn("%s", cp);
return;
}
if (verbose)
printf("getting from %s:%s to %s [%s]\n",
hostname, src, cp, mode);
- peeraddr.sin_port = port;
recvfile(fd, src, mode);
break;
}
cp = tail(src); /* new .. jdg */
fd = creat(cp, 0644);
if (fd < 0) {
- fprintf(stderr, "tftp: "); perror(cp);
+ warn("%s", cp);
continue;
}
if (verbose)
printf("getting from %s:%s to %s [%s]\n",
hostname, src, cp, mode);
- peeraddr.sin_port = port;
recvfile(fd, src, mode);
}
}
printf(" %s file file ... file if connected\n", s);
}
+void
+setblksize(argc, argv)
+ int argc;
+ char *argv[];
+{
+ int t;
+
+ if (argc < 2) {
+ strcpy(line, "blksize ");
+ printf("(blksize) ");
+ fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
+ makeargv();
+ argc = margc;
+ argv = margv;
+ }
+ if (argc != 2) {
+ printf("usage: %s value\n", argv[0]);
+ return;
+ }
+ t = atoi(argv[1]);
+ if (t < 8 || t > 65464)
+ printf("%s: bad value\n", argv[1]);
+ else
+ blksize = t;
+}
+
+int def_rexmtval = TIMEOUT;
int rexmtval = TIMEOUT;
void
if (argc < 2) {
strcpy(line, "Rexmt-timeout ");
printf("(value) ");
- fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin);
+ fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
makeargv();
argc = margc;
argv = margv;
if (argc < 2) {
strcpy(line, "Maximum-timeout ");
printf("(value) ");
- fgets(&line[strlen(line)], BUFSIZ-strlen(line)-1, stdin);
+ fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
makeargv();
argc = margc;
argv = margv;
}
void
-intr()
+intr(dummy)
+ int dummy;
{
signal(SIGALRM, SIG_IGN);
tail(filename)
char *filename;
{
- register char *s;
+ char *s;
while (*filename) {
- s = rindex(filename, '/');
+ s = strrchr(filename, '/');
if (s == NULL)
break;
if (s[1])
static __dead void
command()
{
- register struct cmd *c;
+ struct cmd *c;
for (;;) {
printf("%s> ", prompt);
- if (fgets(line, BUFSIZ-1, stdin) == 0) {
+ if (fgets(line, LBUFLEN, stdin) == 0) {
if (feof(stdin)) {
exit(0);
} else {
continue;
}
}
- if (line[0] == 0)
+ if ((line[0] == 0) || (line[0] == '\n'))
continue;
makeargv();
if (margc == 0)
struct cmd *
getcmd(name)
- register char *name;
+ char *name;
{
- register char *p, *q;
- register struct cmd *c, *found;
- register int nmatches, longest;
+ char *p, *q;
+ struct cmd *c, *found;
+ int nmatches, longest;
longest = 0;
nmatches = 0;
static void
makeargv()
{
- register char *cp;
- register char **argp = margv;
+ char *cp;
+ char **argp = margv;
margc = 0;
for (cp = line; *cp;) {
- while (isspace(*cp))
+ while (isspace((unsigned char)*cp))
cp++;
if (*cp == '\0')
break;
*argp++ = cp;
margc += 1;
- while (*cp != '\0' && !isspace(*cp))
+ while (*cp != '\0' && !isspace((unsigned char)*cp))
cp++;
if (*cp == '\0')
break;
int argc;
char *argv[];
{
- register struct cmd *c;
+ struct cmd *c;
if (argc == 1) {
printf("Commands may be abbreviated. Commands are:\n\n");
return;
}
while (--argc > 0) {
- register char *arg;
+ char *arg;
arg = *++argv;
c = getcmd(arg);
if (c == (struct cmd *)-1)
verbose = !verbose;
printf("Verbose mode %s.\n", verbose ? "on" : "off");
}
+
+void
+settsize(argc, argv)
+ int argc;
+ char **argv;
+{
+ tsize = !tsize;
+ printf("Tsize mode %s.\n", tsize ? "on" : "off");
+}
+
+void
+settimeoutopt(argc, argv)
+ int argc;
+ char **argv;
+{
+ tout = !tout;
+ printf("Timeout option %s.\n", tout ? "on" : "off");
+}
+.\" $NetBSD: tftp.1,v 1.18 2003/08/07 11:16:14 agc Exp $
+.\"
.\" Copyright (c) 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
.\"
.\" 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 the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
+.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\"
.\" @(#)tftp.1 8.2 (Berkeley) 4/18/94
.\"
-.Dd April 18, 1994
+.Dd June 11, 2003
.Dt TFTP 1
-.Os BSD 4.3
+.Os
.Sh NAME
.Nm tftp
.Nd trivial file transfer program
.Sh SYNOPSIS
-.Nm tftp
+.Nm
+.Op Fl e
.Op Ar host
+.Op Ar port
.Sh DESCRIPTION
-.Nm Tftp
+.Nm
is the user interface to the Internet
.Tn TFTP
(Trivial File Transfer Protocol),
which allows users to transfer files to and from a remote machine.
The remote
.Ar host
+(and optional
+.Ar port )
may be specified on the command line, in which case
-.Nm tftp
+.Nm
uses
.Ar host
-as the default host for future transfers (see the
+(and
+.Ar port )
+as the default for future transfers (see the
.Cm connect
command below).
+.Pp
+The optional
+.Fl e
+argument sets a binary transfer mode as well as setting the extended options
+as if
+.Cm tout ,
+.Cm tsize ,
+and
+.Cm blksize 65464 ,
+had been given.
.Sh COMMANDS
Once
-.Nm tftp
+.Nm
is running, it issues the prompt
-.LI tftp>
+.Ql tftp\*[Gt]
and recognizes the following commands:
.Pp
.Bl -tag -width verbose -compact
.It Cm binary
Shorthand for "mode binary"
.Pp
+.It Cm blksize Ar blk-size
+Set the tftp blksize option to
+.Ar blk-size
+octets (8-bit bytes). Since the number of blocks in a tftp
+.Cm get
+or
+.Cm put
+is 65535, the default block size of 512 bytes only allows a maximum of
+just under 32 megabytes to be transferred. The value given for
+.Ar blk-size
+must be between 8 and 65464, inclusive.
+Note that many servers will not respect this option.
+.Pp
.It Cm connect Ar host-name Op Ar port
Set the
.Ar host
.Cm connect
command does not actually create a connection,
but merely remembers what host is to be used for transfers.
-You do not have to use the
+You do not have to use the
.Cm connect
command; the remote host can be specified as part of the
.Cm get
the last hostname specified becomes the default for future transfers.
.Pp
.It Cm mode Ar transfer-mode
-Set the mode for transfers;
+Set the mode for transfers;
.Ar transfer-mode
may be one of
.Em ascii
the hostname specified becomes the default for future transfers.
If the remote-directory form is used, the remote host is
assumed to be a
-.Tn UNIX
+.Ux
machine.
+If you need to specify IPv6 numeric address to
+.Ar hosts ,
+wrap them using square bracket like
+.Ar [hosts]:filename
+to disambiguate the colon.
.Pp
.It Cm quit
Exit
-.Nm tftp .
+.Nm .
An end of file also exits.
.Pp
.It Cm rexmt Ar retransmission-timeout
.It Cm timeout Ar total-transmission-timeout
Set the total transmission timeout, in seconds.
.Pp
+.It Cm tout
+Toggle the tftp "timeout" option. If enabled, the client will pass its
+.Ar retransmission-timeout
+to the server.
+Note that many servers will not respect this option.
+.Pp
.It Cm trace
Toggle packet tracing.
.Pp
+.It Cm tsize
+Toggle the tftp "tsize" option. If enabled, the client will pass and
+request the filesize of a file at the beginning of a file transfer.
+Note that many servers will not respect this option.
+.Pp
.It Cm verbose
Toggle verbose mode.
.El
-.Sh BUGS
-.Pp
-Because there is no user-login or validation within
-the
-.Tn TFTP
-protocol, the remote site will probably have some
-sort of file-access restrictions in place. The
-exact methods are specific to each site and therefore
-difficult to document here.
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.3 .
+IPv6 support was implemented by WIDE/KAME project in 1999.
+TFTP options were implemented by Wasabi Systems, Inc., in 2003,
+and first appeared in
+.Nx 2.0 .
+.Sh SECURITY CONSIDERATIONS
+Because there is no user-login or validation within
+the
+.Tn TFTP
+protocol, the remote site will probably have some
+sort of file-access restrictions in place.
+The exact methods are specific to each site and therefore
+difficult to document here.
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
+/* $NetBSD: tftp.c,v 1.18 2003/08/07 11:16:14 agc Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93";
+#else
+__RCSID("$NetBSD: tftp.c,v 1.18 2003/08/07 11:16:14 agc Exp $");
+#endif
+#endif /* not lint */
/* Many bug fixes are from Jim Guyton <guyton@rand-unix> */
* TFTP User Program -- Protocol Machines
*/
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/time.h>
#include <netinet/in.h>
-#include <arpa/tftp.h>
+#include "tftp.h"
+#include <err.h>
#include <errno.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
+#include <netdb.h>
#include "extern.h"
#include "tftpsubs.h"
-extern int errno;
-
-extern struct sockaddr_in peeraddr; /* filled in by main */
+extern struct sockaddr_storage peeraddr; /* filled in by main */
extern int f; /* the opened socket */
extern int trace;
extern int verbose;
+extern int def_rexmtval;
extern int rexmtval;
extern int maxtimeout;
+extern int tsize;
+extern int tout;
+extern int def_blksize;
+extern int blksize;
-extern jmp_buf toplevel; /* filled in by main */
-
-#define PKTSIZE SEGSIZE+4
char ackbuf[PKTSIZE];
int timeout;
+extern jmp_buf toplevel;
jmp_buf timeoutbuf;
-static void nak __P((int));
-static int makerequest __P((int, const char *, struct tftphdr *, const char *));
+static void nak __P((int, struct sockaddr *));
+static int makerequest __P((int, const char *, struct tftphdr *, const char *, off_t));
static void printstats __P((const char *, unsigned long));
static void startclock __P((void));
static void stopclock __P((void));
static void timer __P((int));
static void tpacket __P((const char *, struct tftphdr *, int));
+static int cmpport __P((struct sockaddr *, struct sockaddr *));
+
+static void get_options(struct tftphdr *, int);
+
+static void
+get_options(struct tftphdr *ap, int size)
+{
+ unsigned long val;
+ char *opt, *endp, *nextopt, *valp;
+ int l;
+
+ size -= 2; /* skip over opcode */
+ opt = ap->th_stuff;
+ endp = opt + size - 1;
+ *endp = '\0';
+
+ while (opt < endp) {
+ l = strlen(opt) + 1;
+ valp = opt + l;
+ if (valp < endp) {
+ val = strtoul(valp, NULL, 10);
+ l = strlen(valp) + 1;
+ nextopt = valp + l;
+ if (val == ULONG_MAX && errno == ERANGE) {
+ /* Report illegal value */
+ opt = nextopt;
+ continue;
+ }
+ } else {
+ /* Badly formed OACK */
+ break;
+ }
+ if (strcmp(opt, "tsize") == 0) {
+ /* cool, but we'll ignore it */
+ } else if (strcmp(opt, "timeout") == 0) {
+ if (val >= 1 && val <= 255) {
+ rexmtval = val;
+ } else {
+ /* Report error? */
+ }
+ } else if (strcmp(opt, "blksize") == 0) {
+ if (val >= 8 && val <= MAXSEGSIZE) {
+ blksize = val;
+ } else {
+ /* Report error? */
+ }
+ } else {
+ /* unknown option */
+ }
+ opt = nextopt;
+ }
+}
/*
* Send the requested file.
*/
void
-tftp_sendfile(fd, name, mode)
+sendfile(fd, name, mode)
int fd;
char *name;
char *mode;
{
- register struct tftphdr *ap; /* data and ack packets */
- struct tftphdr *r_init(), *dp;
- register int n;
- volatile int block, size, convert;
+ struct tftphdr *ap; /* data and ack packets */
+ struct tftphdr *dp;
+ int n;
+ volatile unsigned int block;
+ volatile int size, convert;
volatile unsigned long amount;
- struct sockaddr_in from;
+ struct sockaddr_storage from;
+ struct stat sbuf;
+ off_t filesize=0;
int fromlen;
FILE *file;
+ struct sockaddr_storage peer;
+ struct sockaddr_storage serv; /* valid server port number */
startclock(); /* start stat's clock */
dp = r_init(); /* reset fillbuf/read-ahead code */
ap = (struct tftphdr *)ackbuf;
+ if (tsize) {
+ if (fstat(fd, &sbuf) == 0) {
+ filesize = sbuf.st_size;
+ } else {
+ filesize = -1ULL;
+ }
+ }
file = fdopen(fd, "r");
convert = !strcmp(mode, "netascii");
block = 0;
amount = 0;
+ memcpy(&peer, &peeraddr, peeraddr.ss_len);
+ memset(&serv, 0, sizeof(serv));
signal(SIGALRM, timer);
do {
if (block == 0)
- size = makerequest(WRQ, name, dp, mode) - 4;
+ size = makerequest(WRQ, name, dp, mode, filesize) - 4;
else {
/* size = read(fd, dp->th_data, SEGSIZE); */
- size = readit(file, &dp, convert);
+ size = readit(file, &dp, blksize, convert);
if (size < 0) {
- nak(errno + 100);
+ nak(errno + 100, (struct sockaddr *)&peer);
break;
}
dp->th_opcode = htons((u_short)DATA);
if (trace)
tpacket("sent", dp, size + 4);
n = sendto(f, dp, size + 4, 0,
- (struct sockaddr *)&peeraddr, sizeof(peeraddr));
+ (struct sockaddr *)&peer, peer.ss_len);
if (n != size + 4) {
- perror("tftp: sendto");
+ warn("sendto");
goto abort;
}
- read_ahead(file, convert);
+ if (block)
+ read_ahead(file, blksize, convert);
for ( ; ; ) {
alarm(rexmtval);
do {
} while (n <= 0);
alarm(0);
if (n < 0) {
- perror("tftp: recvfrom");
+ warn("recvfrom");
goto abort;
}
- peeraddr.sin_port = from.sin_port; /* added */
+ if (!serv.ss_family)
+ serv = from;
+ else if (!cmpport((struct sockaddr *)&serv,
+ (struct sockaddr *)&from)) {
+ warn("server port mismatch");
+ goto abort;
+ }
+ peer = from;
if (trace)
tpacket("received", ap, n);
/* should verify packet came from server */
if (ap->th_opcode == ACK) {
int j;
+ if (ap->th_block == 0) {
+ /*
+ * If the extended options are enabled,
+ * the server just refused 'em all.
+ * The only one that _really_
+ * matters is blksize, but we'll
+ * clear timeout, too.
+ */
+ blksize = def_blksize;
+ rexmtval = def_rexmtval;
+ }
if (ap->th_block == block) {
break;
}
/* On an error, try to synchronize
* both sides.
*/
- j = synchnet(f);
+ j = synchnet(f, blksize+4);
if (j && trace) {
printf("discarded %d packets\n",
j);
goto send_data;
}
}
+ if (ap->th_opcode == OACK) {
+ if (block == 0) {
+ blksize = def_blksize;
+ rexmtval = def_rexmtval;
+ get_options(ap, n);
+ break;
+ }
+ }
}
if (block > 0)
amount += size;
block++;
- } while (size == SEGSIZE || block == 1);
+ } while (size == blksize || block == 1);
abort:
fclose(file);
stopclock();
char *name;
char *mode;
{
- register struct tftphdr *ap;
- struct tftphdr *dp, *w_init();
- register int n;
- volatile int block, size, firsttrip;
+ struct tftphdr *ap;
+ struct tftphdr *dp;
+ int n, oack=0;
+ volatile unsigned int block;
+ volatile int size, firsttrip;
volatile unsigned long amount;
- struct sockaddr_in from;
- int fromlen;
+ struct sockaddr_storage from;
+ int fromlen, readlen;
FILE *file;
volatile int convert; /* true if converting crlf -> lf */
+ struct sockaddr_storage peer;
+ struct sockaddr_storage serv; /* valid server port number */
startclock();
dp = w_init();
block = 1;
firsttrip = 1;
amount = 0;
+ memcpy(&peer, &peeraddr, peeraddr.ss_len);
+ memset(&serv, 0, sizeof(serv));
signal(SIGALRM, timer);
do {
if (firsttrip) {
- size = makerequest(RRQ, name, ap, mode);
+ size = makerequest(RRQ, name, ap, mode, 0);
+ readlen = PKTSIZE;
firsttrip = 0;
} else {
ap->th_opcode = htons((u_short)ACK);
ap->th_block = htons((u_short)(block));
+ readlen = blksize+4;
size = 4;
block++;
}
send_ack:
if (trace)
tpacket("sent", ap, size);
- if (sendto(f, ackbuf, size, 0, (struct sockaddr *)&peeraddr,
- sizeof(peeraddr)) != size) {
+ if (sendto(f, ackbuf, size, 0, (struct sockaddr *)&peer,
+ peer.ss_len) != size) {
alarm(0);
- perror("tftp: sendto");
+ warn("sendto");
goto abort;
}
write_behind(file, convert);
alarm(rexmtval);
do {
fromlen = sizeof(from);
- n = recvfrom(f, dp, PKTSIZE, 0,
+ n = recvfrom(f, dp, readlen, 0,
(struct sockaddr *)&from, &fromlen);
} while (n <= 0);
alarm(0);
if (n < 0) {
- perror("tftp: recvfrom");
+ warn("recvfrom");
goto abort;
}
- peeraddr.sin_port = from.sin_port; /* added */
+ if (!serv.ss_family)
+ serv = from;
+ else if (!cmpport((struct sockaddr *)&serv,
+ (struct sockaddr *)&from)) {
+ warn("server port mismatch");
+ goto abort;
+ }
+ peer = from;
if (trace)
tpacket("received", dp, n);
/* should verify client address */
if (dp->th_opcode == DATA) {
int j;
+ if (dp->th_block == 1 && !oack) {
+ /* no OACK, revert to defaults */
+ blksize = def_blksize;
+ rexmtval = def_rexmtval;
+ }
if (dp->th_block == block) {
break; /* have next packet */
}
/* On an error, try to synchronize
* both sides.
*/
- j = synchnet(f);
+ j = synchnet(f, blksize);
if (j && trace) {
printf("discarded %d packets\n", j);
}
goto send_ack; /* resend ack */
}
}
+ if (dp->th_opcode == OACK) {
+ if (block == 1) {
+ oack = 1;
+ blksize = def_blksize;
+ rexmtval = def_rexmtval;
+ get_options(dp, n);
+ ap->th_opcode = htons(ACK);
+ ap->th_block = 0;
+ readlen = blksize+4;
+ size = 4;
+ goto send_ack;
+ }
+ }
}
/* size = write(fd, dp->th_data, n - 4); */
size = writeit(file, &dp, n - 4, convert);
if (size < 0) {
- nak(errno + 100);
+ nak(errno + 100, (struct sockaddr *)&peer);
break;
}
amount += size;
- } while (size == SEGSIZE);
+ } while (size == blksize || block == 1);
abort: /* ok to ack, since user */
ap->th_opcode = htons((u_short)ACK); /* has seen err msg */
ap->th_block = htons((u_short)block);
- (void) sendto(f, ackbuf, 4, 0, (struct sockaddr *)&peeraddr,
- sizeof(peeraddr));
+ (void) sendto(f, ackbuf, 4, 0, (struct sockaddr *)&peer,
+ peer.ss_len);
write_behind(file, convert); /* flush last buffer */
fclose(file);
stopclock();
}
static int
-makerequest(request, name, tp, mode)
+makerequest(request, name, tp, mode, filesize)
int request;
const char *name;
struct tftphdr *tp;
const char *mode;
+ off_t filesize;
{
- register char *cp;
+ char *cp;
tp->th_opcode = htons((u_short)request);
+#ifndef __SVR4
cp = tp->th_stuff;
+#else
+ cp = (void *)&tp->th_stuff;
+#endif
strcpy(cp, name);
cp += strlen(name);
*cp++ = '\0';
strcpy(cp, mode);
cp += strlen(mode);
*cp++ = '\0';
+ if (tsize) {
+ strcpy(cp, "tsize");
+ cp += strlen(cp);
+ *cp++ = '\0';
+ sprintf(cp, "%lu", (unsigned long) filesize);
+ cp += strlen(cp);
+ *cp++ = '\0';
+ }
+ if (tout) {
+ strcpy(cp, "timeout");
+ cp += strlen(cp);
+ *cp++ = '\0';
+ sprintf(cp, "%d", rexmtval);
+ cp += strlen(cp);
+ *cp++ = '\0';
+ }
+ if (blksize != SEGSIZE) {
+ strcpy(cp, "blksize");
+ cp += strlen(cp);
+ *cp++ = '\0';
+ sprintf(cp, "%d", blksize);
+ cp += strlen(cp);
+ *cp++ = '\0';
+ }
return (cp - (char *)tp);
}
-struct errmsg {
+const struct errmsg {
int e_code;
- char *e_msg;
+ const char *e_msg;
} errmsgs[] = {
{ EUNDEF, "Undefined error code" },
{ ENOTFOUND, "File not found" },
{ EBADID, "Unknown transfer ID" },
{ EEXISTS, "File already exists" },
{ ENOUSER, "No such user" },
+ { EOPTNEG, "Option negotiation failed" },
{ -1, 0 }
};
* offset by 100.
*/
static void
-nak(error)
+nak(error, peer)
int error;
+ struct sockaddr *peer;
{
- register struct errmsg *pe;
- register struct tftphdr *tp;
+ const struct errmsg *pe;
+ struct tftphdr *tp;
int length;
- char *strerror();
+ size_t msglen;
tp = (struct tftphdr *)ackbuf;
tp->th_opcode = htons((u_short)ERROR);
- tp->th_code = htons((u_short)error);
+ msglen = sizeof(ackbuf) - (&tp->th_msg[0] - ackbuf);
for (pe = errmsgs; pe->e_code >= 0; pe++)
if (pe->e_code == error)
break;
if (pe->e_code < 0) {
- pe->e_msg = strerror(error - 100);
tp->th_code = EUNDEF;
+ strlcpy(tp->th_msg, strerror(error - 100), msglen);
+ } else {
+ tp->th_code = htons((u_short)error);
+ strlcpy(tp->th_msg, pe->e_msg, msglen);
}
- strcpy(tp->th_msg, pe->e_msg);
- length = strlen(pe->e_msg) + 4;
+ length = strlen(tp->th_msg);
+ msglen = &tp->th_msg[length + 1] - ackbuf;
if (trace)
- tpacket("sent", tp, length);
- if (sendto(f, ackbuf, length, 0, (struct sockaddr *)&peeraddr,
- sizeof(peeraddr)) != length)
- perror("nak");
+ tpacket("sent", tp, (int)msglen);
+ if (sendto(f, ackbuf, msglen, 0, peer, peer->sa_len) != msglen)
+ warn("nak");
}
static void
int n;
{
static char *opcodes[] =
- { "#0", "RRQ", "WRQ", "DATA", "ACK", "ERROR" };
- register char *cp, *file;
+ { "#0", "RRQ", "WRQ", "DATA", "ACK", "ERROR", "OACK" };
+ char *cp, *file, *endp, *opt, *spc;
u_short op = ntohs(tp->th_opcode);
- char *index();
+ int i, o;
- if (op < RRQ || op > ERROR)
+ if (op < RRQ || op > OACK)
printf("%s opcode=%x ", s, op);
else
printf("%s %s ", s, opcodes[op]);
case RRQ:
case WRQ:
n -= 2;
- file = cp = tp->th_stuff;
- cp = index(cp, '\0');
- printf("<file=%s, mode=%s>\n", file, cp + 1);
+#ifndef __SVR4
+ cp = tp->th_stuff;
+#else
+ cp = (void *) &tp->th_stuff;
+#endif
+ endp = cp + n - 1;
+ if (*endp != '\0') { /* Shouldn't happen, but... */
+ *endp = '\0';
+ }
+ file = cp;
+ cp = strchr(cp, '\0') + 1;
+ printf("<file=%s, mode=%s", file, cp);
+ cp = strchr(cp, '\0') + 1;
+ o = 0;
+ while (cp < endp) {
+ i = strlen(cp) + 1;
+ if (o) {
+ printf(", %s=%s", opt, cp);
+ } else {
+ opt = cp;
+ }
+ o = (o+1) % 2;
+ cp += i;
+ }
+ printf(">\n");
break;
case DATA:
case ERROR:
printf("<code=%d, msg=%s>\n", ntohs(tp->th_code), tp->th_msg);
break;
+
+ case OACK:
+ o = 0;
+ n -= 2;
+ cp = tp->th_stuff;
+ endp = cp + n - 1;
+ if (*endp != '\0') { /* Shouldn't happen, but... */
+ *endp = '\0';
+ }
+ printf("<");
+ spc = "";
+ while (cp < endp) {
+ i = strlen(cp) + 1;
+ if (o) {
+ printf("%s%s=%s", spc, opt, cp);
+ spc = ", ";
+ } else {
+ opt = cp;
+ }
+ o = (o+1) % 2;
+ cp += i;
+ }
+ printf(">\n");
+ break;
}
}
unsigned long amount;
{
double delta;
- /* compute delta in 1/10's second units */
+
+ /* compute delta in 1/10's second units */
delta = ((tstop.tv_sec*10.)+(tstop.tv_usec/100000)) -
((tstart.tv_sec*10.)+(tstart.tv_usec/100000));
delta = delta/10.; /* back to seconds */
- printf("%s %d bytes in %.1f seconds", direction, amount, delta);
+ printf("%s %ld bytes in %.1f seconds", direction, amount, delta);
if (verbose)
printf(" [%.0f bits/sec]", (amount*8.)/delta);
putchar('\n');
}
longjmp(timeoutbuf, 1);
}
+
+static int
+cmpport(sa, sb)
+ struct sockaddr *sa;
+ struct sockaddr *sb;
+{
+ char a[NI_MAXSERV], b[NI_MAXSERV];
+
+ if (getnameinfo(sa, sa->sa_len, NULL, 0, a, sizeof(a), NI_NUMERICSERV))
+ return 0;
+ if (getnameinfo(sb, sb->sa_len, NULL, 0, b, sizeof(b), NI_NUMERICSERV))
+ return 0;
+ if (strcmp(a, b) != 0)
+ return 0;
+
+ return 1;
+}
--- /dev/null
+/* $NetBSD: tftp.h,v 1.8 2003/08/07 09:44:12 agc Exp $ */
+
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tftp.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _ARPA_TFTP_H_
+#define _ARPA_TFTP_H_
+
+/*
+ * Trivial File Transfer Protocol (IEN-133)
+ */
+#define SEGSIZE 512 /* data segment size */
+#define MAXSEGSIZE 65464 /* maximum negotiated data segment size */
+
+#define PKTSIZE SEGSIZE + 4
+#define MAXPKTSIZE MAXSEGSIZE + 4
+
+/*
+ * Packet types.
+ */
+#define RRQ 01 /* read request */
+#define WRQ 02 /* write request */
+#define DATA 03 /* data packet */
+#define ACK 04 /* acknowledgement */
+#define ERROR 05 /* error code */
+#define OACK 06 /* option acknowledgement */
+
+struct tftphdr {
+ short th_opcode; /* packet type */
+ union {
+ unsigned short tu_block; /* block # */
+ short tu_code; /* error code */
+ char tu_stuff[1]; /* request packet stuff */
+ } th_u;
+ char th_data[1]; /* data or error string */
+};
+
+#define th_block th_u.tu_block
+#define th_code th_u.tu_code
+#define th_stuff th_u.tu_stuff
+#define th_msg th_data
+
+/*
+ * Error codes.
+ */
+#define EUNDEF 0 /* not defined */
+#define ENOTFOUND 1 /* file not found */
+#define EACCESS 2 /* access violation */
+#define ENOSPACE 3 /* disk full or allocation exceeded */
+#define EBADOP 4 /* illegal TFTP operation */
+#define EBADID 5 /* unknown transfer ID */
+#define EEXISTS 6 /* file already exists */
+#define ENOUSER 7 /* no such user */
+#define EOPTNEG 8 /* option negotiation failed */
+
+#endif /* _ARPA_TFTP_H_ */
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
+/* $NetBSD: tftpsubs.c,v 1.8 2003/08/07 11:16:14 agc Exp $ */
+
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)tftpsubs.c 8.1 (Berkeley) 6/6/93";
+#else
+__RCSID("$NetBSD: tftpsubs.c,v 1.8 2003/08/07 11:16:14 agc Exp $");
+#endif
+#endif /* not lint */
/* Simple minded read-ahead/write-behind subroutines for tftp user and
server. Written originally with multiple buffers in mind, but current
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
-#include <arpa/tftp.h>
+#include "tftp.h"
#include <stdio.h>
#include <unistd.h>
#include "tftpsubs.h"
-#define PKTSIZE SEGSIZE+4 /* should be moved to tftp.h */
-
struct bf {
int counter; /* size of data in buffer, or flag */
- char buf[PKTSIZE]; /* room for data packet */
+ char buf[MAXPKTSIZE]; /* room for data packet */
} bfs[2];
/* Values for bf.counter */
int newline = 0; /* fillbuf: in middle of newline expansion */
int prevchar = -1; /* putbuf: previous char (cr check) */
-static struct tftphdr *rw_init();
+static struct tftphdr *rw_init __P((int));
-struct tftphdr *w_init() { return rw_init(0); } /* write-behind */
-struct tftphdr *r_init() { return rw_init(1); } /* read-ahead */
+struct tftphdr *
+w_init() /* write-behind */
+{
+ return rw_init(0);
+}
+
+struct tftphdr *
+r_init() /* read-ahead */
+{
+ return rw_init(1);
+}
static struct tftphdr *
rw_init(x) /* init for either read-ahead or write-behind */
return (struct tftphdr *)bfs[0].buf;
}
-
/* Have emptied current buffer by sending to net and getting ack.
Free it and return next buffer filled with data.
*/
int
-readit(file, dpp, convert)
+readit(file, dpp, amt, convert)
FILE *file; /* file opened for read */
struct tftphdr **dpp;
+ int amt;
int convert; /* if true, convert to ascii */
{
struct bf *b;
b = &bfs[current]; /* look at new buffer */
if (b->counter == BF_FREE) /* if it's empty */
- read_ahead(file, convert); /* fill it */
+ read_ahead(file, amt, convert); /* fill it */
/* assert(b->counter != BF_FREE);*//* check */
*dpp = (struct tftphdr *)b->buf; /* set caller's ptr */
return b->counter;
* conversions are lf -> cr,lf and cr -> cr, nul
*/
void
-read_ahead(file, convert)
+read_ahead(file, amt, convert)
FILE *file; /* file opened for read */
+ int amt; /* number of bytes to read */
int convert; /* if true, convert to ascii */
{
- register int i;
- register char *p;
- register int c;
+ int i;
+ char *p;
+ int c;
struct bf *b;
struct tftphdr *dp;
dp = (struct tftphdr *)b->buf;
if (convert == 0) {
- b->counter = read(fileno(file), dp->th_data, SEGSIZE);
+ b->counter = read(fileno(file), dp->th_data, amt);
return;
}
p = dp->th_data;
- for (i = 0 ; i < SEGSIZE; i++) {
+ for (i = 0 ; i < amt; i++) {
if (newline) {
if (prevchar == '\n')
c = '\n'; /* lf to cr,lf */
{
char *buf;
int count;
- register int ct;
- register char *p;
- register int c; /* current character */
+ int ct;
+ char *p;
+ int c; /* current character */
struct bf *b;
struct tftphdr *dp;
*/
int
-synchnet(f)
+synchnet(f, bsize)
int f; /* socket to flush */
+ int bsize; /* size of buffer to sync */
{
int i, j = 0;
char rbuf[PKTSIZE];
- struct sockaddr_in from;
+ struct sockaddr_storage from;
int fromlen;
while (1) {
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
+/* $NetBSD: tftpsubs.h,v 1.4 2003/08/07 11:16:14 agc Exp $ */
+
/*
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
* 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* Prototypes for read-ahead/write-behind subroutines for tftp user and
* server.
*/
+
+
struct tftphdr *r_init __P((void));
-void read_ahead __P((FILE *, int));
-int readit __P((FILE *, struct tftphdr **, int));
+void read_ahead __P((FILE *, int, int));
+int readit __P((FILE *, struct tftphdr **, int, int));
-int synchnet __P((int));
+int synchnet __P((int, int));
struct tftphdr *w_init __P((void));
int write_behind __P((FILE *, int));
PROJECTVERSION = 2.8
PROJECT_TYPE = Tool
-CFILES = tftpd.c
+HFILES = tftp.h tftpsubs.h
+CFILES = tftpd.c tftpsubs.c
-OTHERSRCS = Makefile.preamble Makefile Makefile.postamble tftpd.8
+OTHERSRCS = Makefile.preamble Makefile Makefile.postamble tftpd.8 tftp.plist tftp.plist-SERVER
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
PROF_LIBS = $(LIBS)
-HEADER_PATHS = -I../tftp.tproj
-
-
NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD
NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc
# owned by the top-level Makefile API and no context has been set up for where
# derived files should go.
-VPATH += :../tftp.tproj
-
after_install:
mkdir -p "$(DSTROOT)/usr/share/man/man8"
cp tftpd.8 "$(DSTROOT)/usr/share/man/man8/"
+ mkdir -p "$(DSTROOT)/System/Library/LaunchDaemons"
+ cp tftp.plist "$(DSTROOT)/System/Library/LaunchDaemons/"
+ cp tftp.plist-SERVER "$(DSTROOT)/System/Library/LaunchDaemons/"
+ mkdir -p "$(DSTROOT)/private/tftpboot/private"
+ ln -s / "$(DSTROOT)/private/tftpboot/private/tftpboot"
# Don't add more rules here unless you want the first one to be the default
# target for make! Put all your targets in Makefile.postamble.
-OTHER_OFILES = tftpsubs.o
-
-include ../Makefile.include
--- /dev/null
+/* $NetBSD: tftp.h,v 1.8 2003/08/07 09:44:12 agc Exp $ */
+
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tftp.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _ARPA_TFTP_H_
+#define _ARPA_TFTP_H_
+
+/*
+ * Trivial File Transfer Protocol (IEN-133)
+ */
+#define SEGSIZE 512 /* data segment size */
+#define MAXSEGSIZE 65464 /* maximum negotiated data segment size */
+
+#define PKTSIZE SEGSIZE + 4
+#define MAXPKTSIZE MAXSEGSIZE + 4
+
+/*
+ * Packet types.
+ */
+#define RRQ 01 /* read request */
+#define WRQ 02 /* write request */
+#define DATA 03 /* data packet */
+#define ACK 04 /* acknowledgement */
+#define ERROR 05 /* error code */
+#define OACK 06 /* option acknowledgement */
+
+struct tftphdr {
+ short th_opcode; /* packet type */
+ union {
+ unsigned short tu_block; /* block # */
+ short tu_code; /* error code */
+ char tu_stuff[1]; /* request packet stuff */
+ } th_u;
+ char th_data[1]; /* data or error string */
+};
+
+#define th_block th_u.tu_block
+#define th_code th_u.tu_code
+#define th_stuff th_u.tu_stuff
+#define th_msg th_data
+
+/*
+ * Error codes.
+ */
+#define EUNDEF 0 /* not defined */
+#define ENOTFOUND 1 /* file not found */
+#define EACCESS 2 /* access violation */
+#define ENOSPACE 3 /* disk full or allocation exceeded */
+#define EBADOP 4 /* illegal TFTP operation */
+#define EBADID 5 /* unknown transfer ID */
+#define EEXISTS 6 /* file already exists */
+#define ENOUSER 7 /* no such user */
+#define EOPTNEG 8 /* option negotiation failed */
+
+#endif /* _ARPA_TFTP_H_ */
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Disabled</key>
+ <true/>
+ <key>Label</key>
+ <string>com.apple.tftpd</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/libexec/tftpd</string>
+ <string>-s</string>
+ <string>/private/tftpboot</string>
+ </array>
+ <key>inetdCompatibility</key>
+ <dict>
+ <key>Wait</key>
+ <true/>
+ </dict>
+ <key>InitGroups</key>
+ <true/>
+ <key>Sockets</key>
+ <dict>
+ <key>Listeners</key>
+ <dict>
+ <key>SockServiceName</key>
+ <string>tftp</string>
+ <key>SockType</key>
+ <string>dgram</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Disabled</key>
+ <true/>
+ <key>Label</key>
+ <string>com.apple.tftpd</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/libexec/tftpd</string>
+ <string>-i</string>
+ <string>/private/tftpboot</string>
+ </array>
+ <key>inetdCompatibility</key>
+ <dict>
+ <key>Wait</key>
+ <true/>
+ </dict>
+ <key>InitGroups</key>
+ <true/>
+ <key>Sockets</key>
+ <dict>
+ <key>Listeners</key>
+ <dict>
+ <key>SockServiceName</key>
+ <string>tftp</string>
+ <key>SockType</key>
+ <string>dgram</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
+.\" $NetBSD: tftpd.8,v 1.21 2003/08/07 09:46:53 agc Exp $
+.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" 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 the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
+.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)tftpd.8 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/libexec/tftpd/tftpd.8,v 1.16 2002/07/06 19:19:43 charnier Exp $
+.\" from: @(#)tftpd.8 8.1 (Berkeley) 6/4/93
.\"
-.Dd September 14, 2000
+.Dd June 11, 2003
.Dt TFTPD 8
.Os
.Sh NAME
.Nm tftpd
-.Nd Internet Trivial File Transfer Protocol server
+.Nd
+.Tn DARPA
+Internet Trivial File Transfer Protocol server
.Sh SYNOPSIS
-.Nm /usr/libexec/tftpd
-.Op Fl cCln
+.Nm
+.Op Fl d
+.Op Fl g Ar group
+.Op Fl i
+.Op Fl l
+.Op Fl n
.Op Fl s Ar directory
.Op Fl u Ar user
.Op Ar directory ...
.Sh DESCRIPTION
-The
.Nm
-utility is a server which supports the
-Internet Trivial File Transfer
-Protocol
-.Pq Tn RFC 1350 .
+is a server which supports the
+.Tn DARPA
+Trivial File Transfer Protocol.
The
.Tn TFTP
-server operates
-at the port indicated in the
+server operates at the port indicated in the
.Ql tftp
-service description;
-see
+service description; see
.Xr services 5 .
The server is normally started by
.Xr inetd 8 .
does not require an account or password on the remote system.
Due to the lack of authentication information,
.Nm
-will allow only publicly readable files to be
-accessed.
-Files containing the string ``/\|\fB.\|.\fP\|/'' or starting with
-``\|\fB.\|.\fP\|/'' are not allowed.
-Files may be written only if they already exist and are publicly writable.
+will allow only publicly readable files to be accessed.
+Filenames beginning in ``\|\fB.\|.\fP\|/'' or
+containing ``/\|\fB.\|.\fP\|/'' are not allowed.
+Files may be written to only if they already exist and are publicly writable.
+.Pp
Note that this extends the concept of
-.Dq public
+.Qq public
to include
all users on all hosts that can be reached through the network;
this may not be appropriate on all systems, and its implications
The given directories are also treated as a search path for
relative filename requests.
.Pp
-The
-.Fl s
-option provides additional security by changing
-.Nm Ns No 's
-root directory, thereby prohibiting accesses outside of the specified
-.Ar directory .
-Because
-.Xr chroot 2
-requires super-user privileges,
-.Nm
-must be run as root.
-However, after performing the
-.Fn chroot ,
-.Nm
-will set its user id to that of the specified
-.Ar user ,
-or
-.Dq nobody
-if no
-.Fl u
-option is specified.
-.Pp
The options are:
-.Bl -tag -width Ds
-.It Fl c
-Changes the default root directory of a connecting host via chroot based on the
-connecting IP address.
-This prevents multiple clients from writing to the same file at the same time.
-If the directory does not exist, the client connection is refused.
-The
-.Fl s
-option is required for
-.Fl c
-and the specified
-.Ar directory
-is used as a base.
-.It Fl C
-Operates the same as
-.Fl c
-except it falls back to
-.Fl s Ns No 's
-.Ar directory
-if a directory does not exist for the client's IP.
+.Bl -tag -width "directory"
+.It Fl d
+Enable verbose debugging messages to
+.Xr syslogd 8 .
+.It Fl g Ar group
+Change gid to that of
+.Ar group
+on startup.
+If this isn't specified, the gid is set to that of the
+.Ar user
+specified with
+.Fl u .
+.It Fl i
+Enable insecure mode, no
+.Xr realpath 3 .
.It Fl l
-Log all requests using
-.Xr syslog 3
-with the facility of
-.Dv LOG_FTP .
-Note: Logging of
-.Dv LOG_FTP
-messages
-must also be enabled in the syslog configuration file,
-.Xr syslog.conf 5 .
+Logs all requests using
+.Xr syslog 3 .
.It Fl n
-Suppress negative acknowledgement of requests for nonexistent
+Suppresses negative acknowledgement of requests for nonexistent
relative filenames.
.It Fl s Ar directory
-Cause
-.Nm
-to change its root directory to
-.Pa directory .
-After changing roots but before accepting commands,
.Nm
-will switch credentials to an unprivileged user.
+will
+.Xr chroot 2
+to
+.Ar directory
+on startup.
+This is recommended for security reasons (so that files other than
+those in the
+.Pa /tftpboot
+directory aren't accessible).
+If the remote host passes the directory name as part of the
+file name to transfer, you may have to create a symbolic link
+from
+.Sq tftpboot
+to
+.Sq \&.
+under
+.Pa /tftpboot .
.It Fl u Ar user
-Switch credentials to
+Change uid to that of
.Ar user
-(default
-.Dq nobody )
-when the
-.Fl s
-option is used.
-The user must be specified by name, not a numeric UID.
+on startup.
+If
+.Fl u
+isn't given,
+.Ar user
+defaults to
+.Dq nobody .
+If
+.Fl g
+isn't also given, change the gid to that of
+.Ar user
+as well.
.El
.Sh SEE ALSO
.Xr tftp 1 ,
-.Xr chroot 2 ,
-.Xr inetd 8 ,
-.Xr syslogd 8
+.Xr inetd 8
.Rs
-.%A K. R. Sollins
-.%T The TFTP Protocol (Revision 2)
+.%R RFC
+.%N 1350
.%D July 1992
-.%O RFC 1350, STD 33
+.%T "The TFTP Protocol (Revision 2)"
+.Re
+.Rs
+.%R RFC
+.%N 2347
+.%D May 1998
+.%T "TFTP Option Extension"
+.Re
+.Rs
+.%R RFC
+.%N 2348
+.%D May 1998
+.%T "TFTP Blocksize Option"
+.Re
+.Rs
+.%R RFC
+.%N 2349
+.%D May 1998
+.%T "TFTP Timeout Interval and Transfer Size Options"
.Re
.Sh HISTORY
The
.Nm
-utility appeared in
-.Bx 4.2 ;
-the
+command appeared in
+.Bx 4.2 .
+.Pp
+The
.Fl s
-option was introduced in
-.Fx 2.2 ,
-the
+flag appeared in
+.Nx 1.0 .
+.Pp
+The
+.Fl g
+and
.Fl u
-option was introduced in
-.Fx 4.2 ,
-and the
-.Fl c
-option was introduced in
-.Fx 4.3 .
+flags appeared in
+.Nx 1.4 .
+.Pp
+IPv6 support was implemented by WIDE/KAME project in 1999.
+.Pp
+TFTP options were implemented by Wasabi Systems, Inc., in 2003,
+and first appeared in
+NetBSD 2.0 .
.Sh BUGS
Files larger than 33488896 octets (65535 blocks) cannot be transferred
-without client and server supporting blocksize negotiation (RFC1783).
+without client and server supporting blocksize negotiation (RFCs
+2347 and 2348).
.Pp
Many tftp clients will not transfer files over 16744448 octets (32767 blocks).
+.Sh SECURITY CONSIDERATIONS
+You are
+.Em strongly
+advised to set up
+.Nm
+using the
+.Fl s
+flag in conjunction with the name of the directory that
+contains the files that
+.Nm
+will serve to remote hosts (e.g.,
+.Pa /tftpboot ) .
+This ensures that only the files that should be served
+to remote hosts can be accessed by them.
+.Pp
+Because there is no user-login or validation within
+the
+.Tn TFTP
+protocol, the remote site will probably have some
+sort of file-access restrictions in place.
+The exact methods are specific to each site and therefore
+difficult to document here.
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/* $NetBSD: tftpd.c,v 1.28 2004/05/05 20:15:45 kleink Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1983, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
+__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
+ The Regents of the University of California. All rights reserved.\n");
#if 0
static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: tftpd.c,v 1.28 2004/05/05 20:15:45 kleink Exp $");
#endif
-static const char rcsid[] =
- "$FreeBSD: src/libexec/tftpd/tftpd.c,v 1.18 2001/02/02 10:52:58 asmodai Exp $";
#endif /* not lint */
/*
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/socket.h>
-#include <sys/types.h>
#include <netinet/in.h>
-#include <arpa/tftp.h>
+#include "tftp.h"
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
+#include <grp.h>
#include <netdb.h>
#include <pwd.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
+#include <time.h>
#include <unistd.h>
#include "tftpsubs.h"
+#define DEFAULTUSER "nobody"
+
#define TIMEOUT 5
int peer;
int rexmtval = TIMEOUT;
int maxtimeout = 5*TIMEOUT;
-#define PKTSIZE SEGSIZE+4
-char buf[PKTSIZE];
+char buf[MAXPKTSIZE];
char ackbuf[PKTSIZE];
-struct sockaddr_in from;
+char oackbuf[PKTSIZE];
+struct sockaddr_storage from;
int fromlen;
+int debug;
-void tftp __P((struct tftphdr *, int));
+int tftp_opt_tsize = 0;
+int tftp_blksize = SEGSIZE;
+int tftp_tsize = 0;
/*
* Null-terminated directory prefix list for absolute pathname requests and
} dirs[MAXDIRS+1];
static int suppress_naks;
static int logging;
-static int ipchroot;
+static int insecure=0;
+static int secure;
+static char *securedir;
-static char *errtomsg __P((int));
-static void nak __P((int));
-static char * __P(verifyhost(struct sockaddr_in *));
+struct formats;
+
+static const char *errtomsg(int);
+static void nak(int);
+static void tftp(struct tftphdr *, int);
+static void usage(void);
+static char *verifyhost(struct sockaddr *);
+void justquit(int);
+int main(int, char **);
+void recvfile(struct formats *, int, int);
+void sendfile(struct formats *, int, int);
+void timer(int);
+static const char *opcode(int);
+int validate_access(char **, int);
+
+struct formats {
+ const char *f_mode;
+ int (*f_validate)(char **, int);
+ void (*f_send)(struct formats *, int, int);
+ void (*f_recv)(struct formats *, int, int);
+ int f_convert;
+} formats[] = {
+ { "netascii", validate_access, sendfile, recvfile, 1 },
+ { "octet", validate_access, sendfile, recvfile, 0 },
+ { 0 }
+};
+
+static void
+usage(void)
+{
+
+ syslog(LOG_ERR,
+ "Usage: %s [-diln] [-u user] [-g group] [-s directory] [directory ...]",
+ getprogname());
+ exit(1);
+}
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
- register struct tftphdr *tp;
- register int n;
- int ch, on;
- struct sockaddr_in sin;
- char *chroot_dir = NULL;
- struct passwd *nobody;
- char *chuser = "nobody";
-
- openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
- while ((ch = getopt(argc, argv, "cClns:u:")) != -1) {
+ struct sockaddr_storage me;
+ struct passwd *pwent;
+ struct group *grent;
+ struct tftphdr *tp;
+ char *tgtuser, *tgtgroup, *ep;
+ int n, ch, on, fd;
+ int len, soopt;
+ uid_t curuid, tgtuid;
+ gid_t curgid, tgtgid;
+ long nid;
+
+ n = 0;
+ fd = 0;
+ tzset();
+ openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_DAEMON);
+ tgtuser = DEFAULTUSER;
+ tgtgroup = NULL;
+ curuid = getuid();
+ curgid = getgid();
+
+ while ((ch = getopt(argc, argv, "dg:ilns:u:")) != -1)
switch (ch) {
- case 'c':
- ipchroot = 1;
+ case 'd':
+ debug++;
break;
- case 'C':
- ipchroot = 2;
+
+ case 'g':
+ tgtgroup = optarg;
+ break;
+
+ case 'i':
+ insecure = 1;
break;
+
case 'l':
logging = 1;
break;
+
case 'n':
suppress_naks = 1;
break;
+
case 's':
- chroot_dir = optarg;
+ secure = 1;
+ securedir = optarg;
break;
+
case 'u':
- chuser = optarg;
+ tgtuser = optarg;
break;
+
default:
- syslog(LOG_WARNING, "ignoring unknown option -%c", ch);
+ usage();
+ break;
}
- }
+
if (optind < argc) {
struct dirlist *dirp;
}
}
}
- else if (chroot_dir) {
- dirs->name = "/";
- dirs->len = 1;
- }
- if (ipchroot && chroot_dir == NULL) {
- syslog(LOG_ERR, "-c requires -s");
+
+ if (*tgtuser == '\0' || (tgtgroup != NULL && *tgtgroup == '\0'))
+ usage();
+
+ nid = (strtol(tgtuser, &ep, 10));
+ if (*ep == '\0') {
+ if (nid > UID_MAX) {
+ syslog(LOG_ERR, "uid %ld is too large", nid);
+ exit(1);
+ }
+ pwent = getpwuid((uid_t)nid);
+ } else
+ pwent = getpwnam(tgtuser);
+ if (pwent == NULL) {
+ syslog(LOG_ERR, "unknown user `%s'", tgtuser);
exit(1);
}
+ tgtuid = pwent->pw_uid;
+ tgtgid = pwent->pw_gid;
+
+ if (tgtgroup != NULL) {
+ nid = (strtol(tgtgroup, &ep, 10));
+ if (*ep == '\0') {
+ if (nid > GID_MAX) {
+ syslog(LOG_ERR, "gid %ld is too large", nid);
+ exit(1);
+ }
+ grent = getgrgid((gid_t)nid);
+ } else
+ grent = getgrnam(tgtgroup);
+ if (grent != NULL)
+ tgtgid = grent->gr_gid;
+ else {
+ syslog(LOG_ERR, "unknown group `%s'", tgtgroup);
+ exit(1);
+ }
+ }
+
+ if (secure) {
+ if (chdir(securedir) < 0) {
+ syslog(LOG_ERR, "chdir %s: %m", securedir);
+ exit(1);
+ }
+ if (chroot(".")) {
+ syslog(LOG_ERR, "chroot: %m");
+ exit(1);
+ }
+ }
+
+ if (logging)
+ syslog(LOG_DEBUG, "running as user `%s' (%d), group `%s' (%d)",
+ tgtuser, tgtuid, tgtgroup ? tgtgroup : "(unspecified)",
+ tgtgid);
+ if (curgid != tgtgid) {
+ if (setgid(tgtgid)) {
+ syslog(LOG_ERR, "setgid to %d: %m", (int)tgtgid);
+ exit(1);
+ }
+ if (setgroups(0, NULL)) {
+ syslog(LOG_ERR, "setgroups: %m");
+ exit(1);
+ }
+ }
+
+ if (curuid != tgtuid) {
+ if (setuid(tgtuid)) {
+ syslog(LOG_ERR, "setuid to %d: %m", (int)tgtuid);
+ exit(1);
+ }
+ }
on = 1;
- if (ioctl(0, FIONBIO, &on) < 0) {
+ if (ioctl(fd, FIONBIO, &on) < 0) {
syslog(LOG_ERR, "ioctl(FIONBIO): %m");
exit(1);
}
fromlen = sizeof (from);
- n = recvfrom(0, buf, sizeof (buf), 0,
+ n = recvfrom(fd, buf, sizeof (buf), 0,
(struct sockaddr *)&from, &fromlen);
if (n < 0) {
syslog(LOG_ERR, "recvfrom: %m");
* a single request from a single client.
*/
j = sizeof from;
- i = recvfrom(0, buf, sizeof (buf), 0,
+ i = recvfrom(fd, buf, sizeof (buf), 0,
(struct sockaddr *)&from, &j);
if (i > 0) {
n = i;
}
/*
- * Since we exit here, we should do that only after the above
- * recvfrom to keep inetd from constantly forking should there
- * be a problem. See the above comment about system clogging.
+ * remember what address this was sent to, so we can respond on the
+ * same interface
*/
- if (chroot_dir) {
- if (ipchroot) {
- char tempchroot[MAXPATHLEN];
- char *tempaddr;
- struct stat sb;
- int statret;
-
- tempaddr = inet_ntoa(from.sin_addr);
- snprintf(tempchroot, sizeof(tempchroot), "%s/%s", chroot_dir, tempaddr);
- statret = stat(tempchroot, &sb);
- if ((sb.st_mode & S_IFDIR) &&
- (statret == 0 || (statret == -1 && ipchroot == 1)))
- chroot_dir = tempchroot;
- }
- /* Must get this before chroot because /etc might go away */
- if ((nobody = getpwnam(chuser)) == NULL) {
- syslog(LOG_ERR, "%s: no such user", chuser);
- exit(1);
- }
- if (chroot(chroot_dir)) {
- syslog(LOG_ERR, "chroot: %s: %m", chroot_dir);
- exit(1);
+ len = sizeof(me);
+ if (getsockname(fd, (struct sockaddr *)&me, &len) == 0) {
+ switch (me.ss_family) {
+ case AF_INET:
+ ((struct sockaddr_in *)&me)->sin_port = 0;
+ break;
+ case AF_INET6:
+ ((struct sockaddr_in6 *)&me)->sin6_port = 0;
+ break;
+ default:
+ /* unsupported */
+ break;
}
- chdir( "/" );
- setuid(nobody->pw_uid);
+ } else {
+ memset(&me, 0, sizeof(me));
+ me.ss_family = from.ss_family;
+ me.ss_len = from.ss_len;
}
- from.sin_family = AF_INET;
alarm(0);
- close(0);
+ close(fd);
close(1);
- peer = socket(AF_INET, SOCK_DGRAM, 0);
+ peer = socket(from.ss_family, SOCK_DGRAM, 0);
if (peer < 0) {
syslog(LOG_ERR, "socket: %m");
exit(1);
}
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- if (bind(peer, (struct sockaddr *)&sin, sizeof (sin)) < 0) {
+ if (bind(peer, (struct sockaddr *)&me, me.ss_len) < 0) {
syslog(LOG_ERR, "bind: %m");
exit(1);
}
- if (connect(peer, (struct sockaddr *)&from, sizeof(from)) < 0) {
+ if (connect(peer, (struct sockaddr *)&from, from.ss_len) < 0) {
syslog(LOG_ERR, "connect: %m");
exit(1);
}
+ soopt = 65536; /* larger than we'll ever need */
+ if (setsockopt(peer, SOL_SOCKET, SO_SNDBUF, (void *) &soopt, sizeof(soopt)) < 0) {
+ syslog(LOG_ERR, "set SNDBUF: %m");
+ exit(1);
+ }
+ if (setsockopt(peer, SOL_SOCKET, SO_RCVBUF, (void *) &soopt, sizeof(soopt)) < 0) {
+ syslog(LOG_ERR, "set RCVBUF: %m");
+ exit(1);
+ }
+
tp = (struct tftphdr *)buf;
tp->th_opcode = ntohs(tp->th_opcode);
if (tp->th_opcode == RRQ || tp->th_opcode == WRQ)
exit(1);
}
-struct formats;
-int validate_access __P((char **, int));
-void xmitfile __P((struct formats *));
-void recvfile __P((struct formats *));
+static int
+blk_handler(struct tftphdr *tp, char *opt, char *val, char *ack,
+ int *ackl, int *ec)
+{
+ unsigned long bsize;
+ char *endp;
+ int l;
-struct formats {
- char *f_mode;
- int (*f_validate) __P((char **, int));
- void (*f_send) __P((struct formats *));
- void (*f_recv) __P((struct formats *));
- int f_convert;
-} formats[] = {
- { "netascii", validate_access, xmitfile, recvfile, 1 },
- { "octet", validate_access, xmitfile, recvfile, 0 },
-#ifdef notdef
- { "mail", validate_user, sendmail, recvmail, 1 },
-#endif
- { 0 }
+ /*
+ * On these failures, we could just ignore the blocksize option.
+ * Perhaps that should be a command-line option.
+ */
+ errno = 0;
+ bsize = strtoul(val, &endp, 10);
+ if ((bsize == ULONG_MAX && errno == ERANGE) || *endp) {
+ syslog(LOG_NOTICE, "%s: %s request for %s: "
+ "illegal value %s for blksize option",
+ verifyhost((struct sockaddr *)&from),
+ tp->th_opcode == WRQ ? "write" : "read",
+ tp->th_stuff, val);
+ return 0;
+ }
+ if (bsize < 8 || bsize > 65464) {
+ syslog(LOG_NOTICE, "%s: %s request for %s: "
+ "out of range value %s for blksize option",
+ verifyhost((struct sockaddr *)&from),
+ tp->th_opcode == WRQ ? "write" : "read",
+ tp->th_stuff, val);
+ return 0;
+ }
+
+ tftp_blksize = bsize;
+ strcpy(ack + *ackl, "blksize");
+ *ackl += 8;
+ l = sprintf(ack + *ackl, "%lu", bsize);
+ *ackl += l + 1;
+
+ return 0;
+}
+
+static int
+timeout_handler(struct tftphdr *tp, char *opt, char *val, char *ack,
+ int *ackl, int *ec)
+{
+ unsigned long tout;
+ char *endp;
+ int l;
+
+ errno = 0;
+ tout = strtoul(val, &endp, 10);
+ if ((tout == ULONG_MAX && errno == ERANGE) || *endp) {
+ syslog(LOG_NOTICE, "%s: %s request for %s: "
+ "illegal value %s for timeout option",
+ verifyhost((struct sockaddr *)&from),
+ tp->th_opcode == WRQ ? "write" : "read",
+ tp->th_stuff, val);
+ return 0;
+ }
+ if (tout < 1 || tout > 255) {
+ syslog(LOG_NOTICE, "%s: %s request for %s: "
+ "out of range value %s for timeout option",
+ verifyhost((struct sockaddr *)&from),
+ tp->th_opcode == WRQ ? "write" : "read",
+ tp->th_stuff, val);
+ return 0;
+ }
+
+ rexmtval = tout;
+ strcpy(ack + *ackl, "timeout");
+ *ackl += 8;
+ l = sprintf(ack + *ackl, "%lu", tout);
+ *ackl += l + 1;
+
+ /*
+ * Arbitrarily pick a maximum timeout on a request to 3
+ * retransmissions if the interval timeout is more than
+ * one minute. Longest possible timeout is therefore
+ * 3 * 255 - 1, or 764 seconds.
+ */
+ if (rexmtval > 60) {
+ maxtimeout = rexmtval * 3;
+ } else {
+ maxtimeout = rexmtval * 5;
+ }
+
+ return 0;
+}
+
+static int
+tsize_handler(struct tftphdr *tp, char *opt, char *val, char *ack,
+ int *ackl, int *ec)
+{
+ unsigned long fsize;
+ char *endp;
+
+ /*
+ * Maximum file even with extended tftp is 65535 blocks of
+ * length 65464, or 4290183240 octets (4784056 less than 2^32).
+ * unsigned long is at least 32 bits on all NetBSD archs.
+ */
+
+ errno = 0;
+ fsize = strtoul(val, &endp, 10);
+ if ((fsize == ULONG_MAX && errno == ERANGE) || *endp) {
+ syslog(LOG_NOTICE, "%s: %s request for %s: "
+ "illegal value %s for tsize option",
+ verifyhost((struct sockaddr *)&from),
+ tp->th_opcode == WRQ ? "write" : "read",
+ tp->th_stuff, val);
+ return 0;
+ }
+ if (fsize > (unsigned long) 65535 * 65464) {
+ syslog(LOG_NOTICE, "%s: %s request for %s: "
+ "out of range value %s for tsize option",
+ verifyhost((struct sockaddr *)&from),
+ tp->th_opcode == WRQ ? "write" : "read",
+ tp->th_stuff, val);
+ return 0;
+ }
+
+ tftp_opt_tsize = 1;
+ tftp_tsize = fsize;
+ /*
+ * We will report this later -- either replying with the fsize (WRQ)
+ * or replying with the actual filesize (RRQ).
+ */
+
+ return 0;
+}
+
+struct tftp_options {
+ char *o_name;
+ int (*o_handler)(struct tftphdr *, char *, char *, char *,
+ int *, int *);
+} options[] = {
+ { "blksize", blk_handler },
+ { "timeout", timeout_handler },
+ { "tsize", tsize_handler },
+ { NULL, NULL }
};
+/*
+ * Get options for an extended tftp session. Stuff the ones we
+ * recognize in oackbuf.
+ */
+static int
+get_options(struct tftphdr *tp, char *cp, int size, char *ackb,
+ int *alen, int *err)
+{
+ struct tftp_options *op;
+ char *option, *value, *endp;
+ int r, rv=0, ec=0;
+
+ endp = cp + size;
+ while (cp < endp) {
+ option = cp;
+ while (*cp && cp < endp) {
+ *cp = tolower(*cp);
+ cp++;
+ }
+ if (*cp) {
+ /* if we have garbage at the end, just ignore it */
+ break;
+ }
+ cp++; /* skip over NUL */
+ value = cp;
+ while (*cp && cp < endp) {
+ cp++;
+ }
+ if (*cp) {
+ /* if we have garbage at the end, just ignore it */
+ break;
+ }
+ cp++;
+ for (op = options; op->o_name; op++) {
+ if (strcmp(op->o_name, option) == 0)
+ break;
+ }
+ if (op->o_name) {
+ r = op->o_handler(tp, option, value, ackb, alen, &ec);
+ if (r < 0) {
+ rv = -1;
+ break;
+ }
+ rv++;
+ } /* else ignore unknown options */
+ }
+
+ if (rv < 0)
+ *err = ec;
+
+ return rv;
+}
+
/*
* Handle initial connection protocol.
*/
-void
-tftp(tp, size)
- struct tftphdr *tp;
- int size;
+static void
+tftp(struct tftphdr *tp, int size)
{
- register char *cp;
- int first = 1, ecode;
- register struct formats *pf;
- char *filename, *mode;
+ struct formats *pf;
+ char *cp;
+ char *filename, *mode;
+ int first, ecode, alen, etftp=0, r;
+
+ first = 1;
+ mode = NULL;
filename = cp = tp->th_stuff;
again:
nak(EBADOP);
exit(1);
}
+ /*
+ * cp currently points to the NUL byte following the mode.
+ *
+ * If we have some valid options, then let's assume that we're
+ * now dealing with an extended tftp session. Note that if we
+ * don't get any options, then we *must* assume that we do not
+ * have an extended tftp session. If we get options, we fill
+ * in the ack buf to acknowledge them. If we skip that, then
+ * the client *must* assume that we are not using an extended
+ * session.
+ */
+ size -= (++cp - (char *) tp);
+ if (size > 0 && *cp) {
+ alen = 2; /* Skip over opcode */
+ r = get_options(tp, cp, size, oackbuf, &alen, &ecode);
+ if (r > 0) {
+ etftp = 1;
+ } else if (r < 0) {
+ nak(ecode);
+ exit(1);
+ }
+ }
ecode = (*pf->f_validate)(&filename, tp->th_opcode);
if (logging) {
- syslog(LOG_INFO, "%s: %s request for %s: %s", verifyhost(&from),
+ syslog(LOG_INFO, "%s: %s request for %s: %s",
+ verifyhost((struct sockaddr *)&from),
tp->th_opcode == WRQ ? "write" : "read",
filename, errtomsg(ecode));
}
nak(ecode);
exit(1);
}
+
+ if (etftp) {
+ struct tftphdr *oack_h;
+
+ if (tftp_opt_tsize) {
+ int l;
+
+ strcpy(oackbuf + alen, "tsize");
+ alen += 6;
+ l = sprintf(oackbuf + alen, "%u", tftp_tsize);
+ alen += l + 1;
+ }
+ oack_h = (struct tftphdr *) oackbuf;
+ oack_h->th_opcode = htons(OACK);
+ }
+
if (tp->th_opcode == WRQ)
- (*pf->f_recv)(pf);
+ (*pf->f_recv)(pf, etftp, alen);
else
- (*pf->f_send)(pf);
+ (*pf->f_send)(pf, etftp, alen);
exit(0);
}
* If we were invoked with arguments
* from inetd then the file must also be
* in one of the given directory prefixes.
- * Note also, full path name must be
- * given as we have no login directory.
*/
int
-validate_access(filep, mode)
- char **filep;
- int mode;
+validate_access(char **filep, int mode)
{
- struct stat stbuf;
- int fd;
- struct dirlist *dirp;
- static char pathname[MAXPATHLEN];
- char *filename = *filep;
-
+ struct stat stbuf;
+ struct dirlist *dirp;
+ static char pathname[MAXPATHLEN];
+ int fd;
+ char *filename;
+#ifdef __APPLE__
+ static char resolved_path[PATH_MAX+1];
+ bzero(resolved_path,PATH_MAX+1);
+ if(insecure) {
+ filename = *filep;
+ } else {
+ if (realpath(*filep, resolved_path)==NULL) {
+ return (EACCESS);
+ }
+ filename = resolved_path;
+ }
+#else
+ filename = *filep;
+#endif
/*
* Prevent tricksters from getting around the directory restrictions
*/
return (EACCESS);
if (stat(filename, &stbuf) < 0)
return (errno == ENOENT ? ENOTFOUND : EACCESS);
- if ((stbuf.st_mode & S_IFMT) != S_IFREG)
+ if (!S_ISREG(stbuf.st_mode))
return (ENOTFOUND);
if (mode == RRQ) {
if ((stbuf.st_mode & S_IROTH) == 0)
return (EACCESS);
}
} else {
- int err;
-
/*
* Relative file name: search the approved locations for it.
- * Don't allow write requests that avoid directory
- * restrictions.
*/
if (!strncmp(filename, "../", 3))
return (EACCESS);
/*
- * If the file exists in one of the directories and isn't
- * readable, continue looking. However, change the error code
- * to give an indication that the file exists.
+ * Find the first file that exists in any of the directories,
+ * check access on it.
*/
- err = ENOTFOUND;
- for (dirp = dirs; dirp->name != NULL; dirp++) {
- snprintf(pathname, sizeof(pathname), "%s/%s",
- dirp->name, filename);
- if (stat(pathname, &stbuf) == 0 &&
- (stbuf.st_mode & S_IFMT) == S_IFREG) {
- if ((stbuf.st_mode & S_IROTH) != 0) {
+ if (dirs[0].name != NULL) {
+ for (dirp = dirs; dirp->name != NULL; dirp++) {
+ snprintf(pathname, sizeof pathname, "%s/%s",
+ dirp->name, filename);
+ if (stat(pathname, &stbuf) == 0 &&
+ (stbuf.st_mode & S_IFMT) == S_IFREG) {
break;
}
- err = EACCESS;
}
+ if (dirp->name == NULL)
+ return (ENOTFOUND);
+ if (mode == RRQ && !(stbuf.st_mode & S_IROTH))
+ return (EACCESS);
+ if (mode == WRQ && !(stbuf.st_mode & S_IWOTH))
+ return (EACCESS);
+ filename = pathname;
+ *filep = filename;
+ } else {
+ /*
+ * If there's no directory list, take our cue from the
+ * absolute file request check above (*filename == '/'),
+ * and allow access to anything.
+ */
+ if (stat(filename, &stbuf) < 0)
+ return (errno == ENOENT ? ENOTFOUND : EACCESS);
+ if (!S_ISREG(stbuf.st_mode))
+ return (ENOTFOUND);
+ if (mode == RRQ) {
+ if ((stbuf.st_mode & S_IROTH) == 0)
+ return (EACCESS);
+ } else {
+ if ((stbuf.st_mode & S_IWOTH) == 0)
+ return (EACCESS);
+ }
+ *filep = filename;
}
- if (dirp->name == NULL)
- return (err);
- *filep = filename = pathname;
}
- fd = open(filename, mode == RRQ ? O_RDONLY : O_WRONLY|O_TRUNC);
+
+ if (tftp_opt_tsize && mode == RRQ)
+ tftp_tsize = (unsigned long) stbuf.st_size;
+
+ fd = open(filename, mode == RRQ ? O_RDONLY : O_WRONLY | O_TRUNC);
if (fd < 0)
return (errno + 100);
file = fdopen(fd, (mode == RRQ)? "r":"w");
if (file == NULL) {
- return errno+100;
+ close(fd);
+ return (errno + 100);
}
return (0);
}
jmp_buf timeoutbuf;
void
-timer()
+timer(int dummy)
{
timeout += rexmtval;
longjmp(timeoutbuf, 1);
}
+static const char *
+opcode(int code)
+{
+ static char buf[64];
+
+ switch (code) {
+ case RRQ:
+ return "RRQ";
+ case WRQ:
+ return "WRQ";
+ case DATA:
+ return "DATA";
+ case ACK:
+ return "ACK";
+ case ERROR:
+ return "ERROR";
+ case OACK:
+ return "OACK";
+ default:
+ (void)snprintf(buf, sizeof(buf), "*code %d*", code);
+ return buf;
+ }
+}
+
/*
* Send the requested file.
*/
void
-xmitfile(pf)
- struct formats *pf;
+sendfile(struct formats *pf, int etftp, int acklength)
{
- struct tftphdr *dp, *r_init();
- register struct tftphdr *ap; /* ack packet */
- register int size, n;
- volatile unsigned short block;
+ volatile unsigned int block;
+ struct tftphdr *dp;
+ struct tftphdr *ap; /* ack packet */
+ int size, n;
signal(SIGALRM, timer);
- dp = r_init();
ap = (struct tftphdr *)ackbuf;
- block = 1;
+ if (etftp) {
+ dp = (struct tftphdr *)oackbuf;
+ size = acklength - 4;
+ block = 0;
+ } else {
+ dp = r_init();
+ size = 0;
+ block = 1;
+ }
+
do {
- size = readit(file, &dp, pf->f_convert);
- if (size < 0) {
- nak(errno + 100);
- goto abort;
+ if (block > 0) {
+ size = readit(file, &dp, tftp_blksize, pf->f_convert);
+ if (size < 0) {
+ nak(errno + 100);
+ goto abort;
+ }
+ dp->th_opcode = htons((u_short)DATA);
+ dp->th_block = htons((u_short)block);
}
- dp->th_opcode = htons((u_short)DATA);
- dp->th_block = htons((u_short)block);
timeout = 0;
(void)setjmp(timeoutbuf);
send_data:
- if (send(peer, dp, size + 4, 0) != size + 4) {
- syslog(LOG_ERR, "write: %m");
+ if (!etftp && debug)
+ syslog(LOG_DEBUG, "Send DATA %u", block);
+ if ((n = send(peer, dp, size + 4, 0)) != size + 4) {
+ syslog(LOG_ERR, "tftpd: write: %m");
goto abort;
}
- read_ahead(file, pf->f_convert);
+ if (block)
+ read_ahead(file, tftp_blksize, pf->f_convert);
for ( ; ; ) {
alarm(rexmtval); /* read the ack */
- n = recv(peer, ackbuf, sizeof (ackbuf), 0);
+ n = recv(peer, ackbuf, tftp_blksize, 0);
alarm(0);
if (n < 0) {
- syslog(LOG_ERR, "read: %m");
+ syslog(LOG_ERR, "tftpd: read: %m");
goto abort;
}
ap->th_opcode = ntohs((u_short)ap->th_opcode);
ap->th_block = ntohs((u_short)ap->th_block);
-
- if (ap->th_opcode == ERROR)
+ switch (ap->th_opcode) {
+ case ERROR:
goto abort;
- if (ap->th_opcode == ACK) {
+ case ACK:
+ if (ap->th_block == 0) {
+ etftp = 0;
+ acklength = 0;
+ dp = r_init();
+ goto done;
+ }
if (ap->th_block == block)
- break;
+ goto done;
+ if (debug)
+ syslog(LOG_DEBUG, "Resync ACK %u != %u",
+ (unsigned int)ap->th_block, block);
/* Re-synchronize with the other side */
- (void) synchnet(peer);
+ (void) synchnet(peer, tftp_blksize);
if (ap->th_block == (block -1))
goto send_data;
+ default:
+ syslog(LOG_INFO, "Received %s in sendfile\n",
+ opcode(dp->th_opcode));
}
}
+done:
+ if (debug)
+ syslog(LOG_DEBUG, "Received ACK for block %u", block);
block++;
- } while (size == SEGSIZE);
+ } while (size == tftp_blksize || block == 1);
abort:
(void) fclose(file);
}
void
-justquit()
+justquit(int dummy)
{
+
exit(0);
}
-
/*
* Receive a file.
*/
void
-recvfile(pf)
- struct formats *pf;
+recvfile(struct formats *pf, int etftp, int acklength)
{
- struct tftphdr *dp, *w_init();
- register struct tftphdr *ap; /* ack buffer */
- register int n, size;
- volatile unsigned short block;
+ volatile unsigned int block;
+ struct tftphdr *dp;
+ struct tftphdr *ap; /* ack buffer */
+ int n, size;
signal(SIGALRM, timer);
dp = w_init();
- ap = (struct tftphdr *)ackbuf;
+ ap = (struct tftphdr *)oackbuf;
block = 0;
do {
timeout = 0;
- ap->th_opcode = htons((u_short)ACK);
- ap->th_block = htons((u_short)block);
+ if (etftp == 0) {
+ ap = (struct tftphdr *)ackbuf;
+ ap->th_opcode = htons((u_short)ACK);
+ ap->th_block = htons((u_short)block);
+ acklength = 4;
+ }
+ if (debug)
+ syslog(LOG_DEBUG, "Sending ACK for block %u\n", block);
block++;
(void) setjmp(timeoutbuf);
send_ack:
- if (send(peer, ackbuf, 4, 0) != 4) {
- syslog(LOG_ERR, "write: %m");
+ if (send(peer, ap, acklength, 0) != acklength) {
+ syslog(LOG_ERR, "tftpd: write: %m");
goto abort;
}
write_behind(file, pf->f_convert);
for ( ; ; ) {
alarm(rexmtval);
- n = recv(peer, dp, PKTSIZE, 0);
+ n = recv(peer, dp, tftp_blksize + 4, 0);
alarm(0);
if (n < 0) { /* really? */
- syslog(LOG_ERR, "read: %m");
+ syslog(LOG_ERR, "tftpd: read: %m");
goto abort;
}
+ etftp = 0;
dp->th_opcode = ntohs((u_short)dp->th_opcode);
dp->th_block = ntohs((u_short)dp->th_block);
- if (dp->th_opcode == ERROR)
+ if (debug)
+ syslog(LOG_DEBUG, "Received %s for block %u",
+ opcode(dp->th_opcode),
+ (unsigned int)dp->th_block);
+
+ switch (dp->th_opcode) {
+ case ERROR:
goto abort;
- if (dp->th_opcode == DATA) {
- if (dp->th_block == block) {
- break; /* normal */
- }
+ case DATA:
+ if (dp->th_block == block)
+ goto done; /* normal */
+ if (debug)
+ syslog(LOG_DEBUG, "Resync %u != %u",
+ (unsigned int)dp->th_block, block);
/* Re-synchronize with the other side */
- (void) synchnet(peer);
+ (void) synchnet(peer, tftp_blksize);
if (dp->th_block == (block-1))
goto send_ack; /* rexmit */
+ break;
+ default:
+ syslog(LOG_INFO, "Received %s in recvfile\n",
+ opcode(dp->th_opcode));
+ break;
}
}
+done:
+ if (debug)
+ syslog(LOG_DEBUG, "Got block %u", block);
/* size = write(file, dp->th_data, n - 4); */
size = writeit(file, &dp, n - 4, pf->f_convert);
if (size != (n-4)) { /* ahem */
else nak(ENOSPACE);
goto abort;
}
- } while (size == SEGSIZE);
+ } while (size == tftp_blksize);
write_behind(file, pf->f_convert);
(void) fclose(file); /* close data file */
ap->th_opcode = htons((u_short)ACK); /* send the "final" ack */
ap->th_block = htons((u_short)(block));
+ if (debug)
+ syslog(LOG_DEBUG, "Send final ACK %u", block);
(void) send(peer, ackbuf, 4, 0);
signal(SIGALRM, justquit); /* just quit on timeout */
return;
}
-struct errmsg {
- int e_code;
- char *e_msg;
+const struct errmsg {
+ int e_code;
+ const char *e_msg;
} errmsgs[] = {
{ EUNDEF, "Undefined error code" },
{ ENOTFOUND, "File not found" },
{ EBADID, "Unknown transfer ID" },
{ EEXISTS, "File already exists" },
{ ENOUSER, "No such user" },
+ { EOPTNEG, "Option negotiation failed" },
{ -1, 0 }
};
-static char *
-errtomsg(error)
- int error;
+static const char *
+errtomsg(int error)
{
- static char buf[20];
- register struct errmsg *pe;
+ static char ebuf[20];
+ const struct errmsg *pe;
+
if (error == 0)
- return "success";
+ return ("success");
for (pe = errmsgs; pe->e_code >= 0; pe++)
if (pe->e_code == error)
- return pe->e_msg;
- snprintf(buf, sizeof(buf), "error %d", error);
- return buf;
+ return (pe->e_msg);
+ snprintf(ebuf, sizeof(ebuf), "error %d", error);
+ return (ebuf);
}
/*
* offset by 100.
*/
static void
-nak(error)
- int error;
+nak(int error)
{
- register struct tftphdr *tp;
- int length;
- register struct errmsg *pe;
+ const struct errmsg *pe;
+ struct tftphdr *tp;
+ int length;
+ size_t msglen;
tp = (struct tftphdr *)buf;
tp->th_opcode = htons((u_short)ERROR);
- tp->th_code = htons((u_short)error);
+ msglen = sizeof(buf) - (&tp->th_msg[0] - buf);
for (pe = errmsgs; pe->e_code >= 0; pe++)
if (pe->e_code == error)
break;
if (pe->e_code < 0) {
- pe->e_msg = strerror(error - 100);
tp->th_code = EUNDEF; /* set 'undef' errorcode */
+ strlcpy(tp->th_msg, strerror(error - 100), msglen);
+ } else {
+ tp->th_code = htons((u_short)error);
+ strlcpy(tp->th_msg, pe->e_msg, msglen);
}
- strcpy(tp->th_msg, pe->e_msg);
- length = strlen(pe->e_msg);
- tp->th_msg[length] = '\0';
- length += 5;
- if (send(peer, buf, length, 0) != length)
+ if (debug)
+ syslog(LOG_DEBUG, "Send NACK %s", tp->th_msg);
+ length = strlen(tp->th_msg);
+ msglen = &tp->th_msg[length + 1] - buf;
+ if (send(peer, buf, msglen, 0) != msglen)
syslog(LOG_ERR, "nak: %m");
}
static char *
-verifyhost(fromp)
- struct sockaddr_in *fromp;
+verifyhost(struct sockaddr *fromp)
{
- struct hostent *hp;
+ static char hbuf[MAXHOSTNAMELEN];
- hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof(fromp->sin_addr),
- fromp->sin_family);
- if(hp)
- return hp->h_name;
- else
- return inet_ntoa(fromp->sin_addr);
+ if (getnameinfo(fromp, fromp->sa_len, hbuf, sizeof(hbuf), NULL, 0, 0))
+ strlcpy(hbuf, "?", sizeof(hbuf));
+ return (hbuf);
}
--- /dev/null
+/* $NetBSD: tftpsubs.c,v 1.8 2003/08/07 11:16:14 agc Exp $ */
+
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)tftpsubs.c 8.1 (Berkeley) 6/6/93";
+#else
+__RCSID("$NetBSD: tftpsubs.c,v 1.8 2003/08/07 11:16:14 agc Exp $");
+#endif
+#endif /* not lint */
+
+/* Simple minded read-ahead/write-behind subroutines for tftp user and
+ server. Written originally with multiple buffers in mind, but current
+ implementation has two buffer logic wired in.
+
+ Todo: add some sort of final error check so when the write-buffer
+ is finally flushed, the caller can detect if the disk filled up
+ (or had an i/o error) and return a nak to the other side.
+
+ Jim Guyton 10/85
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include "tftp.h"
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include "tftpsubs.h"
+
+struct bf {
+ int counter; /* size of data in buffer, or flag */
+ char buf[MAXPKTSIZE]; /* room for data packet */
+} bfs[2];
+
+ /* Values for bf.counter */
+#define BF_ALLOC -3 /* alloc'd but not yet filled */
+#define BF_FREE -2 /* free */
+/* [-1 .. SEGSIZE] = size of data in the data buffer */
+
+static int nextone; /* index of next buffer to use */
+static int current; /* index of buffer in use */
+
+ /* control flags for crlf conversions */
+int newline = 0; /* fillbuf: in middle of newline expansion */
+int prevchar = -1; /* putbuf: previous char (cr check) */
+
+static struct tftphdr *rw_init __P((int));
+
+struct tftphdr *
+w_init() /* write-behind */
+{
+ return rw_init(0);
+}
+
+struct tftphdr *
+r_init() /* read-ahead */
+{
+ return rw_init(1);
+}
+
+static struct tftphdr *
+rw_init(x) /* init for either read-ahead or write-behind */
+ int x; /* zero for write-behind, one for read-head */
+{
+ newline = 0; /* init crlf flag */
+ prevchar = -1;
+ bfs[0].counter = BF_ALLOC; /* pass out the first buffer */
+ current = 0;
+ bfs[1].counter = BF_FREE;
+ nextone = x; /* ahead or behind? */
+ return (struct tftphdr *)bfs[0].buf;
+}
+
+/* Have emptied current buffer by sending to net and getting ack.
+ Free it and return next buffer filled with data.
+ */
+int
+readit(file, dpp, amt, convert)
+ FILE *file; /* file opened for read */
+ struct tftphdr **dpp;
+ int amt;
+ int convert; /* if true, convert to ascii */
+{
+ struct bf *b;
+
+ bfs[current].counter = BF_FREE; /* free old one */
+ current = !current; /* "incr" current */
+
+ b = &bfs[current]; /* look at new buffer */
+ if (b->counter == BF_FREE) /* if it's empty */
+ read_ahead(file, amt, convert); /* fill it */
+/* assert(b->counter != BF_FREE);*//* check */
+ *dpp = (struct tftphdr *)b->buf; /* set caller's ptr */
+ return b->counter;
+}
+
+/*
+ * fill the input buffer, doing ascii conversions if requested
+ * conversions are lf -> cr,lf and cr -> cr, nul
+ */
+void
+read_ahead(file, amt, convert)
+ FILE *file; /* file opened for read */
+ int amt; /* number of bytes to read */
+ int convert; /* if true, convert to ascii */
+{
+ int i;
+ char *p;
+ int c;
+ struct bf *b;
+ struct tftphdr *dp;
+
+ b = &bfs[nextone]; /* look at "next" buffer */
+ if (b->counter != BF_FREE) /* nop if not free */
+ return;
+ nextone = !nextone; /* "incr" next buffer ptr */
+
+ dp = (struct tftphdr *)b->buf;
+
+ if (convert == 0) {
+ b->counter = read(fileno(file), dp->th_data, amt);
+ return;
+ }
+
+ p = dp->th_data;
+ for (i = 0 ; i < amt; i++) {
+ if (newline) {
+ if (prevchar == '\n')
+ c = '\n'; /* lf to cr,lf */
+ else c = '\0'; /* cr to cr,nul */
+ newline = 0;
+ }
+ else {
+ c = getc(file);
+ if (c == EOF) break;
+ if (c == '\n' || c == '\r') {
+ prevchar = c;
+ c = '\r';
+ newline = 1;
+ }
+ }
+ *p++ = c;
+ }
+ b->counter = (int)(p - dp->th_data);
+}
+
+/* Update count associated with the buffer, get new buffer
+ from the queue. Calls write_behind only if next buffer not
+ available.
+ */
+int
+writeit(file, dpp, ct, convert)
+ FILE *file;
+ struct tftphdr **dpp;
+ int ct, convert;
+{
+ bfs[current].counter = ct; /* set size of data to write */
+ current = !current; /* switch to other buffer */
+ if (bfs[current].counter != BF_FREE) /* if not free */
+ (void)write_behind(file, convert); /* flush it */
+ bfs[current].counter = BF_ALLOC; /* mark as alloc'd */
+ *dpp = (struct tftphdr *)bfs[current].buf;
+ return ct; /* this is a lie of course */
+}
+
+/*
+ * Output a buffer to a file, converting from netascii if requested.
+ * CR,NUL -> CR and CR,LF => LF.
+ * Note spec is undefined if we get CR as last byte of file or a
+ * CR followed by anything else. In this case we leave it alone.
+ */
+int
+write_behind(file, convert)
+ FILE *file;
+ int convert;
+{
+ char *buf;
+ int count;
+ int ct;
+ char *p;
+ int c; /* current character */
+ struct bf *b;
+ struct tftphdr *dp;
+
+ b = &bfs[nextone];
+ if (b->counter < -1) /* anything to flush? */
+ return 0; /* just nop if nothing to do */
+
+ count = b->counter; /* remember byte count */
+ b->counter = BF_FREE; /* reset flag */
+ dp = (struct tftphdr *)b->buf;
+ nextone = !nextone; /* incr for next time */
+ buf = dp->th_data;
+
+ if (count <= 0) return -1; /* nak logic? */
+
+ if (convert == 0)
+ return write(fileno(file), buf, count);
+
+ p = buf;
+ ct = count;
+ while (ct--) { /* loop over the buffer */
+ c = *p++; /* pick up a character */
+ if (prevchar == '\r') { /* if prev char was cr */
+ if (c == '\n') /* if have cr,lf then just */
+ fseek(file, -1, 1); /* smash lf on top of the cr */
+ else
+ if (c == '\0') /* if have cr,nul then */
+ goto skipit; /* just skip over the putc */
+ /* else just fall through and allow it */
+ }
+ putc(c, file);
+skipit:
+ prevchar = c;
+ }
+ return count;
+}
+
+
+/* When an error has occurred, it is possible that the two sides
+ * are out of synch. Ie: that what I think is the other side's
+ * response to packet N is really their response to packet N-1.
+ *
+ * So, to try to prevent that, we flush all the input queued up
+ * for us on the network connection on our host.
+ *
+ * We return the number of packets we flushed (mostly for reporting
+ * when trace is active).
+ */
+
+int
+synchnet(f, bsize)
+ int f; /* socket to flush */
+ int bsize; /* size of buffer to sync */
+{
+ int i, j = 0;
+ char rbuf[PKTSIZE];
+ struct sockaddr_storage from;
+ int fromlen;
+
+ while (1) {
+ (void) ioctl(f, FIONREAD, &i);
+ if (i) {
+ j++;
+ fromlen = sizeof from;
+ (void) recvfrom(f, rbuf, sizeof (rbuf), 0,
+ (struct sockaddr *)&from, &fromlen);
+ } else {
+ return(j);
+ }
+ }
+}
--- /dev/null
+/* $NetBSD: tftpsubs.h,v 1.4 2003/08/07 11:16:14 agc Exp $ */
+
+/*
+ * Copyright (c) 1993
+ * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)tftpsubs.h 8.1 (Berkeley) 6/6/93
+ */
+
+/*
+ * Prototypes for read-ahead/write-behind subroutines for tftp user and
+ * server.
+ */
+
+
+struct tftphdr *r_init __P((void));
+void read_ahead __P((FILE *, int, int));
+int readit __P((FILE *, struct tftphdr **, int, int));
+
+int synchnet __P((int, int));
+
+struct tftphdr *w_init __P((void));
+int write_behind __P((FILE *, int));
+int writeit __P((FILE *, struct tftphdr **, int, int));
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
PROJECTVERSION = 2.8
PROJECT_TYPE = Tool
-CFILES = traceroute.c
+CFILES = traceroute.c ifaddrlist.c findsaddr-socket.c version.c
OTHERSRCS = Makefile.preamble Makefile Makefile.postamble mean.awk\
- median.awk README traceroute.8
+ median.awk README traceroute.8 traceroute.h findsaddr.h\
+ ifaddrlist.h gnuc.h
MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
## (e.g. change -O to -O2), see Makefile.postamble.
# Flags passed to compiler (in addition to -g, -O, etc)
-OTHER_CFLAGS =
+OTHER_CFLAGS = -DHAVE_SOCKADDR_SA_LEN
# Flags passed to ld (in addition to -ObjC, etc.)
OTHER_LDFLAGS =
--- /dev/null
+/*
+ * Copyright (c) 2000
+ * The Regents of the University of California. 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 the Computer Systems
+ * Engineering Group at Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory may be used
+ * to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/contrib/traceroute/findsaddr-socket.c,v 1.2 2002/07/30 04:49:13 fenner Exp $
+ */
+
+/* XXX Yes this is WAY too complicated */
+
+#ifndef lint
+static const char rcsid[] =
+ "@(#) $Id: findsaddr-socket.c,v 1.3 2005/02/12 00:04:09 lindak Exp $ (LBL)";
+#endif
+
+#include <sys/param.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#ifdef HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
+#include <sys/time.h> /* concession to AIX */
+
+#if __STDC__
+struct mbuf;
+struct rtentry;
+#endif
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/route.h>
+#include <netinet/in.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "gnuc.h"
+#ifdef HAVE_OS_PROTO_H
+#include "os-proto.h"
+#endif
+
+#include "findsaddr.h"
+
+#ifdef HAVE_SOCKADDR_SA_LEN
+#define SALEN(sa) ((sa)->sa_len)
+#else
+#define SALEN(sa) salen(sa)
+#endif
+
+#ifndef roundup
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */
+#endif
+
+struct rtmsg {
+ struct rt_msghdr rtmsg;
+ u_char data[512];
+};
+
+static struct rtmsg rtmsg = {
+ { 0, RTM_VERSION, RTM_GET, 0,
+ RTF_UP | RTF_GATEWAY | RTF_HOST | RTF_STATIC,
+ RTA_DST | RTA_IFA, 0, 0, 0, 0, 0, { 0 } },
+ { 0 }
+};
+
+#ifndef HAVE_SOCKADDR_SA_LEN
+static int salen(struct sockaddr *);
+#endif
+
+/*
+ * Return the source address for the given destination address
+ */
+const char *
+findsaddr(register const struct sockaddr_in *to,
+ register struct sockaddr_in *from)
+{
+ register struct rt_msghdr *rp;
+ register u_char *cp;
+
+ register struct sockaddr_in *sp, *ifa;
+ register struct sockaddr *sa;
+ register int s, size, cc, seq, i;
+ register pid_t pid;
+ static char errbuf[512];
+
+ s = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);
+ if (s < 0) {
+ sprintf(errbuf, "socket: %.128s", strerror(errno));
+ return (errbuf);
+ }
+
+ seq = 0;
+ pid = getpid();
+
+ rp = &rtmsg.rtmsg;
+ rp->rtm_seq = ++seq;
+ cp = (u_char *)(rp + 1);
+
+ sp = (struct sockaddr_in *)cp;
+ *sp = *to;
+ cp += roundup(SALEN((struct sockaddr *)sp), sizeof(u_int32_t));
+
+ size = cp - (u_char *)rp;
+ rp->rtm_msglen = size;
+
+ cc = write(s, (char *)rp, size);
+ if (cc < 0) {
+ sprintf(errbuf, "write: %.128s", strerror(errno));
+ close(s);
+ return (errbuf);
+ }
+ if (cc != size) {
+ sprintf(errbuf, "short write (%d != %d)", cc, size);
+ close(s);
+ return (errbuf);
+ }
+
+ size = sizeof(rtmsg);
+ do {
+ memset(rp, 0, size);
+ cc = read(s, (char *)rp, size);
+ if (cc < 0) {
+ sprintf(errbuf, "read: %.128s", strerror(errno));
+ close(s);
+ return (errbuf);
+ }
+
+ } while (rp->rtm_seq != seq || rp->rtm_pid != pid);
+ close(s);
+
+
+ if (rp->rtm_version != RTM_VERSION) {
+ sprintf(errbuf, "bad version %d", rp->rtm_version);
+ return (errbuf);
+ }
+ if (rp->rtm_msglen > cc) {
+ sprintf(errbuf, "bad msglen %d > %d", rp->rtm_msglen, cc);
+ return (errbuf);
+ }
+ if (rp->rtm_errno != 0) {
+ sprintf(errbuf, "rtm_errno: %.128s", strerror(rp->rtm_errno));
+ return (errbuf);
+ }
+
+ /* Find the interface sockaddr */
+ cp = (u_char *)(rp + 1);
+ for (i = 1; i != 0; i <<= 1)
+ if ((i & rp->rtm_addrs) != 0) {
+ sa = (struct sockaddr *)cp;
+ switch (i) {
+
+ case RTA_IFA:
+ if (sa->sa_family == AF_INET) {
+ ifa = (struct sockaddr_in *)cp;
+ if (ifa->sin_addr.s_addr != 0) {
+ *from = *ifa;
+ return (NULL);
+ }
+ }
+ break;
+
+ default:
+ break;
+ /* empty */
+ }
+
+ if (SALEN(sa) == 0)
+ cp += sizeof(long);
+ else
+ cp += roundup(SALEN(sa), sizeof(long));
+ }
+
+ return ("failed!");
+}
+
+#ifndef HAVE_SOCKADDR_SA_LEN
+static int
+salen(struct sockaddr *sa)
+{
+ switch (sa->sa_family) {
+
+ case AF_INET:
+ return (sizeof(struct sockaddr_in));
+
+ case AF_LINK:
+ return (sizeof(struct sockaddr_dl));
+
+ default:
+ return (sizeof(struct sockaddr));
+ }
+}
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2000
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may 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.
+ *
+ * @(#) $Id: findsaddr.h,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL)
+ */
+const char *findsaddr(const struct sockaddr_in *, struct sockaddr_in *);
--- /dev/null
+/* @(#) $Header: /cvs/root/network_cmds/traceroute.tproj/gnuc.h,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL) */
+
+/* Define __P() macro, if necessary */
+#ifndef __P
+#if __STDC__
+#define __P(protos) protos
+#else
+#define __P(protos) ()
+#endif
+#endif
+
+/* inline foo */
+#ifdef __GNUC__
+#define inline __inline
+#else
+#define inline
+#endif
+
+/*
+ * Handle new and old "dead" routine prototypes
+ *
+ * For example:
+ *
+ * __dead void foo(void) __attribute__((volatile));
+ *
+ */
+#ifdef __GNUC__
+#ifndef __dead
+#define __dead volatile
+#endif
+#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+#ifndef __attribute__
+#define __attribute__(args)
+#endif
+#endif
+#else
+#ifndef __dead
+#define __dead
+#endif
+#ifndef __attribute__
+#define __attribute__(args)
+#endif
+#endif
--- /dev/null
+/*
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * The Regents of the University of California. 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 the Computer Systems
+ * Engineering Group at Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory may be used
+ * to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static const char rcsid[] =
+ "@(#) $Id: ifaddrlist.c,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL)";
+#endif
+
+#include <sys/param.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#ifdef HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
+#include <sys/time.h> /* concession to AIX */
+
+#if __STDC__
+struct mbuf;
+struct rtentry;
+#endif
+
+#include <net/if.h>
+#include <netinet/in.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <memory.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "gnuc.h"
+#ifdef HAVE_OS_PROTO_H
+#include "os-proto.h"
+#endif
+
+#include "ifaddrlist.h"
+
+/*
+ * Return the interface list
+ */
+int
+ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf)
+{
+ register int fd, nipaddr;
+#ifdef HAVE_SOCKADDR_SA_LEN
+ register int n;
+#endif
+ register struct ifreq *ifrp, *ifend, *ifnext, *mp;
+ register struct sockaddr_in *sin;
+ register struct ifaddrlist *al;
+ struct ifconf ifc;
+ struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr;
+#define MAX_IPADDR (sizeof(ibuf) / sizeof(ibuf[0]))
+ static struct ifaddrlist ifaddrlist[MAX_IPADDR];
+ char device[sizeof(ifr.ifr_name) + 1];
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0) {
+ (void)sprintf(errbuf, "socket: %s", strerror(errno));
+ return (-1);
+ }
+ ifc.ifc_len = sizeof(ibuf);
+ ifc.ifc_buf = (caddr_t)ibuf;
+
+ if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 ||
+ ifc.ifc_len < sizeof(struct ifreq)) {
+ if (errno == EINVAL)
+ (void)sprintf(errbuf,
+ "SIOCGIFCONF: ifreq struct too small (%d bytes)",
+ sizeof(ibuf));
+ else
+ (void)sprintf(errbuf, "SIOCGIFCONF: %s",
+ strerror(errno));
+ (void)close(fd);
+ return (-1);
+ }
+ ifrp = ibuf;
+ ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len);
+
+ al = ifaddrlist;
+ mp = NULL;
+ nipaddr = 0;
+ for (; ifrp < ifend; ifrp = ifnext) {
+#ifdef HAVE_SOCKADDR_SA_LEN
+ n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
+ if (n < sizeof(*ifrp))
+ ifnext = ifrp + 1;
+ else
+ ifnext = (struct ifreq *)((char *)ifrp + n);
+ if (ifrp->ifr_addr.sa_family != AF_INET)
+ continue;
+#else
+ ifnext = ifrp + 1;
+#endif
+ /*
+ * Need a template to preserve address info that is
+ * used below to locate the next entry. (Otherwise,
+ * SIOCGIFFLAGS stomps over it because the requests
+ * are returned in a union.)
+ */
+ strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
+ if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) {
+ if (errno == ENXIO)
+ continue;
+ (void)sprintf(errbuf, "SIOCGIFFLAGS: %.*s: %s",
+ (int)sizeof(ifr.ifr_name), ifr.ifr_name,
+ strerror(errno));
+ (void)close(fd);
+ return (-1);
+ }
+
+ /* Must be up */
+ if ((ifr.ifr_flags & IFF_UP) == 0)
+ continue;
+
+
+ (void)strncpy(device, ifr.ifr_name, sizeof(ifr.ifr_name));
+ device[sizeof(device) - 1] = '\0';
+#ifdef sun
+ /* Ignore sun virtual interfaces */
+ if (strchr(device, ':') != NULL)
+ continue;
+#endif
+ if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
+ (void)sprintf(errbuf, "SIOCGIFADDR: %s: %s",
+ device, strerror(errno));
+ (void)close(fd);
+ return (-1);
+ }
+
+ if (nipaddr >= MAX_IPADDR) {
+ (void)sprintf(errbuf, "Too many interfaces (%d)",
+ MAX_IPADDR);
+ (void)close(fd);
+ return (-1);
+ }
+ sin = (struct sockaddr_in *)&ifr.ifr_addr;
+ al->addr = sin->sin_addr.s_addr;
+ al->device = strdup(device);
+ ++al;
+ ++nipaddr;
+ }
+ (void)close(fd);
+
+ *ipaddrp = ifaddrlist;
+ return (nipaddr);
+}
--- /dev/null
+/*
+ * Copyright (c) 1997
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may 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: /cvs/root/network_cmds/traceroute.tproj/ifaddrlist.h,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL)
+ */
+
+struct ifaddrlist {
+ u_int32_t addr;
+ char *device;
+};
+
+int ifaddrlist(struct ifaddrlist **, char *);
-.\" Copyright (c) 1990, 1991, 1993
+.\" Copyright (c) 1989, 1995, 1996, 1997, 1999, 2000
.\" The Regents of the University of California. All rights reserved.
.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Van Jacobson.
+.\" Redistribution and use in source and binary forms are permitted
+.\" provided that the above copyright notice and this paragraph are
+.\" duplicated in all such forms and that any documentation,
+.\" advertising materials, and other materials related to such
+.\" distribution and use acknowledge that the software was developed
+.\" by the University of California, Berkeley. The name of the
+.\" University 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
-.\" 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 the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)traceroute.8 8.2 (Berkeley) 6/1/94
-.\"
-.Dd June 1, 1994
+.Dd September 21, 2000
.Dt TRACEROUTE 8
.Os BSD 4.3
.Sh NAME
.Nd print the route packets take to network host
.Sh SYNOPSIS
.Nm traceroute
+.Op Fl dFISdnrvx
+.Op Fl f Ar first_ttl
+.Op Fl g Ar gateway
+.Op Fl i Ar iface
+.Op Fl M Ar first_ttl
.Op Fl m Ar max_ttl
-.Op Fl n
+.Op Fl P Ar proto
.Op Fl p Ar port
.Op Fl q Ar nqueries
-.Op Fl r
-.Bk -words
.Op Fl s Ar src_addr
-.Ek
.Op Fl t Ar tos
.Op Fl w Ar waittime
+.Op Fl z Ar pausemsecs
.Ar host
.Op Ar packetsize
.Sh DESCRIPTION
host.
.Pp
The only mandatory parameter is the destination host name or IP number.
-The default probe datagram length is 38 bytes, but this may be increased
+The default probe datagram length is 40 bytes, but this may be increased
by specifying a packet size (in bytes) after the destination host
name.
.Pp
Other options are:
.Bl -tag -width Ds
+.It Fl f Ar first_ttl
+Set the initial time-to-live used in the first outgoing probe packet.
+.It Fl F
+Set the "don't fragment" bit.
+.It Fl d
+Enable socket level debugging.
+.It Fl g Ar gateway
+Specify a loose source route gateway (8 maximum).
+.It Fl i Ar iface
+Specify a network interface to obtain the source IP address for
+outgoing probe packets. This is normally only useful on a multi-homed
+host. (See the
+.Fl s
+flag for another way to do this.)
+.It Fl I
+Use
+.Tn ICMP
+ECHO instead of
+.Tn UDP
+datagrams. (A synonym for "-P icmp").
+.It Fl M Ar first_ttl
+Set the initial time-to-live value used in outgoing probe packets.
+The default is 1, i.e., start with the first hop.
.It Fl m Ar max_ttl
Set the max time-to-live (max number of hops) used in outgoing probe
-packets. The default is 30 hops (the same default used for
+packets. The default is
+.Em net.inet.ip.ttl
+hops (the same default used for
.Tn TCP
connections).
.It Fl n
Print hop addresses numerically rather than symbolically and numerically
(saves a nameserver address-to-name lookup for each gateway found on the
path).
+.It Fl P Ar proto
+Send packets of specified IP protocol. The currently supported protocols
+are:
+.Tn UDP
+,
+.Tn TCP
+,
+.Tn GRE
+and
+.Tn ICMP
+Other protocols may also be specified (either by name or by number), though
+.Nm traceroute
+does not implement any special knowledge of their packet formats. This
+option is useful for determining which router along a path may be
+blocking packets based on IP protocol number. But see BUGS below.
.It Fl p Ar port
-Set the base
+Protocol specific. For
.Tn UDP
+and
+.Tn TCP,
+sets the base
.Ar port
number used in probes (default is 33434).
.Nm Traceroute
of the interface the probe packet is sent on. If the IP address
is not one of this machine's interface addresses, an error is
returned and nothing is sent.
-.ne 1i
+(See the
+.Fl i
+flag for another way to do this.)
+.It Fl S
+Print a summary of how many probes were not answered for each hop.
.It Fl t Ar tos
Set the
.Em type-of-service
a decimal integer in the range 0 to 255. This option can be used to
see if different types-of-service result in different paths. (If you
are not running a
-.Bx 4.3 tahoe
+.Bx 4.4
or later system, this may be academic since the normal network
services like telnet and ftp don't let you control the
.Dv TOS ) .
.Dv UNREACHABLE Ns s
are listed.
.It Fl w
-Set the time (in seconds) to wait for a response to a probe (default 3
-sec.).
+Set the time (in seconds) to wait for a response to a probe (default 5 sec.).
+.It Fl x
+Toggle IP checksums. Normally, this prevents traceroute from calculating
+IP checksums. In some cases, the operating system can overwrite parts of
+the outgoing packet but not recalculate the checksum (so in some cases
+the default is to not calculate checksums and using
+.Fl x
+causes them to be calculated). Note that checksums are usually required
+for the last hop when using
+.Tn ICMP
+ECHO probes (
+.Fl I
+). So they are always calculated when using ICMP.
+.It Fl z Ar pausemsecs
+Set the time (in milliseconds) to pause between probes (default 0).
+Some systems such as Solaris and routers such as Ciscos rate limit
+ICMP messages. A good value to use with this this is 500 (e.g. 1/2 second).
.El
.Pp
This program attempts to trace the route an IP packet would follow to some
.Tn ICMP
"port unreachable"
(which means we got to "host") or hit a max (which
-defaults to 30 hops & can be changed with the
+defaults to
+.Em net.inet.ip.ttl
+hops & can be changed with the
.Fl m
flag). Three
probes (changed with
line is printed showing the ttl, address of the gateway and
round trip time of each probe. If the probe answers come from
different gateways, the address of each responding system will
-be printed. If there is no response within a 3 sec. timeout
+be printed. If there is no response within a 5 sec. timeout
interval (changed with the
.Fl w
flag), a "*" is printed for that
A sample use and output might be:
.Bd -literal
[yak 71]% traceroute nis.nsf.net.
-traceroute to nis.nsf.net (35.1.1.48), 30 hops max, 56 byte packet
+traceroute to nis.nsf.net (35.1.1.48), 64 hops max, 38 byte packet
1 helios.ee.lbl.gov (128.3.112.1) 19 ms 19 ms 0 ms
2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms
3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms
A more interesting example is:
.Bd -literal
[yak 72]% traceroute allspice.lcs.mit.edu.
-traceroute to allspice.lcs.mit.edu (18.26.0.115), 30 hops max
+traceroute to allspice.lcs.mit.edu (18.26.0.115), 64 hops max
1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms
2 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 19 ms 19 ms
3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 19 ms
software, expect to see this problem
frequently and/or take care picking the target host of your
probes.
+.Pp
Other possible annotations after the time are
.Sy !H ,
.Sy !N ,
+or
.Sy !P
-(got a host, network or protocol unreachable, respectively),
+(host, network or protocol unreachable),
.Sy !S
-or
+(source route failed),
.Sy !F
-(source route failed or fragmentation needed \- neither of these should
-ever occur and the associated gateway is busted if you see one). If
-almost all the probes result in some kind of unreachable,
+(fragmentation needed \- the RFC1191 Path MTU Discovery value is displayed),
+.Sy !X
+(communication administratively prohibited),
+.Sy !V
+(host precedence violation),
+.Sy !C
+(precedence cutoff in effect), or
+.Sy !<num>
+(ICMP unreachable code <num>).
+These are defined by RFC1812 (which supersedes RFC1716).
+If almost all the probes result in some kind of unreachable,
.Nm traceroute
will give up and exit.
.Pp
.Sh SEE ALSO
.Xr netstat 1 ,
.Xr ping 8
-.Sh HISTORY
-The
+.Sh BUGS
+When using protocols other than UDP, functionality is reduced.
+In particular, the last packet will often appear to be lost, because
+even though it reaches the destination host, there's no way to know
+that because no ICMP message is sent back.
+In the TCP case,
.Nm
-command
-.Bt
+should listen for a RST from the destination host (or an intermediate
+router that's filtering packets), but this is not implemented yet.
+
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*-
- * Copyright (c) 1990, 1993
+ * Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000
* The Regents of the University of California. All rights reserved.
*
- * This code is derived from software contributed to Berkeley by
- * Van Jacobson.
- *
* 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 the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may 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.
*/
#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1990, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)traceroute.c 8.1 (Berkeley) 6/6/93";
-#endif /* not lint */
+static const char copyright[] =
+ "@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000\n\
+The Regents of the University of California. All rights reserved.\n";
+#if 0
+static const char rcsid[] =
+ "@(#)$Id: traceroute.c,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL)";
+#endif
+static const char rcsid[] =
+ "$FreeBSD: src/contrib/traceroute/traceroute.c,v 1.26 2004/04/17 18:44:23 pb Exp $";
+#endif
/*
* traceroute host - trace the route ip packets follow going to "host".
* icmp "time exceeded" reply from a gateway. We start our probes
* with a ttl of one and increase by one until we get an icmp "port
* unreachable" (which means we got to "host") or hit a max (which
- * defaults to 30 hops & can be changed with the -m flag). Three
- * probes (change with -q flag) are sent at each ttl setting and a
- * line is printed showing the ttl, address of the gateway and
+ * defaults to net.inet.ip.ttl hops & can be changed with the -m flag).
+ * Three probes (change with -q flag) are sent at each ttl setting and
+ * a line is printed showing the ttl, address of the gateway and
* round trip time of each probe. If the probe answers come from
* different gateways, the address of each responding system will
* be printed. If there is no response within a 5 sec. timeout
* A sample use might be:
*
* [yak 71]% traceroute nis.nsf.net.
- * traceroute to nis.nsf.net (35.1.1.48), 30 hops max, 56 byte packet
+ * traceroute to nis.nsf.net (35.1.1.48), 64 hops max, 56 byte packet
* 1 helios.ee.lbl.gov (128.3.112.1) 19 ms 19 ms 0 ms
* 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms
* 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms
* A more interesting example is:
*
* [yak 72]% traceroute allspice.lcs.mit.edu.
- * traceroute to allspice.lcs.mit.edu (18.26.0.115), 30 hops max
+ * traceroute to allspice.lcs.mit.edu (18.26.0.115), 64 hops max
* 1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms
* 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 19 ms 19 ms
* 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 19 ms
* back to yourself. Unfortunately, SO many gateways botch source
* routing, the thing is almost worthless. Maybe one day...
*
- * -- Van Jacobson (van@helios.ee.lbl.gov)
+ * -- Van Jacobson (van@ee.lbl.gov)
* Tue Dec 20 03:50:13 PST 1988
*/
#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+#include <sys/socket.h>
+#ifdef HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
+#include <sys/time.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
+#include <netinet/ip_var.h>
#include <netinet/ip_icmp.h>
#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcpip.h>
#include <arpa/inet.h>
+#ifdef IPSEC
+#include <net/route.h>
+#include <netinet6/ipsec.h> /* XXX */
+#endif /* IPSEC */
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+#include <memory.h>
#include <netdb.h>
#include <stdio.h>
-#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#define MAXPACKET 65535 /* max ip packet size */
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 64
+#include "gnuc.h"
+#ifdef HAVE_OS_PROTO_H
+#include "os-proto.h"
+#endif
+
+/* rfc1716 */
+#ifndef ICMP_UNREACH_FILTER_PROHIB
+#define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohibited filter */
#endif
+#ifndef ICMP_UNREACH_HOST_PRECEDENCE
+#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host precedence violation */
+#endif
+#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
+#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */
+#endif
+
+#include "findsaddr.h"
+#include "ifaddrlist.h"
+#include "traceroute.h"
-#ifndef FD_SET
-#define NFDBITS (8*sizeof(fd_set))
-#define FD_SETSIZE NFDBITS
-#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
-#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
-#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
-#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
+/* Maximum number of gateways (include room for one noop) */
+#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(u_int32_t)))
+
+#ifndef MAXHOSTNAMELEN
+#define MAXHOSTNAMELEN 64
#endif
#define Fprintf (void)fprintf
-#define Sprintf (void)sprintf
#define Printf (void)printf
-/*
- * format of a (udp) probe packet.
- */
-struct opacket {
- struct ip ip;
- struct udphdr udp;
+/* What a GRE packet header looks like */
+struct grehdr {
+ u_int16_t flags;
+ u_int16_t proto;
+ u_int16_t length; /* PPTP version of these fields */
+ u_int16_t callId;
+};
+#ifndef IPPROTO_GRE
+#define IPPROTO_GRE 47
+#endif
+
+/* For GRE, we prepare what looks like a PPTP packet */
+#define GRE_PPTP_PROTO 0x880b
+
+/* Host name and address list */
+struct hostinfo {
+ char *name;
+ int n;
+ u_int32_t *addrs;
+};
+
+/* Data section of the probe packet */
+struct outdata {
u_char seq; /* sequence number of this packet */
u_char ttl; /* ttl packet left with */
struct timeval tv; /* time packet left */
};
+#ifndef HAVE_ICMP_NEXTMTU
+/* Path MTU Discovery (RFC1191) */
+struct my_pmtu {
+ u_short ipm_void;
+ u_short ipm_nextmtu;
+};
+#endif
+
u_char packet[512]; /* last inbound (icmp) packet */
-struct opacket *outpacket; /* last output (udp) packet */
-int wait_for_reply __P((int, struct sockaddr_in *));
-void send_probe __P((int, int));
-double deltaT __P((struct timeval *, struct timeval *));
-int packet_ok __P((u_char *, int, struct sockaddr_in *, int));
-void print __P((u_char *, int, struct sockaddr_in *));
-void tvsub __P((struct timeval *, struct timeval *));
-char *inetname __P((struct in_addr));
-void usage __P(());
+struct ip *outip; /* last output ip packet */
+u_char *outp; /* last output inner protocol packet */
+
+/* loose source route gateway list (including room for final destination) */
+u_int32_t gwlist[NGATEWAYS + 1];
int s; /* receive (icmp) socket file descriptor */
int sndsock; /* send (udp) socket file descriptor */
-struct timezone tz; /* leftover */
struct sockaddr whereto; /* Who to try to reach */
-int datalen; /* How much data */
-
-char *source = 0;
+struct sockaddr wherefrom; /* Who we are */
+int packlen; /* total length of packet */
+int protlen; /* length of protocol part of packet */
+int minpacket; /* min ip packet size */
+int maxpacket = 32 * 1024; /* max ip packet size */
+int pmtu; /* Path MTU Discovery (RFC1191) */
+u_int pausemsecs;
+
+char *prog;
+char *source;
char *hostname;
+char *device;
+static const char devnull[] = "/dev/null";
int nprobes = 3;
-int max_ttl = 30;
+int max_ttl;
+int first_ttl = 1;
u_short ident;
-u_short port = 32768+666; /* start udp dest port # for probe packets */
+u_short port; /* protocol specific base "port" */
+
int options; /* socket options */
int verbose;
int waittime = 5; /* time to wait for response (in seconds) */
int nflag; /* print addresses numerically */
+#ifdef CANT_HACK_IPCKSUM
+int doipcksum = 0; /* don't calculate ip checksums by default */
+#else
+int doipcksum = 1; /* calculate ip checksums by default */
+#endif
+int optlen; /* length of ip options */
+
+extern int optind;
+extern int opterr;
+extern char *optarg;
+
+/* Forwards */
+double deltaT(struct timeval *, struct timeval *);
+void freehostinfo(struct hostinfo *);
+void getaddr(u_int32_t *, char *);
+struct hostinfo *gethostinfo(char *);
+u_short in_cksum(u_short *, int);
+char *inetname(struct in_addr);
+int main(int, char **);
+u_short p_cksum(struct ip *, u_short *, int);
+int packet_ok(u_char *, int, struct sockaddr_in *, int);
+char *pr_type(u_char);
+void print(u_char *, int, struct sockaddr_in *);
+#ifdef IPSEC
+int setpolicy __P((int so, char *policy));
+#endif
+void send_probe(int, int);
+struct outproto *setproto(char *);
+int str2val(const char *, const char *, int, int);
+void tvsub(struct timeval *, struct timeval *);
+void usage(void);
+int wait_for_reply(int, struct sockaddr_in *, const struct timeval *);
+#ifndef HAVE_USLEEP
+int usleep(u_int);
+#endif
+
+void udp_prep(struct outdata *);
+int udp_check(const u_char *, int);
+void tcp_prep(struct outdata *);
+int tcp_check(const u_char *, int);
+void gre_prep(struct outdata *);
+int gre_check(const u_char *, int);
+void gen_prep(struct outdata *);
+int gen_check(const u_char *, int);
+void icmp_prep(struct outdata *);
+int icmp_check(const u_char *, int);
+
+/* Descriptor structure for each outgoing protocol we support */
+struct outproto {
+ char *name; /* name of protocol */
+ u_char num; /* IP protocol number */
+ u_short hdrlen; /* max size of protocol header */
+ u_short port; /* default base protocol-specific "port" */
+ void (*prepare)(struct outdata *);
+ /* finish preparing an outgoing packet */
+ int (*check)(const u_char *, int);
+ /* check an incoming packet */
+};
+
+/* List of supported protocols. The first one is the default. The last
+ one is the handler for generic protocols not explicitly listed. */
+struct outproto protos[] = {
+ {
+ "udp",
+ IPPROTO_UDP,
+ sizeof(struct udphdr),
+ 32768 + 666,
+ udp_prep,
+ udp_check
+ },
+ {
+ "tcp",
+ IPPROTO_TCP,
+ sizeof(struct tcphdr),
+ 32768 + 666,
+ tcp_prep,
+ tcp_check
+ },
+ {
+ "gre",
+ IPPROTO_GRE,
+ sizeof(struct grehdr),
+ GRE_PPTP_PROTO,
+ gre_prep,
+ gre_check
+ },
+ {
+ "icmp",
+ IPPROTO_ICMP,
+ sizeof(struct icmp),
+ 0,
+ icmp_prep,
+ icmp_check
+ },
+ {
+ NULL,
+ 0,
+ 2 * sizeof(u_short),
+ 0,
+ gen_prep,
+ gen_check
+ },
+};
+struct outproto *proto = &protos[0];
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char **argv)
{
- extern char *optarg;
- extern int optind;
- struct hostent *hp;
- struct protoent *pe;
- struct sockaddr_in from, *to;
- int ch, i, on, probe, seq, tos, ttl;
-
- on = 1;
- seq = tos = 0;
- to = (struct sockaddr_in *)&whereto;
- while ((ch = getopt(argc, argv, "dm:np:q:rs:t:w:v")) != EOF)
- switch(ch) {
+ register int op, code, n;
+ register char *cp;
+ register const char *err;
+ register u_int32_t *ap;
+ register struct sockaddr_in *from = (struct sockaddr_in *)&wherefrom;
+ register struct sockaddr_in *to = (struct sockaddr_in *)&whereto;
+ register struct hostinfo *hi;
+ int on = 1;
+ register struct protoent *pe;
+ register int ttl, probe, i;
+ register int seq = 0;
+ int tos = 0, settos = 0;
+ register int lsrr = 0;
+ register u_short off = 0;
+ struct ifaddrlist *al;
+ char errbuf[132];
+ int requestPort = -1;
+ int sump = 0;
+ int sockerrno;
+
+ /* Insure the socket fds won't be 0, 1 or 2 */
+ if (open(devnull, O_RDONLY) < 0 ||
+ open(devnull, O_RDONLY) < 0 ||
+ open(devnull, O_RDONLY) < 0) {
+ Fprintf(stderr, "%s: open \"%s\": %s\n",
+ prog, devnull, strerror(errno));
+ exit(1);
+ }
+ /*
+ * Do the setuid-required stuff first, then lose priveleges ASAP.
+ * Do error checking for these two calls where they appeared in
+ * the original code.
+ */
+ cp = "icmp";
+ pe = getprotobyname(cp);
+ if (pe) {
+ if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0)
+ sockerrno = errno;
+ else if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
+ sockerrno = errno;
+ }
+
+ setuid(getuid());
+
+#ifdef IPCTL_DEFTTL
+ {
+ int mib[4] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_DEFTTL };
+ size_t sz = sizeof(max_ttl);
+
+ if (sysctl(mib, 4, &max_ttl, &sz, NULL, 0) == -1) {
+ perror("sysctl(net.inet.ip.ttl)");
+ exit(1);
+ }
+ }
+#else
+ max_ttl = 30;
+#endif
+
+ if (argv[0] == NULL)
+ prog = "traceroute";
+ else if ((cp = strrchr(argv[0], '/')) != NULL)
+ prog = cp + 1;
+ else
+ prog = argv[0];
+
+ opterr = 0;
+ while ((op = getopt(argc, argv, "dFInrSvxf:g:i:M:m:P:p:q:s:t:w:z:")) != EOF)
+ switch (op) {
+
case 'd':
options |= SO_DEBUG;
break;
- case 'm':
- max_ttl = atoi(optarg);
- if (max_ttl <= 1) {
+
+ case 'f':
+ case 'M': /* FreeBSD compat. */
+ first_ttl = str2val(optarg, "first ttl", 1, 255);
+ break;
+
+ case 'F':
+ off = IP_DF;
+ break;
+
+ case 'g':
+ if (lsrr >= NGATEWAYS) {
Fprintf(stderr,
- "traceroute: max ttl must be >1.\n");
+ "%s: No more than %d gateways\n",
+ prog, NGATEWAYS);
exit(1);
}
+ getaddr(gwlist + lsrr, optarg);
+ ++lsrr;
+ break;
+
+ case 'i':
+ device = optarg;
+ break;
+
+ case 'I':
+ proto = setproto("icmp");
+ break;
+
+ case 'm':
+ max_ttl = str2val(optarg, "max ttl", 1, 255);
break;
+
case 'n':
- nflag++;
+ ++nflag;
break;
+
+ case 'P':
+ proto = setproto(optarg);
+ break;
+
case 'p':
- port = atoi(optarg);
- if (port < 1) {
- Fprintf(stderr,
- "traceroute: port must be >0.\n");
- exit(1);
- }
+ requestPort = (u_short)str2val(optarg, "port",
+ 1, (1 << 16) - 1);
break;
+
case 'q':
- nprobes = atoi(optarg);
- if (nprobes < 1) {
- Fprintf(stderr,
- "traceroute: nprobes must be >0.\n");
- exit(1);
- }
+ nprobes = str2val(optarg, "nprobes", 1, -1);
break;
+
case 'r':
options |= SO_DONTROUTE;
break;
+
case 's':
/*
* set the ip source address of the outbound
*/
source = optarg;
break;
+
+ case 'S':
+ sump = 1;
+ break;
+
case 't':
- tos = atoi(optarg);
- if (tos < 0 || tos > 255) {
- Fprintf(stderr,
- "traceroute: tos must be 0 to 255.\n");
- exit(1);
- }
+ tos = str2val(optarg, "tos", 0, 255);
+ ++settos;
break;
+
case 'v':
- verbose++;
+ ++verbose;
+ break;
+
+ case 'x':
+ doipcksum = (doipcksum == 0);
break;
+
case 'w':
- waittime = atoi(optarg);
- if (waittime <= 1) {
- Fprintf(stderr,
- "traceroute: wait must be >1 sec.\n");
- exit(1);
- }
+ waittime = str2val(optarg, "wait time",
+ 2, 24 * 60 * 60);
break;
+
+ case 'z':
+ pausemsecs = str2val(optarg, "pause msecs",
+ 0, 60 * 60 * 1000);
+ break;
+
default:
usage();
}
- argc -= optind;
- argv += optind;
- if (argc < 1)
- usage();
-
- setlinebuf (stdout);
+ /* Set requested port, if any, else default for this protocol */
+ port = (requestPort != -1) ? requestPort : proto->port;
- (void) bzero((char *)&whereto, sizeof(struct sockaddr));
- to->sin_family = AF_INET;
- to->sin_addr.s_addr = inet_addr(*argv);
- if (to->sin_addr.s_addr != -1)
- hostname = *argv;
- else {
- hp = gethostbyname(*argv);
- if (hp) {
- to->sin_family = hp->h_addrtype;
- bcopy(hp->h_addr, (caddr_t)&to->sin_addr, hp->h_length);
- hostname = hp->h_name;
- } else {
- (void)fprintf(stderr,
- "traceroute: unknown host %s\n", *argv);
- exit(1);
- }
- }
- if (*++argv)
- datalen = atoi(*argv);
- if (datalen < 0 || datalen >= MAXPACKET - sizeof(struct opacket)) {
+ if (first_ttl > max_ttl) {
Fprintf(stderr,
- "traceroute: packet size must be 0 <= s < %ld.\n",
- MAXPACKET - sizeof(struct opacket));
+ "%s: first ttl (%d) may not be greater than max ttl (%d)\n",
+ prog, first_ttl, max_ttl);
exit(1);
}
- datalen += sizeof(struct opacket);
- outpacket = (struct opacket *)malloc((unsigned)datalen);
- if (! outpacket) {
- perror("traceroute: malloc");
+
+ if (!doipcksum)
+ Fprintf(stderr, "%s: Warning: ip checksums disabled\n", prog);
+
+ if (lsrr > 0)
+ optlen = (lsrr + 1) * sizeof(gwlist[0]);
+ minpacket = sizeof(*outip) + proto->hdrlen + sizeof(struct outdata) + optlen;
+ packlen = minpacket; /* minimum sized packet */
+
+ /* Process destination and optional packet size */
+ switch (argc - optind) {
+
+ case 2:
+ packlen = str2val(argv[optind + 1],
+ "packet length", minpacket, maxpacket);
+ /* Fall through */
+
+ case 1:
+ hostname = argv[optind];
+ hi = gethostinfo(hostname);
+ setsin(to, hi->addrs[0]);
+ if (hi->n > 1)
+ Fprintf(stderr,
+ "%s: Warning: %s has multiple addresses; using %s\n",
+ prog, hostname, inet_ntoa(to->sin_addr));
+ hostname = hi->name;
+ hi->name = NULL;
+ freehostinfo(hi);
+ break;
+
+ default:
+ usage();
+ }
+
+#ifdef HAVE_SETLINEBUF
+ setlinebuf (stdout);
+#else
+ setvbuf(stdout, NULL, _IOLBF, 0);
+#endif
+
+ protlen = packlen - sizeof(*outip) - optlen;
+
+ outip = (struct ip *)malloc((unsigned)packlen);
+ if (outip == NULL) {
+ Fprintf(stderr, "%s: malloc: %s\n", prog, strerror(errno));
exit(1);
}
- (void) bzero((char *)outpacket, datalen);
- outpacket->ip.ip_dst = to->sin_addr;
- outpacket->ip.ip_tos = tos;
- outpacket->ip.ip_v = IPVERSION;
- outpacket->ip.ip_id = 0;
+ memset((char *)outip, 0, packlen);
+
+ outip->ip_v = IPVERSION;
+ if (settos)
+ outip->ip_tos = tos;
+#ifdef BYTESWAP_IP_HDR
+ outip->ip_len = htons(packlen);
+ outip->ip_off = htons(off);
+#else
+ outip->ip_len = packlen;
+ outip->ip_off = off;
+#endif
+ outip->ip_p = proto->num;
+ outp = (u_char *)(outip + 1);
+#ifdef HAVE_RAW_OPTIONS
+ if (lsrr > 0) {
+ register u_char *optlist;
+
+ optlist = outp;
+ outp += optlen;
+
+ /* final hop */
+ gwlist[lsrr] = to->sin_addr.s_addr;
+
+ outip->ip_dst.s_addr = gwlist[0];
+
+ /* force 4 byte alignment */
+ optlist[0] = IPOPT_NOP;
+ /* loose source route option */
+ optlist[1] = IPOPT_LSRR;
+ i = lsrr * sizeof(gwlist[0]);
+ optlist[2] = i + 3;
+ /* Pointer to LSRR addresses */
+ optlist[3] = IPOPT_MINOFF;
+ memcpy(optlist + 4, gwlist + 1, i);
+ } else
+#endif
+ outip->ip_dst = to->sin_addr;
+ outip->ip_hl = (outp - (u_char *)outip) >> 2;
ident = (getpid() & 0xffff) | 0x8000;
- if ((pe = getprotobyname("icmp")) == NULL) {
- Fprintf(stderr, "icmp: unknown protocol\n");
- exit(10);
+ if (pe == NULL) {
+ Fprintf(stderr, "%s: unknown protocol %s\n", prog, cp);
+ exit(1);
}
- if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) {
- perror("traceroute: icmp socket");
- exit(5);
+ if (s < 0) {
+ errno = sockerrno;
+ Fprintf(stderr, "%s: icmp socket: %s\n", prog, strerror(errno));
+ exit(1);
}
if (options & SO_DEBUG)
- (void) setsockopt(s, SOL_SOCKET, SO_DEBUG,
- (char *)&on, sizeof(on));
+ (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&on,
+ sizeof(on));
if (options & SO_DONTROUTE)
- (void) setsockopt(s, SOL_SOCKET, SO_DONTROUTE,
- (char *)&on, sizeof(on));
+ (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on,
+ sizeof(on));
- if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
- perror("traceroute: raw socket");
- exit(5);
+#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
+ if (setpolicy(s, "in bypass") < 0)
+ errx(1, "%s", ipsec_strerror());
+
+ if (setpolicy(s, "out bypass") < 0)
+ errx(1, "%s", ipsec_strerror());
+#endif /* defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) */
+
+ if (sndsock < 0) {
+ errno = sockerrno;
+ Fprintf(stderr, "%s: raw socket: %s\n", prog, strerror(errno));
+ exit(1);
}
+
+#if defined(IP_OPTIONS) && !defined(HAVE_RAW_OPTIONS)
+ if (lsrr > 0) {
+ u_char optlist[MAX_IPOPTLEN];
+
+ cp = "ip";
+ if ((pe = getprotobyname(cp)) == NULL) {
+ Fprintf(stderr, "%s: unknown protocol %s\n", prog, cp);
+ exit(1);
+ }
+
+ /* final hop */
+ gwlist[lsrr] = to->sin_addr.s_addr;
+ ++lsrr;
+
+ /* force 4 byte alignment */
+ optlist[0] = IPOPT_NOP;
+ /* loose source route option */
+ optlist[1] = IPOPT_LSRR;
+ i = lsrr * sizeof(gwlist[0]);
+ optlist[2] = i + 3;
+ /* Pointer to LSRR addresses */
+ optlist[3] = IPOPT_MINOFF;
+ memcpy(optlist + 4, gwlist, i);
+
+ if ((setsockopt(sndsock, pe->p_proto, IP_OPTIONS,
+ (char *)optlist, i + sizeof(gwlist[0]))) < 0) {
+ Fprintf(stderr, "%s: IP_OPTIONS: %s\n",
+ prog, strerror(errno));
+ exit(1);
+ }
+ }
+#endif
+
#ifdef SO_SNDBUF
- if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&datalen,
- sizeof(datalen)) < 0) {
- perror("traceroute: SO_SNDBUF");
- exit(6);
+ if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&packlen,
+ sizeof(packlen)) < 0) {
+ Fprintf(stderr, "%s: SO_SNDBUF: %s\n", prog, strerror(errno));
+ exit(1);
}
-#endif SO_SNDBUF
+#endif
#ifdef IP_HDRINCL
if (setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, (char *)&on,
- sizeof(on)) < 0) {
- perror("traceroute: IP_HDRINCL");
- exit(6);
+ sizeof(on)) < 0) {
+ Fprintf(stderr, "%s: IP_HDRINCL: %s\n", prog, strerror(errno));
+ exit(1);
}
-#endif IP_HDRINCL
+#else
+#ifdef IP_TOS
+ if (settos && setsockopt(sndsock, IPPROTO_IP, IP_TOS,
+ (char *)&tos, sizeof(tos)) < 0) {
+ Fprintf(stderr, "%s: setsockopt tos %d: %s\n",
+ prog, tos, strerror(errno));
+ exit(1);
+ }
+#endif
+#endif
if (options & SO_DEBUG)
- (void) setsockopt(sndsock, SOL_SOCKET, SO_DEBUG,
- (char *)&on, sizeof(on));
+ (void)setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, (char *)&on,
+ sizeof(on));
if (options & SO_DONTROUTE)
- (void) setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE,
- (char *)&on, sizeof(on));
-
- if (source) {
- (void) bzero((char *)&from, sizeof(struct sockaddr));
- from.sin_family = AF_INET;
- from.sin_addr.s_addr = inet_addr(source);
- if (from.sin_addr.s_addr == -1) {
- Printf("traceroute: unknown host %s\n", source);
+ (void)setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, (char *)&on,
+ sizeof(on));
+
+ /* Get the interface address list */
+ n = ifaddrlist(&al, errbuf);
+ if (n < 0) {
+ Fprintf(stderr, "%s: ifaddrlist: %s\n", prog, errbuf);
+ exit(1);
+ }
+ if (n == 0) {
+ Fprintf(stderr,
+ "%s: Can't find any network interfaces\n", prog);
+ exit(1);
+ }
+
+ /* Look for a specific device */
+ if (device != NULL) {
+ for (i = n; i > 0; --i, ++al)
+ if (strcmp(device, al->device) == 0)
+ break;
+ if (i <= 0) {
+ Fprintf(stderr, "%s: Can't find interface %.32s\n",
+ prog, device);
exit(1);
}
- outpacket->ip.ip_src = from.sin_addr;
-#ifndef IP_HDRINCL
- if (bind(sndsock, (struct sockaddr *)&from, sizeof(from)) < 0) {
- perror ("traceroute: bind:");
- exit (1);
+ }
+
+ /* Determine our source address */
+ if (source == NULL) {
+ /*
+ * If a device was specified, use the interface address.
+ * Otherwise, try to determine our source address.
+ */
+ if (device != NULL)
+ setsin(from, al->addr);
+ else if ((err = findsaddr(to, from)) != NULL) {
+ Fprintf(stderr, "%s: findsaddr: %s\n",
+ prog, err);
+ exit(1);
+ }
+ } else {
+ hi = gethostinfo(source);
+ source = hi->name;
+ hi->name = NULL;
+ /*
+ * If the device was specified make sure it
+ * corresponds to the source address specified.
+ * Otherwise, use the first address (and warn if
+ * there are more than one).
+ */
+ if (device != NULL) {
+ for (i = hi->n, ap = hi->addrs; i > 0; --i, ++ap)
+ if (*ap == al->addr)
+ break;
+ if (i <= 0) {
+ Fprintf(stderr,
+ "%s: %s is not on interface %.32s\n",
+ prog, source, device);
+ exit(1);
+ }
+ setsin(from, *ap);
+ } else {
+ setsin(from, hi->addrs[0]);
+ if (hi->n > 1)
+ Fprintf(stderr,
+ "%s: Warning: %s has multiple addresses; using %s\n",
+ prog, source, inet_ntoa(from->sin_addr));
}
-#endif IP_HDRINCL
+ freehostinfo(hi);
}
- Fprintf(stderr, "traceroute to %s (%s)", hostname,
- inet_ntoa(to->sin_addr));
+ outip->ip_src = from->sin_addr;
+
+ /* Check the source address (-s), if any, is valid */
+ if (bind(sndsock, (struct sockaddr *)from, sizeof(*from)) < 0) {
+ Fprintf(stderr, "%s: bind: %s\n",
+ prog, strerror(errno));
+ exit (1);
+ }
+
+#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
+ if (setpolicy(sndsock, "in bypass") < 0)
+ errx(1, "%s", ipsec_strerror());
+
+ if (setpolicy(sndsock, "out bypass") < 0)
+ errx(1, "%s", ipsec_strerror());
+#endif /* defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) */
+
+ Fprintf(stderr, "%s to %s (%s)",
+ prog, hostname, inet_ntoa(to->sin_addr));
if (source)
Fprintf(stderr, " from %s", source);
- Fprintf(stderr, ", %d hops max, %d byte packets\n", max_ttl, datalen);
- (void) fflush(stderr);
+ Fprintf(stderr, ", %d hops max, %d byte packets\n", max_ttl, packlen);
+ (void)fflush(stderr);
- for (ttl = 1; ttl <= max_ttl; ++ttl) {
- u_long lastaddr = 0;
+ for (ttl = first_ttl; ttl <= max_ttl; ++ttl) {
+ u_int32_t lastaddr = 0;
+ int gotlastaddr = 0;
int got_there = 0;
int unreachable = 0;
+ int sentfirst = 0;
+ int loss;
Printf("%2d ", ttl);
- for (probe = 0; probe < nprobes; ++probe) {
- int cc;
+ for (probe = 0, loss = 0; probe < nprobes; ++probe) {
+ register int cc;
struct timeval t1, t2;
struct timezone tz;
- struct ip *ip;
-
- (void) gettimeofday(&t1, &tz);
- send_probe(++seq, ttl);
- while (cc = wait_for_reply(s, &from)) {
- (void) gettimeofday(&t2, &tz);
- if ((i = packet_ok(packet, cc, &from, seq))) {
- if (from.sin_addr.s_addr != lastaddr) {
- print(packet, cc, &from);
- lastaddr = from.sin_addr.s_addr;
- }
- Printf(" %g ms", deltaT(&t1, &t2));
- switch(i - 1) {
- case ICMP_UNREACH_PORT:
+ register struct ip *ip;
+ struct outdata outdata;
+
+ if (sentfirst && pausemsecs > 0)
+ usleep(pausemsecs * 1000);
+ /* Prepare outgoing data */
+ outdata.seq = ++seq;
+ outdata.ttl = ttl;
+
+ /* Avoid alignment problems by copying bytewise: */
+ (void)gettimeofday(&t1, &tz);
+ memcpy(&outdata.tv, &t1, sizeof(outdata.tv));
+
+ /* Finalize and send packet */
+ (*proto->prepare)(&outdata);
+ send_probe(seq, ttl);
+ ++sentfirst;
+
+ /* Wait for a reply */
+ while ((cc = wait_for_reply(s, from, &t1)) != 0) {
+ double T;
+ int precis;
+
+ (void)gettimeofday(&t2, &tz);
+ i = packet_ok(packet, cc, from, seq);
+ /* Skip short packet */
+ if (i == 0)
+ continue;
+ if (!gotlastaddr ||
+ from->sin_addr.s_addr != lastaddr) {
+ print(packet, cc, from);
+ lastaddr = from->sin_addr.s_addr;
+ ++gotlastaddr;
+ }
+ T = deltaT(&t1, &t2);
+#ifdef SANE_PRECISION
+ if (T >= 1000.0)
+ precis = 0;
+ else if (T >= 100.0)
+ precis = 1;
+ else if (T >= 10.0)
+ precis = 2;
+ else
+#endif
+ precis = 3;
+ Printf(" %.*f ms", precis, T);
+ if (i == -2) {
#ifndef ARCHAIC
- ip = (struct ip *)packet;
- if (ip->ip_ttl <= 1)
- Printf(" !");
-#endif ARCHAIC
- ++got_there;
- break;
- case ICMP_UNREACH_NET:
- ++unreachable;
- Printf(" !N");
- break;
- case ICMP_UNREACH_HOST:
- ++unreachable;
- Printf(" !H");
- break;
- case ICMP_UNREACH_PROTOCOL:
- ++got_there;
- Printf(" !P");
- break;
- case ICMP_UNREACH_NEEDFRAG:
- ++unreachable;
- Printf(" !F");
- break;
- case ICMP_UNREACH_SRCFAIL:
- ++unreachable;
- Printf(" !S");
- break;
- }
+ ip = (struct ip *)packet;
+ if (ip->ip_ttl <= 1)
+ Printf(" !");
+#endif
+ ++got_there;
+ break;
+ }
+ /* time exceeded in transit */
+ if (i == -1)
+ break;
+ code = i - 1;
+ switch (code) {
+
+ case ICMP_UNREACH_PORT:
+#ifndef ARCHAIC
+ ip = (struct ip *)packet;
+ if (ip->ip_ttl <= 1)
+ Printf(" !");
+#endif
+ ++got_there;
+ break;
+
+ case ICMP_UNREACH_NET:
+ ++unreachable;
+ Printf(" !N");
+ break;
+
+ case ICMP_UNREACH_HOST:
+ ++unreachable;
+ Printf(" !H");
+ break;
+
+ case ICMP_UNREACH_PROTOCOL:
+ ++got_there;
+ Printf(" !P");
+ break;
+
+ case ICMP_UNREACH_NEEDFRAG:
+ ++unreachable;
+ Printf(" !F-%d", pmtu);
+ break;
+
+ case ICMP_UNREACH_SRCFAIL:
+ ++unreachable;
+ Printf(" !S");
+ break;
+
+ case ICMP_UNREACH_FILTER_PROHIB:
+ ++unreachable;
+ Printf(" !X");
+ break;
+
+ case ICMP_UNREACH_HOST_PRECEDENCE:
+ ++unreachable;
+ Printf(" !V");
+ break;
+
+ case ICMP_UNREACH_PRECEDENCE_CUTOFF:
+ ++unreachable;
+ Printf(" !C");
+ break;
+
+ default:
+ ++unreachable;
+ Printf(" !<%d>", code);
break;
}
+ break;
}
- if (cc == 0)
+ if (cc == 0) {
+ loss++;
Printf(" *");
- (void) fflush(stdout);
+ }
+ (void)fflush(stdout);
+ }
+ if (sump) {
+ Printf(" (%d%% loss)", (loss * 100) / nprobes);
}
putchar('\n');
- if (got_there || unreachable >= nprobes-1)
- exit(0);
+ if (got_there ||
+ (unreachable > 0 && unreachable >= nprobes - 1))
+ break;
}
+ exit(0);
}
int
-wait_for_reply(sock, from)
- int sock;
- struct sockaddr_in *from;
+wait_for_reply(register int sock, register struct sockaddr_in *fromp,
+ register const struct timeval *tp)
{
- fd_set fds;
- struct timeval wait;
- int cc = 0;
- int fromlen = sizeof (*from);
-
- FD_ZERO(&fds);
- FD_SET(sock, &fds);
- wait.tv_sec = waittime; wait.tv_usec = 0;
+ fd_set *fdsp;
+ size_t nfds;
+ struct timeval now, wait;
+ struct timezone tz;
+ register int cc = 0;
+ register int error;
+ int fromlen = sizeof(*fromp);
+
+ nfds = howmany(sock + 1, NFDBITS);
+ if ((fdsp = malloc(nfds * sizeof(fd_mask))) == NULL)
+ err(1, "malloc");
+ memset(fdsp, 0, nfds * sizeof(fd_mask));
+ FD_SET(sock, fdsp);
+
+ wait.tv_sec = tp->tv_sec + waittime;
+ wait.tv_usec = tp->tv_usec;
+ (void)gettimeofday(&now, &tz);
+ tvsub(&wait, &now);
+ if (wait.tv_sec < 0) {
+ wait.tv_sec = 0;
+ wait.tv_usec = 1;
+ }
- if (select(sock+1, &fds, (fd_set *)0, (fd_set *)0, &wait) > 0)
- cc=recvfrom(s, (char *)packet, sizeof(packet), 0,
- (struct sockaddr *)from, &fromlen);
+ error = select(sock + 1, fdsp, NULL, NULL, &wait);
+ if (error == -1 && errno == EINVAL) {
+ Fprintf(stderr, "%s: botched select() args\n", prog);
+ exit(1);
+ }
+ if (error > 0)
+ cc = recvfrom(sock, (char *)packet, sizeof(packet), 0,
+ (struct sockaddr *)fromp, &fromlen);
+ free(fdsp);
return(cc);
}
-
void
-send_probe(seq, ttl)
- int seq, ttl;
+send_probe(int seq, int ttl)
{
- struct opacket *op = outpacket;
- struct ip *ip = &op->ip;
- struct udphdr *up = &op->udp;
- int i;
+ register int cc;
+
+ outip->ip_ttl = ttl;
+ outip->ip_id = htons(ident + seq);
+
+ /* XXX undocumented debugging hack */
+ if (verbose > 1) {
+ register const u_short *sp;
+ register int nshorts, i;
+
+ sp = (u_short *)outip;
+ nshorts = (u_int)packlen / sizeof(u_short);
+ i = 0;
+ Printf("[ %d bytes", packlen);
+ while (--nshorts >= 0) {
+ if ((i++ % 8) == 0)
+ Printf("\n\t");
+ Printf(" %04x", ntohs(*sp++));
+ }
+ if (packlen & 1) {
+ if ((i % 8) == 0)
+ Printf("\n\t");
+ Printf(" %02x", *(u_char *)sp);
+ }
+ Printf("]\n");
+ }
- ip->ip_off = 0;
- ip->ip_hl = sizeof(*ip) >> 2;
- ip->ip_p = IPPROTO_UDP;
- ip->ip_len = datalen;
- ip->ip_ttl = ttl;
- ip->ip_v = IPVERSION;
- ip->ip_id = htons(ident+seq);
-
- up->uh_sport = htons(ident);
- up->uh_dport = htons(port+seq);
- up->uh_ulen = htons((u_short)(datalen - sizeof(struct ip)));
- up->uh_sum = 0;
-
- op->seq = seq;
- op->ttl = ttl;
- (void) gettimeofday(&op->tv, &tz);
-
- i = sendto(sndsock, (char *)outpacket, datalen, 0, &whereto,
- sizeof(struct sockaddr));
- if (i < 0 || i != datalen) {
- if (i<0)
- perror("sendto");
- Printf("traceroute: wrote %s %d chars, ret=%d\n", hostname,
- datalen, i);
- (void) fflush(stdout);
+#if !defined(IP_HDRINCL) && defined(IP_TTL)
+ if (setsockopt(sndsock, IPPROTO_IP, IP_TTL,
+ (char *)&ttl, sizeof(ttl)) < 0) {
+ Fprintf(stderr, "%s: setsockopt ttl %d: %s\n",
+ prog, ttl, strerror(errno));
+ exit(1);
+ }
+#endif
+
+ cc = sendto(sndsock, (char *)outip,
+ packlen, 0, &whereto, sizeof(whereto));
+ if (cc < 0 || cc != packlen) {
+ if (cc < 0)
+ Fprintf(stderr, "%s: sendto: %s\n",
+ prog, strerror(errno));
+ Printf("%s: wrote %s %d chars, ret=%d\n",
+ prog, hostname, packlen, cc);
+ (void)fflush(stdout);
}
}
+#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
+int
+setpolicy(so, policy)
+ int so;
+ char *policy;
+{
+ char *buf;
+
+ buf = ipsec_set_policy(policy, strlen(policy));
+ if (buf == NULL) {
+ warnx("%s", ipsec_strerror());
+ return -1;
+ }
+ (void)setsockopt(so, IPPROTO_IP, IP_IPSEC_POLICY,
+ buf, ipsec_get_policylen(buf));
+
+ free(buf);
+
+ return 0;
+}
+#endif
double
-deltaT(t1p, t2p)
- struct timeval *t1p, *t2p;
+deltaT(struct timeval *t1p, struct timeval *t2p)
{
register double dt;
return (dt);
}
-
/*
* Convert an ICMP "type" field to a printable string.
*/
char *
-pr_type(t)
- u_char t;
+pr_type(register u_char t)
{
static char *ttab[] = {
"Echo Reply", "ICMP 1", "ICMP 2", "Dest Unreachable",
"Info Reply"
};
- if(t > 16)
+ if (t > 16)
return("OUT-OF-RANGE");
return(ttab[t]);
}
-
int
-packet_ok(buf, cc, from, seq)
- u_char *buf;
- int cc;
- struct sockaddr_in *from;
- int seq;
+packet_ok(register u_char *buf, int cc, register struct sockaddr_in *from,
+ register int seq)
{
register struct icmp *icp;
- u_char type, code;
- int hlen;
+ register u_char type, code;
+ register int hlen;
#ifndef ARCHAIC
- struct ip *ip;
+ register struct ip *ip;
ip = (struct ip *) buf;
hlen = ip->ip_hl << 2;
icp = (struct icmp *)(buf + hlen);
#else
icp = (struct icmp *)buf;
-#endif ARCHAIC
- type = icp->icmp_type; code = icp->icmp_code;
+#endif
+ type = icp->icmp_type;
+ code = icp->icmp_code;
+ /* Path MTU Discovery (RFC1191) */
+ if (code != ICMP_UNREACH_NEEDFRAG)
+ pmtu = 0;
+ else {
+#ifdef HAVE_ICMP_NEXTMTU
+ pmtu = ntohs(icp->icmp_nextmtu);
+#else
+ pmtu = ntohs(((struct my_pmtu *)&icp->icmp_void)->ipm_nextmtu);
+#endif
+ }
+ if (type == ICMP_ECHOREPLY
+ && proto->num == IPPROTO_ICMP
+ && (*proto->check)((u_char *)icp, (u_char)seq))
+ return -2;
if ((type == ICMP_TIMXCEED && code == ICMP_TIMXCEED_INTRANS) ||
type == ICMP_UNREACH) {
struct ip *hip;
- struct udphdr *up;
+ u_char *inner;
hip = &icp->icmp_ip;
hlen = hip->ip_hl << 2;
- up = (struct udphdr *)((u_char *)hip + hlen);
- if (hlen + 12 <= cc && hip->ip_p == IPPROTO_UDP &&
- up->uh_sport == htons(ident) &&
- up->uh_dport == htons(port+seq))
- return (type == ICMP_TIMXCEED? -1 : code+1);
+ inner = (u_char *)((u_char *)hip + hlen);
+ if (hlen + 12 <= cc
+ && hip->ip_p == proto->num
+ && (*proto->check)(inner, (u_char)seq))
+ return (type == ICMP_TIMXCEED ? -1 : code + 1);
}
#ifndef ARCHAIC
if (verbose) {
- int i;
- u_long *lp = (u_long *)&icp->icmp_ip;
-
- Printf("\n%d bytes from %s to %s", cc,
- inet_ntoa(from->sin_addr), inet_ntoa(ip->ip_dst));
- Printf(": icmp type %d (%s) code %d\n", type, pr_type(type),
- icp->icmp_code);
- for (i = 4; i < cc ; i += sizeof(long))
- Printf("%2d: x%8.8lx\n", i, *lp++);
+ register int i;
+ u_int32_t *lp = (u_int32_t *)&icp->icmp_ip;
+
+ Printf("\n%d bytes from %s to ", cc, inet_ntoa(from->sin_addr));
+ Printf("%s: icmp type %d (%s) code %d\n",
+ inet_ntoa(ip->ip_dst), type, pr_type(type), icp->icmp_code);
+ for (i = 4; i < cc ; i += sizeof(*lp))
+ Printf("%2d: x%8.8x\n", i, *lp++);
}
-#endif ARCHAIC
+#endif
return(0);
}
+void
+icmp_prep(struct outdata *outdata)
+{
+ struct icmp *const icmpheader = (struct icmp *) outp;
+
+ icmpheader->icmp_type = ICMP_ECHO;
+ icmpheader->icmp_id = htons(ident);
+ icmpheader->icmp_seq = htons(outdata->seq);
+ icmpheader->icmp_cksum = 0;
+ icmpheader->icmp_cksum = in_cksum((u_short *)icmpheader, protlen);
+ if (icmpheader->icmp_cksum == 0)
+ icmpheader->icmp_cksum = 0xffff;
+}
+
+int
+icmp_check(const u_char *data, int seq)
+{
+ struct icmp *const icmpheader = (struct icmp *) data;
+
+ return (icmpheader->icmp_id == htons(ident)
+ && icmpheader->icmp_seq == htons(seq));
+}
+
+void
+udp_prep(struct outdata *outdata)
+{
+ struct udphdr *const outudp = (struct udphdr *) outp;
+
+ outudp->uh_sport = htons(ident);
+ outudp->uh_dport = htons(port + outdata->seq);
+ outudp->uh_ulen = htons((u_short)protlen);
+ outudp->uh_sum = 0;
+ if (doipcksum) {
+ u_short sum = p_cksum(outip, (u_short*)outudp, protlen);
+ outudp->uh_sum = (sum) ? sum : 0xffff;
+ }
+
+ return;
+}
+
+int
+udp_check(const u_char *data, int seq)
+{
+ struct udphdr *const udp = (struct udphdr *) data;
+
+ return (ntohs(udp->uh_sport) == ident
+ && ntohs(udp->uh_dport) == port + seq);
+}
+
+void
+tcp_prep(struct outdata *outdata)
+{
+ struct tcphdr *const tcp = (struct tcphdr *) outp;
+
+ tcp->th_sport = htons(ident);
+ tcp->th_dport = htons(port + outdata->seq);
+ tcp->th_seq = (tcp->th_sport << 16) | tcp->th_dport;
+ tcp->th_ack = 0;
+ tcp->th_off = 5;
+ tcp->th_flags = TH_SYN;
+ tcp->th_sum = 0;
+
+ if (doipcksum) {
+ u_short sum = p_cksum(outip, (u_short*)tcp, protlen);
+ tcp->th_sum = (sum) ? sum : 0xffff;
+ }
+}
+
+int
+tcp_check(const u_char *data, int seq)
+{
+ struct tcphdr *const tcp = (struct tcphdr *) data;
+
+ return (ntohs(tcp->th_sport) == ident
+ && ntohs(tcp->th_dport) == port + seq);
+}
void
-print(buf, cc, from)
- u_char *buf;
- int cc;
- struct sockaddr_in *from;
+gre_prep(struct outdata *outdata)
{
- struct ip *ip;
- int hlen;
+ struct grehdr *const gre = (struct grehdr *) outp;
+
+ gre->flags = htons(0x2001);
+ gre->proto = htons(port);
+ gre->length = 0;
+ gre->callId = htons(ident + outdata->seq);
+}
+
+int
+gre_check(const u_char *data, int seq)
+{
+ struct grehdr *const gre = (struct grehdr *) data;
+
+ return(ntohs(gre->proto) == port
+ && ntohs(gre->callId) == ident + seq);
+}
+
+void
+gen_prep(struct outdata *outdata)
+{
+ u_int16_t *const ptr = (u_int16_t *) outp;
+
+ ptr[0] = htons(ident);
+ ptr[1] = htons(port + outdata->seq);
+}
+
+int
+gen_check(const u_char *data, int seq)
+{
+ u_int16_t *const ptr = (u_int16_t *) data;
+
+ return(ntohs(ptr[0]) == ident
+ && ntohs(ptr[1]) == port + seq);
+}
+
+void
+print(register u_char *buf, register int cc, register struct sockaddr_in *from)
+{
+ register struct ip *ip;
+ register int hlen;
ip = (struct ip *) buf;
hlen = ip->ip_hl << 2;
Printf(" %s", inet_ntoa(from->sin_addr));
else
Printf(" %s (%s)", inetname(from->sin_addr),
- inet_ntoa(from->sin_addr));
+ inet_ntoa(from->sin_addr));
if (verbose)
- Printf (" %d bytes to %s", cc, inet_ntoa (ip->ip_dst));
+ Printf(" %d bytes to %s", cc, inet_ntoa (ip->ip_dst));
}
+/*
+ * Checksum routine for UDP and TCP headers.
+ */
+u_short
+p_cksum(struct ip *ip, u_short *data, int len)
+{
+ static struct ipovly ipo;
+ u_short sumh, sumd;
+ u_long sumt;
+
+ ipo.ih_pr = ip->ip_p;
+ ipo.ih_len = htons(len);
+ ipo.ih_src = ip->ip_src;
+ ipo.ih_dst = ip->ip_dst;
+
+ sumh = in_cksum((u_short*)&ipo, sizeof(ipo)); /* pseudo ip hdr cksum */
+ sumd = in_cksum((u_short*)data, len); /* payload data cksum */
+ sumt = (sumh << 16) | (sumd);
+
+ return ~in_cksum((u_short*)&sumt, sizeof(sumt));
+}
-#ifdef notyet
/*
* Checksum routine for Internet Protocol family headers (C Version)
*/
u_short
-in_cksum(addr, len)
- u_short *addr;
- int len;
+in_cksum(register u_short *addr, register int len)
{
register int nleft = len;
register u_short *w = addr;
answer = ~sum; /* truncate to 16 bits */
return (answer);
}
-#endif notyet
/*
* Subtract 2 timeval structs: out = out - in.
- * Out is assumed to be >= in.
+ * Out is assumed to be within about LONG_MAX seconds of in.
*/
void
-tvsub(out, in)
- register struct timeval *out, *in;
+tvsub(register struct timeval *out, register struct timeval *in)
{
+
if ((out->tv_usec -= in->tv_usec) < 0) {
- out->tv_sec--;
+ --out->tv_sec;
out->tv_usec += 1000000;
}
out->tv_sec -= in->tv_sec;
}
-
/*
* Construct an Internet address representation.
* If the nflag has been supplied, give
* numeric value, otherwise try for symbolic name.
*/
char *
-inetname(in)
- struct in_addr in;
+inetname(struct in_addr in)
{
register char *cp;
- static char line[50];
- struct hostent *hp;
- static char domain[MAXHOSTNAMELEN + 1];
+ register struct hostent *hp;
static int first = 1;
+ static char domain[MAXHOSTNAMELEN + 1], line[MAXHOSTNAMELEN + 1];
if (first && !nflag) {
first = 0;
- if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
- (cp = index(domain, '.')))
- (void) strcpy(domain, cp + 1);
- else
- domain[0] = 0;
+ if (gethostname(domain, sizeof(domain) - 1) < 0)
+ domain[0] = '\0';
+ else {
+ cp = strchr(domain, '.');
+ if (cp == NULL) {
+ hp = gethostbyname(domain);
+ if (hp != NULL)
+ cp = strchr(hp->h_name, '.');
+ }
+ if (cp == NULL)
+ domain[0] = '\0';
+ else {
+ ++cp;
+ (void)strncpy(domain, cp, sizeof(domain) - 1);
+ domain[sizeof(domain) - 1] = '\0';
+ }
+ }
}
- cp = 0;
if (!nflag && in.s_addr != INADDR_ANY) {
- hp = gethostbyaddr((char *)&in, sizeof (in), AF_INET);
- if (hp) {
- if ((cp = index(hp->h_name, '.')) &&
- !strcmp(cp + 1, domain))
- *cp = 0;
- cp = hp->h_name;
+ hp = gethostbyaddr((char *)&in, sizeof(in), AF_INET);
+ if (hp != NULL) {
+ if ((cp = strchr(hp->h_name, '.')) != NULL &&
+ strcmp(cp + 1, domain) == 0)
+ *cp = '\0';
+ (void)strncpy(line, hp->h_name, sizeof(line) - 1);
+ line[sizeof(line) - 1] = '\0';
+ return (line);
}
}
- if (cp)
- (void) strcpy(line, cp);
- else {
- in.s_addr = ntohl(in.s_addr);
-#define C(x) ((x) & 0xff)
- Sprintf(line, "%lu.%lu.%lu.%lu", C(in.s_addr >> 24),
- C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr));
+ return (inet_ntoa(in));
+}
+
+struct hostinfo *
+gethostinfo(register char *hostname)
+{
+ register int n;
+ register struct hostent *hp;
+ register struct hostinfo *hi;
+ register char **p;
+ register u_int32_t addr, *ap;
+
+ if (strlen(hostname) > 64) {
+ Fprintf(stderr, "%s: hostname \"%.32s...\" is too long\n",
+ prog, hostname);
+ exit(1);
+ }
+ hi = calloc(1, sizeof(*hi));
+ if (hi == NULL) {
+ Fprintf(stderr, "%s: calloc %s\n", prog, strerror(errno));
+ exit(1);
}
- return (line);
+ addr = inet_addr(hostname);
+ if ((int32_t)addr != -1) {
+ hi->name = strdup(hostname);
+ hi->n = 1;
+ hi->addrs = calloc(1, sizeof(hi->addrs[0]));
+ if (hi->addrs == NULL) {
+ Fprintf(stderr, "%s: calloc %s\n",
+ prog, strerror(errno));
+ exit(1);
+ }
+ hi->addrs[0] = addr;
+ return (hi);
+ }
+
+ hp = gethostbyname(hostname);
+ if (hp == NULL) {
+ Fprintf(stderr, "%s: unknown host %s\n", prog, hostname);
+ exit(1);
+ }
+ if (hp->h_addrtype != AF_INET || hp->h_length != 4) {
+ Fprintf(stderr, "%s: bad host %s\n", prog, hostname);
+ exit(1);
+ }
+ hi->name = strdup(hp->h_name);
+ for (n = 0, p = hp->h_addr_list; *p != NULL; ++n, ++p)
+ continue;
+ hi->n = n;
+ hi->addrs = calloc(n, sizeof(hi->addrs[0]));
+ if (hi->addrs == NULL) {
+ Fprintf(stderr, "%s: calloc %s\n", prog, strerror(errno));
+ exit(1);
+ }
+ for (ap = hi->addrs, p = hp->h_addr_list; *p != NULL; ++ap, ++p)
+ memcpy(ap, *p, sizeof(*ap));
+ return (hi);
+}
+
+void
+freehostinfo(register struct hostinfo *hi)
+{
+ if (hi->name != NULL) {
+ free(hi->name);
+ hi->name = NULL;
+ }
+ free((char *)hi->addrs);
+ free((char *)hi);
+}
+
+void
+getaddr(register u_int32_t *ap, register char *hostname)
+{
+ register struct hostinfo *hi;
+
+ hi = gethostinfo(hostname);
+ *ap = hi->addrs[0];
+ freehostinfo(hi);
}
void
-usage()
+setsin(register struct sockaddr_in *sin, register u_int32_t addr)
{
- (void)fprintf(stderr,
-"usage: traceroute [-dnrv] [-m max_ttl] [-p port#] [-q nqueries]\n\t\
-[-s src_addr] [-t tos] [-w wait] host [data size]\n");
+
+ memset(sin, 0, sizeof(*sin));
+#ifdef HAVE_SOCKADDR_SA_LEN
+ sin->sin_len = sizeof(*sin);
+#endif
+ sin->sin_family = AF_INET;
+ sin->sin_addr.s_addr = addr;
+}
+
+/* String to value with optional min and max. Handles decimal and hex. */
+int
+str2val(register const char *str, register const char *what,
+ register int mi, register int ma)
+{
+ register const char *cp;
+ register int val;
+ char *ep;
+
+ if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
+ cp = str + 2;
+ val = (int)strtol(cp, &ep, 16);
+ } else
+ val = (int)strtol(str, &ep, 10);
+ if (*ep != '\0') {
+ Fprintf(stderr, "%s: \"%s\" bad value for %s \n",
+ prog, str, what);
+ exit(1);
+ }
+ if (val < mi && mi >= 0) {
+ if (mi == 0)
+ Fprintf(stderr, "%s: %s must be >= %d\n",
+ prog, what, mi);
+ else
+ Fprintf(stderr, "%s: %s must be > %d\n",
+ prog, what, mi - 1);
+ exit(1);
+ }
+ if (val > ma && ma >= 0) {
+ Fprintf(stderr, "%s: %s must be <= %d\n", prog, what, ma);
+ exit(1);
+ }
+ return (val);
+}
+
+struct outproto *
+setproto(char *pname)
+{
+ struct outproto *proto;
+ int i;
+
+ for (i = 0; protos[i].name != NULL; i++) {
+ if (strcasecmp(protos[i].name, pname) == 0) {
+ break;
+ }
+ }
+ proto = &protos[i];
+ if (proto->name == NULL) { /* generic handler */
+ struct protoent *pe;
+ u_long pnum;
+
+ /* Determine the IP protocol number */
+ if ((pe = getprotobyname(pname)) != NULL)
+ pnum = pe->p_proto;
+ else
+ pnum = str2val(optarg, "proto number", 1, 255);
+ proto->num = pnum;
+ }
+ return proto;
+}
+
+void
+usage(void)
+{
+ extern char version[];
+
+ Fprintf(stderr, "Version %s\n", version);
+ Fprintf(stderr,
+ "Usage: %s [-dFInrSvx] [-g gateway] [-i iface] [-f first_ttl]\n"
+ "\t[-m max_ttl] [-p port] [-P proto] [-q nqueries] [-s src_addr]\n"
+ "\t[-t tos] [-w waittime] [-z pausemsecs] host [packetlen]\n", prog);
exit(1);
}
--- /dev/null
+/*
+ * Copyright (c) 2000
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may 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.
+ *
+ * @(#) $Id: traceroute.h,v 1.2 2004/08/08 00:27:54 lindak Exp $ (LBL)
+ */
+
+extern char *prog;
+
+void setsin(struct sockaddr_in *, u_int32_t);
--- /dev/null
+char version[] = "1.4a12+Darwin";
PROF_LIBS = $(LIBS)
+HEADER_PATHS =\
+ -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders/
NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc
# Makefile API), which are rules that get invoked before and after the install
# target runs. Such rules should be specified with the '::' syntax rather than
# a single colon.
+
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man8
+ install -c -m 444 trpt.8 $(DSTROOT)/usr/share/man/man8/trpt.8
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
#
# Note: on MS Windows, executables, have an extension, so rules and dependencies
# for generated tools should use $(EXECUTABLE_EXT) on the end.
+
+after_install:
+ install -d $(DSTROOT)/usr/share/man/man1
+ install -c -m 444 wall.1 $(DSTROOT)/usr/share/man/man1/wall.1
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <rpc/xdr.h>
#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
+#include <sys/param.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include <sys/signal.h>
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
}
int
-acl_check_host(addr)
+yp_acl_check_host(addr)
struct in_addr *addr;
{
struct aclent *p;
}
int
-acl_init(file)
+yp_acl_init(file)
char *file;
{
char data_line[1024];
}
int
-acl_securenet(file)
+yp_acl_securenet(file)
char *file;
{
char data_line[1024];
}
void
-acl_reset()
+yp_acl_reset()
{
struct aclent *p;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
};
__BEGIN_DECLS
-int acl_check_host __P((struct in_addr *));
-int acl_init __P((char *));
-int acl_securenet __P((char *));
-void acl_reset __P((void));
+int yp_acl_check_host __P((struct in_addr *));
+int yp_acl_init __P((char *));
+int yp_acl_securenet __P((char *));
+void yp_acl_reset __P((void));
__END_DECLS
#endif /* !_ACL_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _YPLOG_H_
#define _YPLOG_H_
+#include <stdarg.h>
+
__BEGIN_DECLS
void yplog __P((const char *, ...));
-void vyplog __P((const char *, _BSD_VA_LIST_));
+void vyplog __P((const char *, va_list));
void ypopenlog __P((void));
void ypcloselog __P((void));
__END_DECLS
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
}
if (aclfile != NULL) {
- (void)acl_init(aclfile);
+ (void)yp_acl_init(aclfile);
} else {
- (void)acl_securenet(YP_SECURENET_FILE);
+ (void)yp_acl_securenet(YP_SECURENET_FILE);
}
if (xflag) {
exit(1);
void
sig_hup()
{
- acl_reset();
+ yp_acl_reset();
if (aclfile != NULL) {
yplog("sig_hup: reread %s",aclfile);
- (void)acl_init(aclfile);
+ (void)yp_acl_init(aclfile);
} else {
yplog("sig_hup: reread %s",YP_SECURENET_FILE);
- (void)acl_securenet(YP_SECURENET_FILE);
+ (void)yp_acl_securenet(YP_SECURENET_FILE);
}
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
{
static char *result;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
YPLOG("null_2: caller=[%s].%d, auth_ok=%s",
inet_ntoa(caller->sin_addr), ntohs(caller->sin_port), TORF(ok));
{
static bool_t result; /* is domain_served? */
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
static char domain_path[MAXPATHLEN];
struct stat finfo;
{
static bool_t result; /* is domain served? */
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
static char domain_path[MAXPATHLEN];
struct stat finfo;
{
static ypresp_val res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure = ypdb_secure(argp->domain,argp->map);
if (strchr(argp->domain, '/') || strchr(argp->map, '/'))
{
static ypresp_key_val res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure = ypdb_secure(argp->domain,argp->map);
if (strchr(argp->domain, '/') || strchr(argp->map, '/'))
{
static ypresp_key_val res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure = ypdb_secure(argp->domain,argp->map);
if (strchr(argp->domain, '/') || strchr(argp->map, '/'))
{
static ypresp_xfr res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
pid_t pid;
char tid[11];
char prog[11];
{
static char *res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
YPLOG( "clear_2: caller=[%s].%d, auth_ok=%s, opt=%s",
inet_ntoa(caller->sin_addr), ntohs(caller->sin_port), TORF(ok),
static ypresp_all res;
pid_t pid;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure = ypdb_secure(argp->domain,argp->map);
if (strchr(argp->domain, '/') || strchr(argp->map, '/'))
static ypresp_master res;
static peername nopeer = "";
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure = ypdb_secure(argp->domain,argp->map);
if (strchr(argp->domain, '/') || strchr(argp->map, '/'))
{
static ypresp_order res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure = ypdb_secure(argp->domain,argp->map);
if (strchr(argp->domain, '/'))
{
static ypresp_maplist res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
static char domain_path[MAXPATHLEN];
struct stat finfo;
DIR *dirp = NULL;
{
static char *result;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
YPLOG("null_1: caller=[%s].%d, auth_ok=%s",
inet_ntoa(caller->sin_addr), ntohs(caller->sin_port), TORF(ok));
{
static bool_t result; /* is domain_served? */
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
static char domain_path[MAXPATHLEN];
struct stat finfo;
{
static bool_t result; /* is domain served? */
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
static char domain_path[MAXPATHLEN];
struct stat finfo;
{
static ypresponse res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure;
if (strchr(argp->ypmatch_req_domain, '/') ||
{
static ypresponse res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure;
if (strchr(argp->ypfirst_req_domain, '/') ||
{
static ypresponse res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure;
if (strchr(argp->ypnext_req_domain, '/') ||
ypresp_order order;
ypresp_master master;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure;
if (strchr(argp->yppoll_req_domain, '/') ||
struct svc_req *rqstp;
{
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure;
pid_t pid;
char yppush_proc[] = YPPUSH_PROC;
struct svc_req *rqstp;
{
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure;
pid_t pid;
char ypxfr_proc[] = YPXFR_PROC;
{
char *res;
struct sockaddr_in *caller = svc_getcaller(rqstp->rq_xprt);
- int ok = acl_check_host(&caller->sin_addr);
+ int ok = yp_acl_check_host(&caller->sin_addr);
int secure;
pid_t pid;
char ypxfr_proc[] = YPXFR_PROC;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _YPLOG_H_
#define _YPLOG_H_
+#include <stdarg.h>
+
__BEGIN_DECLS
void yplog __P((const char *, ...));
-void vyplog __P((const char *, _BSD_VA_LIST_));
+void vyplog __P((const char *, va_list));
void ypopenlog __P((void));
void ypcloselog __P((void));
__END_DECLS
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/