<commit_before>/*
 * route-bsd.c
 *
 * Copyright (c) 2001 <NAME> <<EMAIL>>
 * Copyright (c) 1999 <NAME> <<EMAIL>>
 *
 * $Id: route-bsd.c 555 2005-02-10 05:18:38Z dugsong $
 */

#include "config.h"

#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
#endif
#ifdef HAVE_STREAMS_MIB2
#include <sys/stream.h>
#include <sys/tihdr.h>
#include <sys/tiuser.h>
#include <inet/common.h>
#include <inet/mib2.h>
#include <inet/ip.h>
#undef IP_ADDR_LEN
#include <stropts.h>
#elif defined(HAVE_STREAMS_ROUTE)
#include <sys/stream.h>
#include <sys/stropts.h>
#endif
#ifdef HAVE_GETKERNINFO
#include <sys/kinfo.h>
#endif

#define route_t	oroute_t	/* XXX - unixware */
#include <net/route.h>
#undef route_t
#include <net/if.h>
#include <netinet/in.h>

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "dnet.h"

/* Unix Network Programming, 3rd edition says that sockaddr structures in
   rt_msghdr should be padded so their addresses start on a multiple of
   sizeof(u_long). But on 64-bit Mac OS X 10.6 at least, this is false. Apple's
   netstat code uses 4-byte padding, not 8-byte. This is relevant for IPv6
   addresses, for which sa_len == 28.

http://www.opensource.apple.com/source/network_cmds/network_cmds-329.2.2/netstat.tproj/route.c
*/
#ifdef __APPLE__
#define RT_MSGHDR_ALIGNMENT sizeof(uint32_t)
#else
#define RT_MSGHDR_ALIGNMENT sizeof(unsigned long)
#endif

#ifdef RT_ROUNDUP
/* NetBSD defines this macro rounding to 64-bit boundaries.
   http://fxr.watson.org/fxr/ident?v=NETBSD;i=RT_ROUNDUP */
#define ROUNDUP(a) RT_ROUNDUP(a)
#else
#define ROUNDUP(a) \
	((a) > 0 ? (1 + (((a) - 1) | (RT_MSGHDR_ALIGNMENT - 1))) : RT_MSGHDR_ALIGNMENT)
#endif

#ifdef HAVE_SOCKADDR_SA_LEN
#define NEXTSA(s) \
	((struct sockaddr *)((u_char *)(s) + ROUNDUP((s)->sa_len)))
#else
#define NEXTSA(s) \
	((struct sockaddr *)((u_char *)(s) + ROUNDUP(sizeof(*(s)))))
#endif

struct route_handle {
	int	fd;
	int	seq;
#ifdef HAVE_STREAMS_MIB2
	int	ip_fd;
#endif<commit_msg>Only use RT_ROUNDUP on NetBSD<commit_after>/*
 * route-bsd.c
 *
 * Copyright (c) 2001 <NAME> <<EMAIL>>
 * Copyright (c) 1999 <NAME> <<EMAIL>>
 *
 * $Id: route-bsd.c 555 2005-02-10 05:18:38Z dugsong $
 */

#include "config.h"

#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
#endif
#ifdef HAVE_STREAMS_MIB2
#include <sys/stream.h>
#include <sys/tihdr.h>
#include <sys/tiuser.h>
#include <inet/common.h>
#include <inet/mib2.h>
#include <inet/ip.h>
#undef IP_ADDR_LEN
#include <stropts.h>
#elif defined(HAVE_STREAMS_ROUTE)
#include <sys/stream.h>
#include <sys/stropts.h>
#endif
#ifdef HAVE_GETKERNINFO
#include <sys/kinfo.h>
#endif

#define route_t	oroute_t	/* XXX - unixware */
#include <net/route.h>
#undef route_t
#include <net/if.h>
#include <netinet/in.h>

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "dnet.h"

/* Unix Network Programming, 3rd edition says that sockaddr structures in
   rt_msghdr should be padded so their addresses start on a multiple of
   sizeof(u_long). But on 64-bit Mac OS X 10.6 at least, this is false. Apple's
   netstat code uses 4-byte padding, not 8-byte. This is relevant for IPv6
   addresses, for which sa_len == 28.

http://www.opensource.apple.com/source/network_cmds/network_cmds-329.2.2/netstat.tproj/route.c
*/
#ifdef __APPLE__
#define RT_MSGHDR_ALIGNMENT sizeof(uint32_t)
#else
#define RT_MSGHDR_ALIGNMENT sizeof(unsigned long)
#endif

#if defined(RT_ROUNDUP) && defined(__NetBSD__)
/* NetBSD defines this macro rounding to 64-bit boundaries.
   http://fxr.watson.org/fxr/ident?v=NETBSD;i=RT_ROUNDUP */
#define ROUNDUP(a) RT_ROUNDUP(a)
#else
#define ROUNDUP(a) \
	((a) > 0 ? (1 + (((a) - 1) | (RT_MSGHDR_ALIGNMENT - 1))) : RT_MSGHDR_ALIGNMENT)
#endif

#ifdef HAVE_SOCKADDR_SA_LEN
#define NEXTSA(s) \
	((struct sockaddr *)((u_char *)(s) + ROUNDUP((s)->sa_len)))
#else
#define NEXTSA(s) \
	((struct sockaddr *)((u_char *)(s) + ROUNDUP(sizeof(*(s)))))
#endif

struct route_handle {
	int	fd;
	int	seq;
#ifdef HAVE_STREAMS_MIB2
	int	ip_fd;
#endif
{'fraction_non_alphanumeric': 0.1551194135729487, 'fraction_numerical': 0.024592102151808938, 'mean_word_length': 4.708502024291498, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2173453', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1750, 'n_words': 420}