Académique Documents
Professionnel Documents
Culture Documents
h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip_icmp.h>
#include <netinet/icmp6.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "openvswitch/vlog.h"
#include "ops-utils.h"
#define DEFDATALEN 56
#define MAXICMPLEN 76
#define MAXIPLEN 60
#define PACKETSIZE 64
VLOG_DEFINE_THIS_MODULE(ping_util);
struct packet
{
struct icmphdr hdr;
char msg[PACKETSIZE-sizeof(struct icmphdr)];
};
/*--------------------------------------------------------------------
*--- checksum - standard 1s complement checksum ---
*--------------------------------------------------------------------*/
unsigned short checksum(void *b, int len)
{ unsigned short *buf = b;
unsigned int sum=0;
unsigned short result;
memset(&pckt, 0, sizeof(pckt));
pckt.hdr.type = ICMP_ECHO;
pckt.hdr.un.echo.id = 1234;
pckt.hdr.un.echo.sequence = 1;
pckt.hdr.checksum = checksum(&pckt, sizeof(pckt));
sockopt = 2;
setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, (char *) &sockopt,
sizeof(sockopt));
if (c < 0 ) {
VLOG_ERR("error:sendto: errno = %s",strerror(errno) );
close(pingsock);
return c;
}
return 0;
}