Проблемы с tcphdr (sock raw)

Автор: iam0x70 Дата: 02.09.2003 12:58 Я вот решил научиться программированию сырых сокетов, компилирую эту программу
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <sys/types.h>
#include <netinet/in.h>
#define P 25
#include <netinet/ip.h>
unsigned short int csum (unsigned short *buf, int nwords)
{
unsigned long sum;
for(sum=0;nwords>0;nwords--)
{
sum+=*buf++;
sum=(sum>>16)+(sum&0xffff);
sum+=(sum>>16);
return ~sum;
}


}


int main(void)
{
int one=1;

int s = socket (PF_INET,SOCK_RAW,IPPROTO_TCP);
char datagram[4096];
struct ip *iph = (struct ip*) datagram;
struct tcphdr *tcpmy= (struct tcphdr *)datagram + sizeof(struct ip);
struct sockaddr_in sin;
sin.sin_family= AF_INET;
sin.sin_port=htons(P);
sin.sin_addr.s_addr=inet_addr("127.0.0.1";-);

memset (datagram,0,4096);

iph->ip_hl=5;
iph->ip_v=4;
iph->ip_tos=0;
iph->ip_len=sizeof(struct ip)+sizeof(struct tcphdr);
iph->ip_id=htonl(112);
iph->ip_off=0;
iph->ip_ttl=112;
iph->ip_p=6;
iph->ip_sum=0;
iph->ip_src.s_addr=inet_addr("1.2.3.4";-);
iph->ip_dst.s_addr=sin.sin_addr.s_addr;
tcpmy->th_sport=htons(112);
tcpmy->th_dport=htons(P);
tcpmy->th_seq=random();
tcpmy->th_ack=0;
tcpmy->th_x2=0;
tcpmy->th_off=0;
tcpmy->th_flags=TH_SYN;
tcpmy->th_win=htonl(65535);
tcpmy->th_sum=0;
tcpmy->th_urp=0;

iph->ip_sum=csum((unsigned short *)datagram,iph->ip_len>>1);
setsockopt(s,IPPROTO_IP,IP_HDRINCL,(char *) &one,sizeof(s));

for(;;-)
sendto(s,datagram,(sizeof(struct ip)+sizeof(struct tcphdr)),0,(struct sockaddr *)&sin,sizeof(sin));

return 0;

}

и получаю

programms/syn.c: In function `main':
programms/syn.c:48: structure has no member named `th_sport'
programms/syn.c:49: structure has no member named `th_dport'
programms/syn.c:50: structure has no member named `th_seq'
programms/syn.c:51: structure has no member named `th_ack'
programms/syn.c:52: structure has no member named `th_x2'
programms/syn.c:53: structure has no member named `th_off'
programms/syn.c:54: structure has no member named `th_flags'
programms/syn.c:54: `TH_SYN' undeclared (first use in this function)
programms/syn.c:54: (Each undeclared identifier is reported only once
programms/syn.c:54: for each function it appears in.)
programms/syn.c:55: structure has no member named `th_win'
programms/syn.c:56: structure has no member named `th_sum'
programms/syn.c:57: structure has no member named `th_urp'

Странно, ведь netinet/tcp.h я включил. Непонимаю что твориться!?
Re: проблемы с tcphdr (sock raw) 02.09.2003 15:32zakon less netinet/tcp.h

-D__FAVOR_BSD если я не ошибаюсь
Re: проблемы с tcphdr (sock raw) 02.09.2003 21:52iam0x70 Пробовал компилировать с ней все-равно тоже выдает.
Re: проблемы с tcphdr (sock raw) 03.09.2003 10:55zakon Извините:
-D_BSD_SOURCE
RSS-материал