UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2002-07-27 01:02 AM

HectorLasso
Administrator
From: Colombia
Registered: 2002-06-12
Posts: 353

Re: 6.5 - RAW sockets

#define IPPROTO_TEST 88 
#define BUFSIZE 1500 
char buf[BUFSIZE]; 
char rcvbuf[BUFSIZE]; 
int s; 
int nSize; 

//On client end 
main(char *toName) 
{ 
  struct sockaddr_in toAddr; 
  int n; 

  nSize = sizeof( struct sockaddr_in); 
  s = socket(AF_INET, SOCK_RAW, IPPROTO_TEST); 

  //On client end 
  n = sendto(s, (caddr_t) &buf, sizeof(buf), 0, 
               (struct sockaddr *) &toAddr, nSize) 
  if (n < 0) 
  { 
     perror("sendto"); 
     return(n); 
  } 
} 

//On server end 
main() 
{ 
  struct sockaddr_in frAddr; 
  int n; 
  
  nSize = sizeof( struct sockaddr_in); 
  s = socket(AF_INET, SOCK_RAW, IPPROTO_TEST); 


  n = rcvfrom(s, rcvbuf, sizeof(rcvbuf), 0, 
              (struct sockaddr *) &frAddr, nSize); 
  if(n < 0) 
  { 
     perror("rcvfrom"); 
     return(n); 
  } 
}

Offline

Board footer

Powered by FluxBB