#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/icmp6.h>
int main(int argc, char *argv[])
{
int sd;
int on;
int status;
struct icmp6_hdr icmpv6={0};
sd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
if (sd < 0)
{
perror ("Failed to get socket descriptor ");
return -2;
}
on = 1;
if ((status = setsockopt (sd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on, sizeof (on))) < 0) {
perror ("setsockopt to IPV6_RECVHOPLIMIT failed ");
return -1;
}
status = recv(sd, &icmpv6, sizeof(struct icmp6_hdr), 0);
if (status < 0)
{
perror ("recv error ");
return -1;
}
printf("icmpv6 type:%d\n", icmpv6.icmp6_type);
close(sd);
return 0;
}
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/icmp6.h>
int main(int argc, char *argv[])
{
int sd;
int on;
int status;
struct icmp6_hdr icmpv6={0};
sd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
if (sd < 0)
{
perror ("Failed to get socket descriptor ");
return -2;
}
on = 1;
if ((status = setsockopt (sd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on, sizeof (on))) < 0) {
perror ("setsockopt to IPV6_RECVHOPLIMIT failed ");
return -1;
}
status = recv(sd, &icmpv6, sizeof(struct icmp6_hdr), 0);
if (status < 0)
{
perror ("recv error ");
return -1;
}
printf("icmpv6 type:%d\n", icmpv6.icmp6_type);
close(sd);
return 0;
}
댓글
댓글 쓰기