Hi,
I am using RAW sockets (Solaris 8) to send out a VRRP protocol packet
out to a multicast group. For some reason, I am not seeing the IP
header information that I am sending out. Instead I see TTL = 1,
Protocol=2 and etc. Can someone help me out in identifying the likely
problem in this code?
int vrrp_send_pkt( vrrp_rt *vsrv, char *buffer, int buflen )
{
struct sockaddr_in from;
int len;
int fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if( fd < 0 ){
perror( "socket" );
return -1;
}
int on = 1;
int geton = 1;
int retSetSock = setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &on,
sizeof(on));
char lBuffer[72];
struct ip ip;
struct udphdr udphdr;
ip.ip_hl = 5;
ip.ip_v = 4;
ip.ip_tos = 0;
ip.ip_len = ip.ip_hl*4 + vrrp_hd_len( vsrv );
ip.ip_len = htons(ip.ip_len);
ip.ip_id = ++ip_id;
ip.ip_off = 0;
ip.ip_ttl = VRRP_IP_TTL;
ip.ip_p = IPPROTO_VRRP;
ip.ip_src.s_addr = htonl(vsrv->vif.ipaddr);
ip.ip_dst.s_addr = htonl(INADDR_VRRP_GROUP);
/* checksum must be done last */
ip.ip_sum = in_csum( (u_short*)(&ip), ip.ip_hl*4, 0 );
memcpy(lBuffer+sizeof(ip), &udphdr, sizeof(udphdr));
/* build the address */
memset( &from, 0 , sizeof(from));
//strcpy( from.sa_data, vsrv->vif.ifname );
/* send the data */
from.sin_family = AF_INET;
from.sin_addr.s_addr=inet_addr("224.0.0.18");
from.sin_port=htonl(5000);
len = sendto( fd, &ip, 40, 0, (struct sockaddr *) &from,
sizeof(from) );
printf("len=%d\n",len);
close( fd );
return len;
Thanks,Quote:}
Devender