xDer 0 Newbie Poster

Hey! I am using UDP sockets in IPV6 and i can't get the server to receive the packet sent by the client to the All Hosts ipv6 address ff02::1. The client is sending the packets as i see them in the wireshark. Can you help please?

Server

#include <sstream>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/ethernet.h>
#include <unistd.h>
#include <netdb.h>
#include <vector>
#include <iostream>
#include <sys/types.h>
#include <ifaddrs.h>
#include <stdlib.h>
#include <iostream>
#include <netinet/in.h>

using namespace std;

int main(void)
{
  struct sockaddr_in6 server;
  struct in6_addr to_addr;
 int server_sock,bytes_sent;

  if ((server_sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
	     cout << "Error creating socket!" << endl;
	    }


  if(inet_pton(AF_INET6,"ff02::1",&to_addr)<=0){
	cout << "Error in PTON" << endl;	
	exit(1);
	}

 cout << "Binding..." << endl;

 server.sin6_family=AF_INET6;
 server.sin6_port=20470;
 server.sin6_addr=to_addr;
 server.sin6_scope_id=2;

 bytes_sent=bind(server_sock, (struct sockaddr *)&server, sizeof(server));
 
 if(bytes_sent < 0 )
	{
      		char buf[1024];
	sprintf(buf,"LinkDiscover::Run() - BIND failed: %s",strerror(errno));
	cout << buf << endl;
	exit(1);
	}

 while(1)
 {
  char buf[2048];
  struct sockaddr_storage client;

   cout << "Waiting for a new packet..." << endl;
       
    int len;
    socklen_t aLen = sizeof(client);
    len = recvfrom(server_sock, buf, sizeof(buf), 0, (struct sockaddr *)&client, &aLen);
    if(len < 0) {
      char buf[1024];
      sprintf(buf,"UdpSocket::Recv() - recvfrom() failed: %s",strerror(errno));
      cout << buf << endl;
	 exit(1);

 }

   cout << " new packet arrived with " << len << "bytes!" << endl;
 }

}
Client


   1.
      #include "ipv6.h"
   2.
      #include <string.h>
   3.
      #include <sys/socket.h>
   4.
      #include <netinet/in.h>
   5.
      #include <arpa/inet.h>
   6.
      #include <sys/ioctl.h>
   7.
      #include <net/if.h>
   8.
      #include <net/ethernet.h>
   9.
      #include <unistd.h>
  10.
      #include <netdb.h>
  11.
      #include <iostream>
  12.
       
  13.
      int main(void)
  14.
      {
  15.
              int cFd;
  16.
              struct in6_addr to_addr;
  17.
              if ((cFd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
  18.
                    cout << "Socket error!" << endl;
  19.
                      exit(1);
  20.
                  }
  21.
       
  22.
       
  23.
               if(inet_pton(AF_INET6,"ff02::1",&to_addr)<=0){
  24.
              cout << "Error in PTON" << endl;       
  25.
              exit(1);
  26.
              }
  27.
       
  28.
              InetAddrv6 addr = InetAddrv6(to_addr,20470);
  29.
       
  30.
              while(1)
  31.
              sendto(cFd, "TranT", 6,  0, (struct sockaddr *)&addr, sizeof(addr));
  32.
       
  33.
              return 0;
  34.
      }