0
votes

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;
 }
1
Can you show the code you have written so far please?simonc
at first i have used the nping for sending the M-search message using the command "nping --udp -g1900 -p1900 --data-string "<Msearch message >" 239.255.255.250abhishek kumar srivastava
and now i am trying to perform the same using the c language code ...of seperate server and client side ..codes i will upload the codeabhishek kumar srivastava
"for time being i am just sending up the data on local host" -- sending to 127.0.0.1 makes no sense even then: M-SEARCH messages are multicast and need to be sent to the SSDP multicast address.Jussi Kukkonen
@jku thanks for pointing it out ... i corrected it ...now my main concern is how to set up a upnp server on a ubuntu machine so that it reply back to my M-search messages ...abhishek kumar srivastava

1 Answers

0
votes

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".