udpwiresharkupnpicmpssdp

how to perform ssdp communicationbetween upnp devices


i am trying to implement the upnp level communication between the devices .. but facing problem in getting the response message .and more over on sending the ssdp:discovery multicast not able to recieve the messages from the devices ... please guide me through i am completely newto this topic

pre-requisite done by me :

1.able to send the M-Search ..and notify message on the network .. and have confirmed via wireshark

2.gone through the upnp architecture related pdf

response got in wireshark :

when ever i am sending the message i am getting the icmp error message that destination is not reachable ..

< client side code > is the first one and second one is the for time being i am just sending up the data on local host

   #include <arpa/inet.h>
   #include <netinet/in.h>
   #include <stdio.h>
   #include <sys/types.h>
   #include <sys/socket.h>
   #include <unistd.h>



   #define SRV_IP "127.0.0.1"
   /* diep(), #includes and #defines like in the server */

  #define BUFLEN 512
   #define NPACK 10
  #define PORT 1900

void diep(char *s)
  {
    perror(s);
    exit(1);
  }

   int main(void)
   {
     struct sockaddr_in si_other;
     int s, i, slen=sizeof(si_other);
     char buf[BUFLEN];

    if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
      diep("socket");

    memset((char *) &si_other, 0, sizeof(si_other));
    si_other.sin_family = AF_INET;
    si_other.sin_port = htons(PORT);
    if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
      fprintf(stderr, "inet_aton() failed\n");
      exit(1);
    }

    for (i=0; i<NPACK; i++) {
      printf("Sending packet %d\n", i);
      sprintf(buf, "\n");
      if (sendto(s, buf, BUFLEN, 0, &si_other, slen)==-1)
        diep("sendto()");
    }

    close(s);
    return 0;
  }







  #include <arpa/inet.h>
   #include <netinet/in.h>
   #include <stdio.h>
   #include <sys/types.h>
   #include <sys/socket.h>
   #include <unistd.h>

   #define BUFLEN 512
   #define NPACK 10
  #define PORT 1900

  void diep(char *s)
  {
    perror(s);
    exit(1);
  }

  int main(void)
  {
    struct sockaddr_in si_me, si_other;
    int s, i, slen=sizeof(si_other);
    char buf[BUFLEN];

    if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
      diep("socket");
        memset((char *) &si_me, 0, sizeof(si_me));
    si_me.sin_family = AF_INET;
    si_me.sin_port = htons(PORT);
    si_me.sin_addr.s_addr = htonl(INADDR_ANY);
    if (bind(s, &si_me, sizeof(si_me))==-1)
        diep("bind");

    for (i=0; i<NPACK; i++) {
      if (recvfrom(s, buf, BUFLEN, 0, &si_other, &slen)==-1)
        diep("recvfrom()");
      printf("Received packet from %s:%d\nData: %s\n\n", 
             inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf);
    }

    close(s);
    return 0;
 }

Solution

  • The individual lines in you M-SEARCH need to have "\r\n" at the end of each line, not just a "\n". Your system may just be sending "\n" across the wire. Check the bytes you're sending for a 13 followed by a 10. That's "\r\n".