diff options
Diffstat (limited to 'ping.c')
-rw-r--r-- | ping.c | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * $Id: ping.c,v 1.7 2000/01/26 20:06:48 erik Exp $ | 2 | * $Id: ping.c,v 1.8 2000/01/29 05:52:40 erik Exp $ |
3 | * Mini ping implementation for busybox | 3 | * Mini ping implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
@@ -312,18 +312,14 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from) | |||
312 | 312 | ||
313 | static void ping(char *host) | 313 | static void ping(char *host) |
314 | { | 314 | { |
315 | struct protoent *proto; | 315 | struct protoent *proto=NULL; |
316 | struct hostent *h; | 316 | struct hostent *h; |
317 | char buf[MAXHOSTNAMELEN]; | 317 | char buf[MAXHOSTNAMELEN]; |
318 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; | 318 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
319 | int sockopt; | 319 | int sockopt; |
320 | 320 | ||
321 | if (!(proto = getprotobyname("icmp"))) { | 321 | proto = getprotobyname("icmp"); |
322 | /* getprotobyname failed, so just silently force | 322 | if ((pingsock = socket(AF_INET, SOCK_RAW, (proto)? proto->p_proto : 1 )) < 0) { /* 1 == ICMP */ |
323 | * proto->p_proto to have the correct value for "icmp" */ | ||
324 | proto->p_proto = 1; | ||
325 | } | ||
326 | if ((pingsock = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) { /* 1 == ICMP */ | ||
327 | if (errno == EPERM) { | 323 | if (errno == EPERM) { |
328 | fprintf(stderr, "ping: permission denied. (are you root?)\n"); | 324 | fprintf(stderr, "ping: permission denied. (are you root?)\n"); |
329 | } else { | 325 | } else { |