/*
* Rdisc (this program) was developed by Sun Microsystems, Inc. and is
* provided for unrestricted use provided that this legend is included on
* all tape media and as a part of the software program in whole or part.
* Users may copy or modify Rdisc without charge, and they may freely
* distribute it.
*
* RDISC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Rdisc is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY RDISC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
/* Do not use "improved" glibc version! */
#include <linux/limits.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <malloc.h>
#include <sys/ioctl.h>
#include <linux/if.h>
#include <linux/route.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
/*
* The next include contains all defs and structures for multicast
* that are not in SunOS 4.1.x. On a SunOS 4.1.x system none of this code
* is ever used because it does not support multicast
* Fraser Gardiner - Sun Microsystems Australia
*/
#include <netdb.h>
#include <arpa/inet.h>
#include <string.h>
#include <syslog.h>
#include "SNAPSHOT.h"
struct interface
{
struct in_addr address; /* Used to identify the interface */
struct in_addr localaddr; /* Actual address if the interface */
int preference;
int flags;
struct in_addr bcastaddr;
struct in_addr remoteaddr;
struct in_addr netmask;
int ifindex;
char name[IFNAMSIZ];
};
/*
* TBD
* Use 255.255.255.255 for broadcasts - not the interface broadcast
* address.
*/
#define ALLIGN(ptr) (ptr)
static int join(int sock, struct sockaddr_in *sin);
static void solicitor(struct sockaddr_in *);
#ifdef RDISC_SERVER
static void advertise(struct sockaddr_in *, int lft);
#endif
static char *pr_name(struct in_addr addr);
static void pr_pack(char *buf, int cc, struct sockaddr_in *from);
static void age_table(int time);
static void record_router(struct in_addr router, int preference, int ttl);
static void add_route(struct in_addr addr);
static void del_route(struct in_addr addr);
static void rtioctl(struct in_addr addr, int op);
static int support_multicast(void);
static int sendbcast(int s, char *packet, int packetlen);
static int sendmcast(int s, char *packet, int packetlen, struct sockaddr_in *);
static int sendbcastif(int s, char *packet, int packetlen, struct interface *ifp);
static int sendmcastif(int s, char *packet, int packetlen, struct sockaddr_in *sin, struct interface *ifp);
static int is_directly_connected(struct in_addr in);
static void initlog(void);
static void discard_table(void);
static void init(void);
#define ICMP_ROUTER_ADVERTISEMENT 9
#define ICMP_ROUTER_SOLICITATION 10
#define ALL_HOSTS_ADDRESS "224.0.0.1"
#define ALL_ROUTERS_ADDRESS "224.0.0.2"
#define MAXIFS 32
#if !defined(__GLIBC__) || __GLIBC__ < 2
/* For router advertisement */
struct icmp_ra
{
u_char icmp_type; /* type of message, see below */
u_char icmp_code; /* type sub code */
u_short icmp_cksum; /* ones complement cksum of struct */
u_char icmp_num_addrs;
u_char icmp_wpa; /* Words per address */
short icmp_lifetime;
};
struct icmp_ra_addr
{
__u32 ira_addr;
__u32 ira_preference;
};
#else
#define icmp_ra icmp
#endif
/* Router constants */
#define MAX_INITIAL_ADVERT_INTERVAL 16
#define MAX_INITIAL_ADVERTISEMENTS 3
#define MAX_RESPONSE_DELAY 2 /* Not used */
/* Host constants */
#define MAX_SOLICITATIONS 3
#define SOLICITATION_INTERVAL 3
#define MAX_SOLICITATION_DELAY 1 /* Not used */
#define INELIGIBLE_PREF 0x80000000 /* Maximum negative */
#define MAX_ADV_INT 600
/* Statics */
static int num_interfaces;
static struct interface *interfaces;
static int interfaces_size; /* Number of elements in interfaces */
#define MAXPACKET 4096 /* max packet size */
/* fraser */
int debugfile;
char usage[] =
"Usage: rdisc [-b] [-d] [-s] [-v] [-f] [-a] [-V] [send_address] [receive_address]\n"
#ifdef RDISC_SERVER
" rdisc -r [-b] [-d] [-s] [-v] [-f] [-a] [-V] [-p <preference>] [-T <secs>] \n"
" [send_address] [receive_address]\n"
#endif
;
int s; /* Socket file descriptor */
struct sockaddr_in whereto;/* Address to send to */
/* Common variables */
int verbose = 0;
int debug = 0;
int trace = 0;
int solicit = 0;
int ntransmitted = 0;
int nreceived = 0;
int forever = 0; /* Never give up on host. If 0 defer fork until
* first response.
*/
#ifdef RDISC_SERVER
/* Router variables */
int responder;
int max_adv_int = MAX_ADV_INT;
int min_adv_int;
int lifetime;
int initial_advert_interval = MAX_INITIAL_ADVERT_INTERVAL;
int initial_advertisements = MAX_INITIAL_ADVERTISEMENTS;
int preference = 0; /* Setable with -p option */
#endif
/* Host variables */
int max_solicitations = MAX_SOLICITATIONS;
unsigned int solicitation_interval = SOLICITATION_INTERVAL;
int best_preference = 1; /* Set to record only the router(s) with the
best preference in the kernel. Not set
puts all routes in the kernel. */
static void graceful_finish(void);
static void finish(void);
static void timer(void);
static void initifs(void);
static u_short in_cksum(u_short *addr, int len);
static int logging = 0;
#define logerr(fmt...) ({ if (logging) syslog(LOG_ERR, fmt); \
else fprintf(stderr, fmt); })
#define logtrace(fmt...) ({ if (logging) syslog(LOG_INFO, fmt); \
else fprintf(stderr, fmt); })
#define logdebug(fmt...) ({ if (logging) syslog(LOG_DEBUG, fmt); \
else fprintf(stderr, fmt); })
static void logperror(char *str);
static __inline__ int isbroadcast(struct sockaddr_in *sin)
{
return (sin->sin_addr.s_addr == INADDR_BROADCAST);
}
static __inline__ int ismulticast(struct sockaddr_in *sin)
{
return IN_CLASSD(ntohl(sin->sin_addr.s_addr));
}
static void prusage(void)
{
(void) fprintf(stderr, usage);
exit(1);
}
void do_fork(void)
{
int t;
pid_t pid;
if (trace)
return;
if ((pid=fork()) != 0)
exit(0);
for (t = 0; t < OPEN_MAX; t++)
if (t != s)
close(t);
setsid();
initlog();
}
void signal_setup(int signo, void (*handler)(void))
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = (void (*)(int))handler;
#ifdef SA_INTERRUPT
sa.sa_flags = SA_INTERRUPT;
#endif
sigaction(signo, &sa, NULL);
}
/*
* M A I N
*/
char *sendaddress, *recvaddress;
int main(int argc, char **argv)
{
struct sockaddr_in from;
char **av = argv;
struct sockaddr_in *to = &whereto;
struct sockaddr_in joinaddr;
sigset_t sset, sset_empty;
#ifdef RDISC_SERVER
int val;
min_adv_int =( max_adv_int * 3 / 4);
lifetime = (3*max_adv_int);
#endif
argc--, av++;
while (argc > 0 && *av[0] == '-') {
while (*++av[0]) {
switch (*av[0]) {
case 'd':
debug = 1;
break;
case 't':
trace = 1;
break;
case 'v':
verbose++;
break;
case 's':
solicit = 1;
break;
#ifdef RDISC_SERVER
case 'r':
responder = 1;
break;
#endif
case 'a':
best_preference = 0;
break;
case 'b':
best_preference = 1;
break;
case 'f':
forever = 1;
break;
case 'V':
printf("rdisc utility, iputils-ss%s\n", SNAPSHOT);
exit(0);
#ifdef
iputils-ss020927.zip_iputi_iputils-ss
版权申诉
140 浏览量
2022-09-21
17:30:13
上传
评论
收藏 156KB ZIP 举报
邓凌佳
- 粉丝: 65
- 资源: 1万+
最新资源
- 基于 Java的班级管理系统课程设计
- 深入探索Suno AI:教程、元标签与案例分析.pdf
- 超市会员积分管理系统主要用于实现了企业管理数据统计等
- 基于 Java的班级管理系统
- MyBatis 动态 SQL:灵活而强大的查询构建器.pdf
- com.accordion.prettyo.apk
- 毕业设计:基于SSM的mysql-ssm软件bug管理系统(源码 + 数据库 + 说明文档)
- MTSQL8.0.35windows(64bit)-mysql-installer-community-8.0.35.0
- 人工智能引领音乐创作新时代之Suno AI
- Public-bicycle-usage-forecast-master.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈