Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


My application not recieving SSDP response?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Mon Dec 06, 2010 3:09 pm    Post subject: My application not recieving SSDP response? Reply with quote

I have had a good look at this again today, and i am pretty sure i solved the issue with sending to the wrong port, by merging the two applications together, and then calling bind() on the socket which im sending the packets from. This seems to work perfectly fine, however i am no having issues with receiving the responses from the UPnP (SSDP) device.

My new source is as follows:
Code:
#include <Winsock2.h>
#include <WS2tcpip.h>
#include <iostream>

#pragma comment(lib, "wsock32.lib")

#define multicast_address "239.255.255.250"
#define multicast_port 1900

SOCKET sock;
SOCKADDR_IN sockAddr;

//The exact packet that my Sonos controller uses to search for the devices
const char packet[] =   "M-SEARCH * HTTP/1.1\r\n"
                  "HOST: 239.255.255.250:1900\r\n"
                  "MAN: \"ssdp:discover\"\r\n"
                  "MX: 1\r\n"
                  "ST: urn:schemas-upnp-org:device:ZonePlayer:1\r\n"
                  "X-RINCON-HOUSEHOLD: HHID_0CIxhbn87mLLeVNz78fjTb0jx2F\r\n\r\n";

//The exact packet that my third party controller uses to search for the devices
//const char packet[] =   "M-SEARCH * HTTP/1.1\r\n"
//   "ST: upnp:rootdevice\r\n"
//   "MX: 3\r\n"
//   "MAN: \"ssdp:discover\"\r\n"
//   "HOST: HOST: 239.255.255.250:1900\r\n\r\n";

int recvThread(){
   char buf[512];
   while(true){
      memset(buf, 0, sizeof(buf));
      if(recvfrom(sock, buf, sizeof(buf), 0, NULL, NULL) == SOCKET_ERROR)
         std::cout << "recvfrom() error: " << WSAGetLastError();
      std::cout << "Packet recieved:\n" << buf;
   }
   return 0;
}

int main(){
   WSAData wsaData;
   SOCKADDR_IN sockSendAddr;
   char TTLVal = 10; //I believe this should be correct?
   ip_mreq mreq;
   WSAStartup(0x0202, &wsaData);
   sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
   if(sock == INVALID_SOCKET)
      std::cout << "socket() error";
   if(setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&TTLVal, sizeof(TTLVal)) == SOCKET_ERROR)
      std::cout << "setsockopt() error: " << WSAGetLastError();
   unsigned long addr = inet_addr(multicast_address);
   setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&addr, sizeof(addr));
   sockAddr.sin_family = AF_INET;
   sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);//inet_addr(multicast_address);
   sockAddr.sin_port = htons(multicast_port);
   if(bind(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)) == SOCKET_ERROR)
      std::cout << "bind() error: " << WSAGetLastError();
   mreq.imr_multiaddr.s_addr = inet_addr(multicast_address);
   mreq.imr_interface.s_addr = INADDR_ANY;
   if(setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) == SOCKET_ERROR)
      std::cout << "setsockopt() error: " << WSAGetLastError();
   sockSendAddr.sin_family = AF_INET;
   sockSendAddr.sin_addr.s_addr = inet_addr(multicast_address);
   sockSendAddr.sin_port = htons(multicast_port);
   CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)recvThread, NULL, 0, NULL);
   while(true){
      std::cin.sync();
      std::cin.ignore();
      if(sendto(sock, packet, sizeof(packet), 0, (sockaddr*)&sockSendAddr, sizeof(sockSendAddr)) == SOCKET_ERROR)
         std::cout << "sendto() error: " << WSAGetLastError();
   }
}


I know that my SSDP devices in fact recieves the packet, since i am able to get a response, however my application doesent recieve the response, though it shows up on wireshark (see attached SS), i have verified the packets, and they indeed are 100% as they should be, but nomatter what, my application doesnt recieve the packet Sad



Udklip.PNG
 Description:
 Filesize:  5.3 KB
 Viewed:  3476 Time(s)

Udklip.PNG


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites