View | Details | Raw Unified | Return to bug 6832
Collapse All | Expand All

(-)ping.8 (+8 lines)
Lines 48-53 Link Here
48
.Op Fl l Ar preload
48
.Op Fl l Ar preload
49
.Op Fl p Ar pattern
49
.Op Fl p Ar pattern
50
.Op Fl s Ar packetsize
50
.Op Fl s Ar packetsize
51
.Op Fl S Ar src_addr
51
.Bo
52
.Bo
52
.Ar host |
53
.Ar host |
53
.Op Fl L
54
.Op Fl L
Lines 194-199 Link Here
194
with the 8 bytes of
195
with the 8 bytes of
195
.Tn ICMP
196
.Tn ICMP
196
header data.
197
header data.
198
.It Fl S Ar src_addr
199
Use the following IP address as the source address in outgoing packets.
200
On hosts with more than one IP address, this option can be used to
201
force the source address to be something other than the IP address
202
of the interface the probe packet is sent on.  If the IP address
203
is not one of this machine's interface addresses, an error is
204
returned and nothing is sent.
197
.It Fl T Ar ttl
205
.It Fl T Ar ttl
198
Set the IP Time To Live for multicasted packets.
206
Set the IP Time To Live for multicasted packets.
199
This flag only applies if the ping destination is a multicast address.
207
This flag only applies if the ping destination is a multicast address.
(-)ping.c (-3 / +25 lines)
Lines 184-197 Link Here
184
{
184
{
185
	struct timeval last, intvl;
185
	struct timeval last, intvl;
186
	struct hostent *hp;
186
	struct hostent *hp;
187
	struct sockaddr_in *to;
187
	struct sockaddr_in *to, sin;
188
	struct termios ts;
188
	struct termios ts;
189
	register int i;
189
	register int i;
190
	int ch, hold, packlen, preload, sockerrno, almost_done = 0;
190
	int ch, hold, packlen, preload, sockerrno, almost_done = 0;
191
	struct in_addr ifaddr;
191
	struct in_addr ifaddr;
192
	unsigned char ttl, loop;
192
	unsigned char ttl, loop;
193
	u_char *datap, *packet;
193
	u_char *datap, *packet;
194
	char *target, hnamebuf[MAXHOSTNAMELEN];
194
	char *source = NULL, *target, hnamebuf[MAXHOSTNAMELEN];
195
	char *ep;
195
	char *ep;
196
	u_long ultmp;
196
	u_long ultmp;
197
#ifdef IP_OPTIONS
197
#ifdef IP_OPTIONS
Lines 217-223 Link Here
217
	preload = 0;
217
	preload = 0;
218
218
219
	datap = &outpack[8 + sizeof(struct timeval)];
219
	datap = &outpack[8 + sizeof(struct timeval)];
220
	while ((ch = getopt(argc, argv, "I:LQRT:c:adfi:l:np:qrs:v")) != -1) {
220
	while ((ch = getopt(argc, argv, "I:LQRS:T:c:adfi:l:np:qrs:v")) != -1) {
221
		switch(ch) {
221
		switch(ch) {
222
		case 'a':
222
		case 'a':
223
			options |= F_AUDIBLE;
223
			options |= F_AUDIBLE;
Lines 301-306 Link Here
301
				     optarg);
301
				     optarg);
302
			datalen = ultmp;
302
			datalen = ultmp;
303
			break;
303
			break;
304
		case 'S':
305
			source = optarg;
306
			break;
304
		case 'T':		/* multicast TTL */
307
		case 'T':		/* multicast TTL */
305
			ultmp = strtoul(optarg, &ep, 0);
308
			ultmp = strtoul(optarg, &ep, 0);
306
			if (*ep || ep == optarg || ultmp > 255)
309
			if (*ep || ep == optarg || ultmp > 255)
Lines 322-327 Link Here
322
		usage(argv[0]);
325
		usage(argv[0]);
323
	target = argv[optind];
326
	target = argv[optind];
324
327
328
	if (source) {
329
		bzero((char *)&sin, sizeof(sin));
330
		sin.sin_family = AF_INET;
331
		if (inet_aton(source, &sin.sin_addr) == 0) {
332
			hp = gethostbyname2(source, AF_INET);
333
			if (!hp)
334
				errx(EX_NOHOST, "cannot resolve %s: %s",
335
				     source, hstrerror(h_errno));
336
337
			sin.sin_len = sizeof sin;
338
			if (hp->h_length > sizeof(sin.sin_addr))
339
				errx(1,"gethostbyname2 returned an illegal address");
340
			memcpy(&sin.sin_addr, hp->h_addr_list[0], sizeof sin.sin_addr);
341
		}
342
		if (bind(s, (struct sockaddr *)&sin, sizeof sin) == -1)
343
			err(1, "bind");
344
	}
345
325
	bzero((char *)&whereto, sizeof(struct sockaddr));
346
	bzero((char *)&whereto, sizeof(struct sockaddr));
326
	to = (struct sockaddr_in *)&whereto;
347
	to = (struct sockaddr_in *)&whereto;
327
	to->sin_family = AF_INET;
348
	to->sin_family = AF_INET;
Lines 1251-1256 Link Here
1251
	fprintf(stderr,
1272
	fprintf(stderr,
1252
		"usage: %s [-QRadfnqrv] [-c count] [-i wait] [-l preload] "
1273
		"usage: %s [-QRadfnqrv] [-c count] [-i wait] [-l preload] "
1253
		"[-p pattern]\n       [-s packetsize] "
1274
		"[-p pattern]\n       [-s packetsize] "
1275
		"[-S src_addr]\n       "
1254
		"[host | [-L] [-I iface] [-T ttl] mcast-group]\n",
1276
		"[host | [-L] [-I iface] [-T ttl] mcast-group]\n",
1255
		argv0);
1277
		argv0);
1256
	exit(EX_USAGE);
1278
	exit(EX_USAGE);

Return to bug 6832