Skip to content
11 changes: 2 additions & 9 deletions src/socket4.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,13 @@ static int outgoing_src_addr_set_ipv4 = 0;

int open_ping_socket_ipv4(int *socktype)
{
struct protoent* proto;
int s;

/* confirm that ICMP is available on this machine */
if ((proto = getprotobyname("icmp")) == NULL)
crash_and_burn("icmp: unknown protocol");

/* create raw socket for ICMP calls (ping) */
*socktype = SOCK_RAW;
s = socket(AF_INET, *socktype, proto->p_proto);
int s = socket(AF_INET, *socktype, IPPROTO_ICMP);
if (s < 0) {
/* try non-privileged icmp (works on Mac OSX without privileges, for example) */
*socktype = SOCK_DGRAM;
s = socket(AF_INET, *socktype, proto->p_proto);
s = socket(AF_INET, *socktype, IPPROTO_ICMP);
if (s < 0) {
return -1;
}
Expand Down
11 changes: 2 additions & 9 deletions src/socket6.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,13 @@ static int outgoing_src_addr_set_ipv6 = 0;

int open_ping_socket_ipv6(int *socktype)
{
struct protoent* proto;
int s;

/* confirm that ICMP6 is available on this machine */
if ((proto = getprotobyname("ipv6-icmp")) == NULL)
crash_and_burn("ipv6-icmp: unknown protocol");

/* create raw socket for ICMP6 calls (ping) */
*socktype = SOCK_RAW;
s = socket(AF_INET6, *socktype, proto->p_proto);
int s = socket(AF_INET6, *socktype, IPPROTO_ICMPV6);
if (s < 0) {
/* try non-privileged icmp6 (works on Mac OSX without privileges, for example) */
*socktype = SOCK_DGRAM;
s = socket(AF_INET6, *socktype, proto->p_proto);
s = socket(AF_INET6, *socktype, IPPROTO_ICMPV6);
if (s < 0) {
return -1;
}
Expand Down
Loading