Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-07-2008, 01:03 AM   #1
Registered: Jan 2008
Posts: 40

Rep: Reputation: 15
Thumbs down error: ‘for’ loop initial declaration

how you will deal this problem

error: ‘for’ loop initial declaration used outside C99 mode
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h> 
#include <netdb.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <netinet/ip_icmp.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
//#include <iostream.h>
#include <sys/types.h>
#include <unistd.h>

unsigned short in_checksum(unsigned short*,int );
void counter(unsigned int);
void banner(void);

int main(int argc,char **argv)

int sockfd;
const int on = 1;
int datalen, packlen, targetlen;
datalen = 0;

char *targetip;
char *broadcastip;

char readbuffer[1500];
char sendbuffer[1500];

struct sockaddr_in broadcast,target;

struct iphdr *ipheader;
struct icmp *icmpheader;

if(argc != 3)
printf("\n\nbash#./rurf <Target> <Broadcast>\n\n");
return (-1);

if((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
printf("\n\n Are you root?\n\n");
return 0;

setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));

broadcastip = argv[2];
targetip= argv[1];

broadcast.sin_family = AF_INET;
broadcast.sin_family = htons(0);
if(inet_pton(AF_INET, broadcastip, &broadcast.sin_addr) <= 0)
   printf("\n\nFehler: inet_pton() broadcastip\n\n");
   return 0;
if(inet_pton(AF_INET, targetip, &target.sin_addr) <= 0)
   printf("\n\nFehler: inet_pton() targetip\n\n");
   return 0;

ipheader = (struct iphdr *)sendbuffer;
icmpheader = (struct icmp *) (sendbuffer + sizeof(struct iphdr)); 

ipheader->ihl = 5;
ipheader->version = 4;
ipheader->tos = 0;
ipheader->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmp) + 
ipheader->id = 0; 
ipheader->frag_off = 0;
ipheader->ttl = 200;
ipheader->protocol = IPPROTO_ICMP;
ipheader->check = in_checksum( (u_short *)ipheader, sizeof(struct iphdr));  
ipheader->saddr = target.sin_addr.s_addr;
ipheader->daddr = broadcast.sin_addr.s_addr;

printf("\n\nPing from <<argv[1]<< to the broadcast <<argv[2]<< are sent");
printf("\nPings: ");

for(unsigned int i= 0;;i++)
icmpheader->icmp_type = ICMP_ECHO;
icmpheader->icmp_code = 0;
icmpheader->icmp_seq = i;
icmpheader->icmp_cksum = in_checksum( (u_short *)icmpheader, 
                                    sizeof(struct icmp) + datalen);

sendto(sockfd,sendbuffer,sizeof(struct iphdr) + sizeof(struct icmphdr) 
      + datalen,0,(struct sockaddr *)&broadcast,sizeof(struct sockaddr));
return 0;
Old 06-07-2008, 01:08 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
main(int argc,char **argv)

  int sockfd;
  const int on = 1;
  int datalen = 0, packlen = 0, targetlen = 0;
  unsigned int i = 0;
  for(i= 0; ; i++)
    icmpheader->icmp_type = ICMP_ECHO;
    icmpheader->icmp_code = 0;
    icmpheader->icmp_seq = i;
Old 06-07-2008, 01:33 AM   #3
Registered: Mar 2005
Location: INDIA
Posts: 79

Rep: Reputation: 16
if you are using gcc, the declaration is not understood by iso c90 which is by default. optionally, you can also use -std=c99 option to tell your compiler to enable c99 flag to understand c99 features. This will solve your this problem but others may creep in.
Old 06-07-2008, 11:31 AM   #4
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Even though the most recent GCC doesn't have *total* C99 support, it does provide lots of useful features and I would recommend that you use it. Additionally, GCC's C99 mode should be backwards compatible with C90 and thus should not introduce additional problems (other than warnings) for compiling code written in C90. It's for good reason that systems like FreeBSD have moved over to an increasingly C99 (with the ever-closer goal of a totaly C99) codebase.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
error: previous declaration of xxxxx was here horacioemilio Programming 5 07-15-2009 06:00 PM
error: ‘for’ loop initial declaration nasim751 Linux - Software 2 06-07-2008 06:35 AM
Implicit Declaration Compiler Error Programming 1 12-11-2005 05:24 AM
g++ compiler error declaration does not declare anything Basiltp Programming 4 10-11-2004 12:29 PM
cpp forward declaration error ashirazi Programming 5 09-17-2004 01:55 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 AM.

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