Linux-Bulgaria.ORG
навигация

 

начало

пощенски списък

архив на групата

семинари ...

документи

как да ...

 

 

Предишно писмо Следващо писмо Предишно по тема Следващо по тема По Дата По тема (thread)

Re: lug-bg: SOCK_RAW source


  • Subject: Re: lug-bg: SOCK_RAW source
  • From: close_forever@xxxxxxxxx (skk)
  • Date: Fri, 13 Aug 1999 00:39:34 -0700 (PDT)



/*  Towa e napulno raboteshta 
        programa za Micro$oft Visual C++
        Za da se kompilira s gcc sa
        neobhodimi minimalni kozmetichni
        promeni. Ako niakoj se zainteresuwa
        moga da mu pratia i koregirania
        kod za linux, no pod linux niama
        problemi! Waprosa e kak da stane
        pod windows...
*/

#pragma pack(4)

#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>

/* The IP header !!!!
   We going to need it 
   if somebody solve 
   the problem :))))
   but...
   useless now :((((
*/
typedef struct iphdr {
        unsigned int h_len:4;          
        unsigned int version:4;        
        unsigned char tos;             
        unsigned short total_len;      
        unsigned short ident;          
        unsigned short frag_and_flags; 
        unsigned char  ttl; 
        unsigned char proto;           
        unsigned short checksum;       

        unsigned int sourceIP;
        unsigned int destIP;

}IpHeader;

#define STATUS_FAILED 0xFFFF

int main(int argc, char **argv){

  WSADATA wsaData;
  SOCKET sockRaw;
  int bread;
  BOOL value = TRUE;
  int optval;
  unsigned int optlen=sizeof(optval);

  if (WSAStartup(MAKEWORD(2,2),&wsaData) != 0){
        fprintf(stderr,"WSAStartup failed:
%d\n",GetLastError());
        ExitProcess(STATUS_FAILED);
  }

  sockRaw = WSASocket(AF_INET,
                   SOCK_RAW,
                   IPPROTO_RAW,
                   NULL, 0,0);
  
  if (sockRaw == INVALID_SOCKET) {
fprintf(stderr,"WSASocket() failed:
%d\n",WSAGetLastError());
        ExitProcess(STATUS_FAILED);
  }
  
  bread = getsockopt(sockRaw,
                IPPROTO_IP,
                IP_HDRINCL,
                (char*)&optval,
                &optlen);
  
  if(bread == SOCKET_ERROR) {
printf("failed to get current status of IP_HDRINCL:
%d\n", WSAGetLastError());
  } else {
    printf("current status of IP_HDRINCL: %d\n",
optval);
  }

  bread = setsockopt(sockRaw,
                IPPROTO_IP,
                IP_HDRINCL,
                (char*)&value,
                sizeof(value));
  
  if(bread == SOCKET_ERROR) {
fprintf(stderr,"failed to set IP_HDRINCL:
%d\n",WSAGetLastError());
        ExitProcess(STATUS_FAILED);
  }

  WSACleanup();
  
  return 0;

}

_________________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

==================================================================
A mail-list of Linux Users Group - Bulgaria (bulgarian linuxers)
For more send to lug-bg-request@xxxxxxxxxxxx a single word 'info'
==================================================================



 

наши приятели

 

линукс за българи
http://linux-bg.org

FSA-BG
http://fsa-bg.org

OpenFest
http://openfest.org

FreeBSD BG
http://bg-freebsd.org

KDE-BG
http://kde.fsa-bg.org/

Gnome-BG
http://gnome.cult.bg/

проект OpenFMI
http://openfmi.net

NetField Forum
http://netField.ludost.net/forum/

 

 

Linux-Bulgaria.ORG

Mailing list messages are © Copyright their authors.