Date: Thu, 17 Apr 1997 00:32:36 -0600 (MDT) From: Marc Slemko <marcs@znep.com> To: hackers@freebsd.org Subject: source address for ping causes crash? Message-ID: <Pine.BSF.3.95.970417002625.12316G-100000@alive.znep.com>
next in thread | raw e-mail | index | archive | help
I was testing a copy of ping with the following changes to allow you to
specify the local address with the -S option. Appeared to be working fine
(and is, in some situations, a very useful thing to have) but then the box
I was testing it on rebooted itself. Was not near the console so I don't
know if it paniced or just rebooted.
Any reason what I'm trying shouldn't work? There are around 75 alias
interfaces on lo0 on that box which is running 2.2 from a couple of weeks
ago. Don't have time to track the cause (or run it on a box I'm sitting
in front of) now, but if no one has any suggestions I will look into it
when I get a chance.
Index: ping.c
===================================================================
RCS file: /usr/cvs/src/sbin/ping/ping.c,v
retrieving revision 1.8.2.8
diff -c -r1.8.2.8 ping.c
*** ping.c 1997/03/03 09:44:16 1.8.2.8
--- ping.c 1997/04/17 06:25:08
***************
*** 121,126 ****
--- 121,127 ----
char rcvd_tbl[MAX_DUP_CHK / 8];
struct sockaddr whereto; /* who to ping */
+ struct sockaddr_in *wherefrom; /* source address */
int datalen = DEFDATALEN;
int s; /* socket file descriptor */
u_char outpack[MAXPACKET];
***************
*** 184,190 ****
preload = 0;
datap = &outpack[8 + sizeof(struct timeval)];
! while ((ch = getopt(argc, argv, "I:LQRT:c:adfi:l:np:qrs:v")) != -1)
switch(ch) {
case 'a':
options |= F_AUDIBLE;
--- 185,191 ----
preload = 0;
datap = &outpack[8 + sizeof(struct timeval)];
! while ((ch = getopt(argc, argv, "I:LQRS:T:c:adfi:l:np:qrs:v")) != -1)
switch(ch) {
case 'a':
options |= F_AUDIBLE;
***************
*** 276,281 ****
--- 277,302 ----
exit(1);
}
break;
+ case 'S': /* source address */
+ wherefrom = (struct sockaddr_in *)
+ calloc(1, sizeof(struct sockaddr_in));
+ wherefrom->sin_family = AF_INET;
+ wherefrom->sin_len = sizeof(struct sockaddr_in);
+ wherefrom->sin_port = htons(INADDR_ANY);
+ wherefrom->sin_addr.s_addr = inet_addr(optarg);
+ if (wherefrom->sin_addr.s_addr == (u_int)-1) {
+ hp = gethostbyname(optarg);
+ if (!hp) {
+ (void)fprintf(stderr,
+ "ping: unknown host %s\n", optarg);
+ exit(1);
+ }
+ wherefrom->sin_family = hp->h_addrtype;
+ if (hp->h_length > sizeof(wherefrom->sin_addr))
+ errx(1,"gethostbyname returned an illegal address");
+ bcopy(hp->h_addr, (caddr_t)&wherefrom->sin_addr.s_addr, hp->h_length);
+ }
+ break;
case 'T': /* multicast TTL */
i = atoi(optarg);
if (i < 0 || i > 255) {
***************
*** 522,527 ****
--- 543,551 ----
/* compute ICMP checksum here */
icp->icmp_cksum = in_cksum((u_short *)icp, cc);
+
+ if (wherefrom && bind(s, (struct sockaddr *)wherefrom, sizeof(struct sockaddr_in)))
+ err(1, "bind (source address)");
i = sendto(s, (char *)outpack, cc, 0, &whereto,
sizeof(struct sockaddr));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95.970417002625.12316G-100000>
