Date: Fri, 23 Sep 2005 03:42:11 -0500 From: Tyler T <espartano.list@gmail.com> To: freebsd-questions@freebsd.org Subject: Problen with a little C program Message-ID: <9385b1fc0509230142733b4f94@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
hi list, firts sorry for my english.
for hobbye i am trying to write a little program in C lenguage, the
program create a ip header and show the values of ip header whitout
send any data, only create the header, the program is this:
//////BEGIN////////
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netdb.h>
struct ip *create_iph(char *ips, char *ipd, int sec);
void show_iph(struct ip *iph);
int main(){
struct ip *iph;
iph =3D create_iph("127.0.0.1","127.0.0.1",10);
showiph(iph);
free(iph);
iph=3DNULL;
return 0;
}
struct ip *create_iph(char *ips, char *ipd, int sec){
struct ip *iph;
iph =3D malloc(sizeof(struct ip));
iph->ip_v =3D 4;
iph->ip_hl =3D 5;
iph->ip_tos =3D 0;
iph->ip_len =3D sizeof(struct ip) + sizeof(struct tcphdr);
iph->ip_id =3D htons(sec); //cambiar el id por el numero de port a =
scanear
iph->ip_ttl =3D 255;
iph->ip_p =3D 6;
iph->ip_sum =3D 0; //checksum
iph->ip_src.s_addr =3D inet_addr(ips);
iph->ip_dst.s_addr =3D inet_addr(ipd);
return iph;
}
void show_iph(struct ip *iph){
printf("version %d\n",iph->ip_v);
printf("header leng (ihl) %d\n",iph->ip_hl);
printf("total leng %d\n",iph->ip_len);
printf("identification %d\n",iph->ip_id);
printf("TTL %d\n",iph->ip_ttl);
printf("protocol %d\n",iph->ip_p);
printf("checksum %d\n",iph->ip_sum);
printf("type of service (TOS) %d\n",iph->ip_tos);
printf("ip source %s\n",inet_ntoa(iph->ip_src));
printf("ip destination %s\n",inet_ntoa(iph->ip_dst));
}
////////END///////
when i execute: "gcc -o sock_raw sock_raw.c" i obtain:
-bash-2.05b$ gcc -o sock_raw sock_raw.c
In file included from sock_raw.c:7:
/usr/include/netinet/ip.h:160: error: syntax error before "n_long"
/usr/include/netinet/ip.h:163: error: syntax error before "n_long"
-bash-2.05b$
my system is: FreeBSD 5.4 STABLE
and my gcc version is: gcc version 3.4.2 [FreeBSD] 20040728
thanks in advance.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9385b1fc0509230142733b4f94>
