httpserver/sockets.cpp
//------------------------------------------------------------------------------------------------------
// This static function will check if the port occupied.
//------------------------------------------------------------------------------------------------------
This static function will check if the port occupied.
This static function will check if the port occupied .
static int SendStopCommand(int port) {
char* command = 
"POST stop HTTP/1.1\r\n\
Accept: */*\r\n\
Accept-Language: en-us\r\n\
Content-Type: application/discover\r\n\
Accept-Encoding: gzip,deflate\r\n\
User-Agent: StopDiscover\r\n\
Host: 127.0.0.1\r\n\
Content-Length: 0\r\n\r\n";
u_long addr;
struct sockaddr_in self_addr;
    addr                = inet_addr("127.0.0.1");
    struct hostent *ent = gethostbyaddr((char *)&addr, sizeof (addr), AF_INET);
    if(ent == NULL)
	return 0;
    self_addr.sin_family = AF_INET;
    self_addr.sin_port   = htons(port);
    self_addr.sin_addr   = *(in_addr *)*ent->h_addr_list;
    int sock = socket (PF_INET, SOCK_STREAM, 0);
    if (sock < 0) return 0;
    if(connect(sock,  (struct sockaddr *)&self_addr, sizeof (sockaddr_in)) < 0)
	     return 0;
    send(sock,command,strlen(command),0);
    closesocket(sock);
	return 1;
}
static int SendStopCommand ( int port ) { char * command = " \r \n \
 \r \n \
 \r \n \
 \r \n \
 \r \n \
 \r \n \
 \r \n \
 \r \n \r \n " ; u_long addr ; struct sockaddr_in self_addr ; addr = inet_addr ( " " ) ; struct hostent * ent = gethostbyaddr ( ( char * ) & addr , sizeof ( addr ) , AF_INET ) ; if ( ent == NULL ) return 0 ; self_addr . sin_family = AF_INET ; self_addr . sin_port = htons ( port ) ; self_addr . sin_addr = * ( in_addr * ) * ent -> h_addr_list ; int sock = socket ( PF_INET , SOCK_STREAM , 0 ) ; if ( sock < 0 ) return 0 ; if ( connect ( sock , ( struct sockaddr * ) & self_addr , sizeof ( sockaddr_in ) ) < 0 ) return 0 ; send ( sock , command , strlen ( command ) , 0 ) ; closesocket ( sock ) ; return 1 ; }
This static function will check if the port occupied.
This static function will check if the port occupied .
/* Create the socket. */ /* Give the socket a name. */