LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-06-2012, 11:47 AM   #1
pavaneee
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Rep: Reputation: Disabled
Red face ICMP Type 69 error


I have written ping program.sometimes i am getting the response and sometimes i am getting ICMP Type 69 error. What could be the problem ?


17:31:14.581000 IP 192.0.0.1 > 192.0.4.1: ICMP type-#69, length 28
17:37:19.477000 IP 192.0.0.1 > 192.0.4.1: ICMP type-#69, length 28
 
Old 02-06-2012, 12:08 PM   #2
es0teric
Member
 
Registered: Apr 2007
Distribution: Ubuntu
Posts: 105

Rep: Reputation: 19
The ping packet is probably malformed or not being interpreted/unpacked correctly. If you give more details about how the program works, someone may be able to help you troubleshoot the code.
 
Old 02-06-2012, 12:19 PM   #3
pavaneee
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Here you go...Plz help me.


#include <sys/ioctl.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <linux/ip.h>
#include <linux/icmp.h>
#include <string.h>
#include <unistd.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <errno.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/time.h>


#define MAX_NUMBER_OF_NODES 5
struct cal_nodes{
int rackno;
int slotno;
int instanceno;
int card_type;
int node_type;
int node_state;
unsigned int nodeIP;
char* ipaddr;
};

struct ping_param {
int nbytes;
char interface[10];
int iRetries;
int inpackets;
int idelay;
int idelaybtwpings;
};
struct cal_nodes node_details[MAX_NUMBER_OF_NODES];
void* PingNodes(char* argv);
unsigned short in_cksum(unsigned short *, int);
void parse_argvs(char**, char*, char* );
void usage();
char* getip();

void* PingingThread(void * pa)
{
int iter = 0;
struct ping_param param;

param.nbytes = 100;
strcpy(param.interface,"eth-vf1.3073");
param.iRetries = 5;
param.inpackets = 1;
param.idelay = 2000;
param.idelaybtwpings= 300;


while(iter < 4)
{
PingNodes(node_details[iter].ipaddr);//here IP address is coming as properly. I have printed and verified.
iter++;
}
return 0;
}

void* PingNodes(char* argv)
{
struct sockaddr_in connection;
struct iphdr* ip;
struct iphdr* ip_reply;
struct icmphdr* icmp;
char* SendBuff;
char* RecvBuff;
char* RecvBuff1;
char* packet;
char* buffer;
char* buffer1;
int sockfd1;
int sockfd;
int optval;
int addrlen;
int err;
struct ifreq Interface;
int ibytes;
fd_set read_flags,write_flags,exce_flags;
struct timeval waitd;
char dst_addr[15];
char src_addr[15];

strcpy(dst_addr,argv);
/*
* allocate all necessary memory
*/
SendBuff = malloc(70);
RecvBuff = malloc(70);
RecvBuff1 = malloc(70);
if (SendBuff && RecvBuff && RecvBuff1)
{
memset(SendBuff,0,70);
memset(RecvBuff,0,70);
memset(RecvBuff1,0,70);
}

if ((sockfd1 = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1)
{
perror("socket sockfd1 Creation Failure");
exit(EXIT_FAILURE);
}

if ((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1)
{
perror("socket sockfd Creation Failure");
exit(EXIT_FAILURE);
}
setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &optval, sizeof(int));

memset(&Interface, 0, sizeof(Interface));
strncpy(Interface.ifr_ifrn.ifrn_name, "eth-vf1.3073", IFNAMSIZ);
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, &Interface, sizeof(Interface)) < 0)
{
printf("Error in binding");
close(sockfd);
}

ioctl(sockfd, SIOCGIFADDR, &Interface);
printf("%s\n", inet_ntoa(((struct sockaddr_in *)&Interface.ifr_addr)->sin_addr));

strcpy(src_addr,inet_ntoa(((struct sockaddr_in *)&Interface.ifr_addr)->sin_addr));
printf("Source address: %s\n", src_addr);


ip = malloc(sizeof(struct iphdr));
ip_reply = malloc(sizeof(struct iphdr));
icmp = malloc(sizeof(struct icmphdr));
packet = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr));
buffer1 = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr));
buffer = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr));
memset(packet,0,sizeof(struct iphdr) + sizeof(struct icmphdr));
memset(buffer1,0,sizeof(struct iphdr) + sizeof(struct icmphdr));
memset(buffer,0,sizeof(struct iphdr) + sizeof(struct icmphdr));
ip = (struct iphdr*) packet;
icmp = (struct icmphdr*) (packet + sizeof(struct iphdr));

/*
* here the ip packet is set up except checksum
*/
ip->ihl = 5;
ip->version = 4;
ip->tos = 0;
ip->tot_len = sizeof(struct iphdr) + sizeof(struct icmphdr);
ip->id = htons(random());
ip->ttl = 255;
ip->protocol = IPPROTO_ICMP;
ip->saddr = inet_addr(src_addr);
ip->daddr = inet_addr(dst_addr);

icmp->type = 8;
icmp->code = 0;
icmp->un.echo.id = 0;
icmp->un.echo.sequence = 0;
icmp-> checksum = in_cksum((unsigned short *)icmp, sizeof(struct icmphdr));
ip->check = in_cksum((unsigned short *)ip, sizeof(struct iphdr));

connection.sin_family = AF_INET;
connection.sin_addr.s_addr = inet_addr(dst_addr);

/*
* now the packet is sent
*/

if((ibytes = sendto(sockfd, packet, ip->tot_len, 0, (struct sockaddr *)&connection, sizeof(struct sockaddr))) <= 0 )
{
printf("Sendto Error\n");
} else {
printf("\nSent %d byte packet to %s and %ul\n", (int)ibytes, dst_addr,connection.sin_addr.s_addr );
ibytes = 0;
}
addrlen = sizeof(connection);
while(1)
{
waitd.tv_sec = 90; // Make select wait up to 90 second for data
waitd.tv_usec = 0; // and 0 milliseconds.

FD_ZERO(&read_flags); // Zero the flags ready for using
FD_ZERO(&write_flags);
FD_ZERO(&exce_flags);
FD_SET(sockfd1, &read_flags);
FD_SET(sockfd, &read_flags);
FD_SET(sockfd1, &write_flags);
FD_SET(sockfd, &write_flags);
FD_SET(sockfd1, &exce_flags);
FD_SET(sockfd, &exce_flags);

err=select(sockfd+1, &read_flags,&write_flags,&exce_flags,&waitd);
if(err < 0)
{
printf("\nTimeout in Select\n");
continue;
}
if(FD_ISSET(sockfd, &read_flags))
{
if ((ibytes = recvfrom(sockfd, buffer1, sizeof(struct iphdr) + sizeof(struct icmphdr), 0, (struct sockaddr *)&connection, &addrlen)) == -1)
{

printf("Hello Pavan you got error in recvfrom \n");
perror("recvfrom2 failed");
}
else
{
printf("Received same address ethvf1.3073 %d byte reply from %s ; %ul:\n", (int)ibytes, dst_addr,connection.sin_addr.s_addr);
ip_reply = (struct iphdr*)buffer1;
printf("ID: %d\n", ntohs(ip_reply->id));
printf("TTL: %d\n", ip_reply->ttl);
}

if ((ibytes=recvfrom(sockfd, buffer, sizeof(struct iphdr) + sizeof(struct icmphdr), 0, (struct sockaddr *)0, (int*)0))>0)
{
printf("\nNo.of bytes received on sockfd eth-vf1.3073 deom any address: %d",ibytes);
ibytes = 0;
ip_reply = (struct iphdr*)buffer;
printf("ID: %d\n", ntohs(ip_reply->id));
printf("TTL: %d\n", ip_reply->ttl);

}else {
printf("\nrecvfrom Failed on sockfdnew: %d\n",ibytes);
perror("recvfrom0 failed");
}
FD_CLR(sockfd, &read_flags);
}

if(FD_ISSET(sockfd1, &read_flags))
{
if ((ibytes = recvfrom(sockfd1, buffer, sizeof(struct iphdr) + sizeof(struct icmphdr), 0, (struct sockaddr *)&connection, &addrlen))
== -1)
{

printf("Hello Pavan you got error in recvfrom \n");
perror("recvfrom2 failed");
}
else
{
printf("Received %d byte reply from1.general.same address. %s ; %ul:\n", (int)ibytes, dst_addr,connection.sin_addr.s_addr);
ip_reply = (struct iphdr*)buffer;
printf("ID: %d\n", ntohs(ip_reply->id));
printf("TTL: %d\n", ip_reply->ttl);
break;
}
FD_CLR(sockfd1, &read_flags);
}
if(FD_ISSET(sockfd, &exce_flags))
{
printf("\nException in sockfd\n");
}
}
close(sockfd1);
close(sockfd);
return 0;
}

void parse_argvs(char** argv, char* dst, char* src)
{
int i;
if(!(*(argv + 1)))
{
/* there are no options on the command line */
usage();
exit(EXIT_FAILURE);
}
if (*(argv + 1) && (!(*(argv + 2))))
{
/*
* only one argument provided
* assume it is the destination server
* source address is local host
*/
strncpy(dst, *(argv + 1), 15);
strncpy(src, getip(), 15);
printf("\n parse_argvs1.src : %s \n",src);
return;
}
else if ((*(argv + 1) && (*(argv + 2))))
{
/*
* both the destination and source address are defined
* for now only implemented is a source address and
* destination address
*/
strncpy(dst, *(argv + 1), 15);
i = 2;
while(*(argv + i + 1))
{
if (strncmp(*(argv + i), "-s", 2) == 0)
{
strncpy(src, *(argv + i + 1), 15);
printf("\n parse_argvs2.src : %s \n",src);
break;
}
i++;
}

}
}

void usage()
{
fprintf(stderr, "\nUsage: pinger [destination] <-s [source]>\n");
fprintf(stderr, "Destination must be provided\n");
fprintf(stderr, "Source is optional\n\n");
}

char* getip()
{
char buffer[256];
struct hostent* h;

gethostname(buffer, 256);
h = gethostbyname(buffer);
printf("\nGethostname returns : %s\n",inet_ntoa(*(struct in_addr *)h->h_addr));
return inet_ntoa(*(struct in_addr *)h->h_addr);

}
/*
* in_cksum --
* Checksum routine for Internet Protocol
* family headers (C Version)
*/
unsigned short in_cksum(unsigned short *addr, int len)
{
register int sum = 0;
u_short answer = 0;
register u_short *w = addr;
register int nleft = len;
/*
* Our algorithm is simple, using a 32 bit accumulator (sum), we add
* sequential 16 bit words to it, and at the end, fold back all the
* carry bits from the top 16 bits into the lower 16 bits.
*/
while (nleft > 1)
{
sum += *w++;
nleft -= 2;
}
/* mop up an odd byte, if necessary */
if (nleft == 1)
{
*(u_char *) (&answer) = *(u_char *) w;
sum += answer;
}
/* add back carry outs from top 16 bits to low 16 bits */
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
sum += (sum >> 16); /* add carry */
answer = ~sum; /* truncate to 16 bits */
return (answer);
}
int main(int argc, char* argv[])
{
int rvalue1 = 0;
int rvalue2 = 0;
pthread_t CMThread;
pthread_t PingThread;

rvalue2 = pthread_create(&PingThread, NULL,PingingThread, (void *)0 );
if (rvalue2 != 0) {
perror("pthread_create error");
printf("error in thread creation\n");
return 0;
}
pthread_join(CMThread, NULL);
pthread_join(PingThread, NULL);
return 0;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending ICMP messages of type 3 when packet size exceeds MTU of the interface nmb1081 Linux - Networking 1 04-13-2008 10:14 PM
kernel: 10.x.x.x sent an invalid ICMP type 11, code 0 error to a broadcast: x.x.x.x Felipe Linux - Networking 0 02-25-2008 02:20 AM
invalid icmp type 3 code 3 error to a broadcast nkeever Linux - Newbie 3 06-12-2006 03:15 PM
invalid ICMP type 11 icedude Linux - Networking 5 01-17-2006 08:29 AM
icmpquery: Unknown ICMP message received (type 13) phsythax Linux - Networking 1 11-17-2005 03:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration