Home > OS >  Help: what way can make the setsockopt under LINUX under 7 layer SOCK_STREAM effective?
Help: what way can make the setsockopt under LINUX under 7 layer SOCK_STREAM effective?

Time:10-06

Now I realize, in sockfd=socket (AF_INET SOCK_STREAM, 0), before the connect call setsockopt (sockfd, IPPROTO_IP IP_OPTIONS, (char *) & amp; Opthdr, sizeof (opthdr)) & lt; 0) found the setsockopt error: Invalid argument, have a driver or other methods can be introduced to set your own IP options in the connect parameters? The following for the test code, found that only defined code for seven or 131 or 134 won't be an error, but also not connected to the target,

#include
#include
#include
#include
#include
#include
#include

# define SERV_PORT 80
# define SERV_IP "221.14.145.31
"
Struct ip_option_hdr {
Unsigned char code;
Unsigned char length;
Unsigned char offset.
Unsigned addrs [9].
} opthdr;


Int main (int arg c, char * argv []) {
Int sockfd;
Struct sockaddr_in servaddr;

Memset (& amp; Servaddr, 0, sizeof (servaddr));
Servaddr. Sin_family=AF_INET;
Servaddr. Sin_addr. S_addr=inet_addr (SERV_IP);
Servaddr. Sin_port=htons (SERV_PORT);


If ((sockfd=socket (AF_INET SOCK_STREAM, 0)) & lt;=0) {
Perror (" socket error: ");
exit(1);
}
Memset ((char *) & amp; Opthdr, 0, sizeof (opthdr));
Opthdr. Code=7;
Opthdr. Length=39;
Opthdr. Offset=4;

//set the socket send this option
If (setsockopt (sockfd, IPPROTO_IP IP_OPTIONS, (char *) & amp; Opthdr, sizeof (opthdr)) & lt; 0 {
Perror (" setsockopt error ");
return 0;
}

If (connect (sockfd, (struct sockaddr *) & amp; Servaddr, sizeof (servaddr)) & lt; 0 {
Perror (" connect error ");
exit(1);
}
Write (sockfd, "/n/r/r/n", strlen ("/n/r/r/n "));
Close (sockfd);
}

Strives for the solution,,,,, if the trouble can be a red envelope support,,,,

CodePudding user response:

Artificial placed at the top,,,, index of patches
  • Related