Print this page


Split Close
Expand all
Collapse all
          --- old/src/dep/net.c
          +++ new/src/dep/net.c
↓ open down ↓ 46 lines elided ↑ open up ↑
  47   47  
  48   48  /**
  49   49   * @file   net.c
  50   50   * @date   Tue Jul 20 16:17:49 2010
  51   51   *
  52   52   * @brief  Functions to interact with the network sockets and NIC driver.
  53   53   *
  54   54   *
  55   55   */
  56   56  
       57 +#ifdef __sun
       58 +/*
       59 + * These are needed to enable control messages on sendmsg().
       60 + * I'll save the commentary on why the bend-over-backwards old way of doing
       61 + * sendmsg() is still around.
       62 + *
       63 + * STRICTLY SPEAKING this program should be linked against libxnet instead
       64 + * of libsocket because of these interfaces, but we'll cross that bridge
       65 + * when we get to it.
       66 + */
       67 +#define _XOPEN_SOURCE 500
       68 +#define __EXTENSIONS__
       69 +#endif
       70 +
  57   71  #include "../ptpd.h"
  58   72  
  59   73  #ifdef PTPD_PCAP
  60   74  #ifdef HAVE_PCAP_PCAP_H
  61   75  #include <pcap/pcap.h>
  62   76  #else /* !HAVE_PCAP_PCAP_H */
  63   77  /* Cases like RHEL5 and others where only pcap.h exists */
  64   78  #ifdef HAVE_PCAP_H
  65   79  #include <pcap.h>
  66   80  #endif /* HAVE_PCAP_H */
↓ open down ↓ 232 lines elided ↑ open up ↑
 299  313     hw address available, -1 on failure.
 300  314   */
 301  315  static int
 302  316  getHwAddress (char* ifaceName, unsigned char* hwAddr, int hwAddrSize)
 303  317  {
 304  318  
 305  319      int ret;
 306  320      if(!strlen(ifaceName))
 307  321          return 0;
 308  322  
      323 +#if defined(AF_LINK) && !defined(__sun)
 309  324  /* BSD* - AF_LINK gives us access to the hw address via struct sockaddr_dl */
 310      -#ifdef AF_LINK
 311  325  
 312  326      struct ifaddrs *ifaddr, *ifa;
 313  327  
 314  328      if(getifaddrs(&ifaddr) == -1) {
 315  329          PERROR("Could not get interface list");
 316  330          ret = -1;
 317  331          goto end;
 318  332  
 319  333      }
 320  334  
↓ open down ↓ 19 lines elided ↑ open up ↑
 340  354      }
 341  355  
 342  356      ret = 0;
 343  357      DBG("Interface not found: %s\n", ifaceName);
 344  358  
 345  359  end:
 346  360  
 347  361      freeifaddrs(ifaddr);
 348  362      return ret;
 349  363  
 350      -/* Linux, basically */
 351  364  #else
      365 +/* Linux and Solarish systems have SIOCGIFHWADDR/SIOCGLIFHWADDR.  Use it. */
 352  366  
 353  367      int sockfd;
 354  368      struct ifreq ifr;
 355  369  
 356  370      sockfd = socket(AF_INET, SOCK_DGRAM, 0);
 357  371  
 358  372      if(sockfd < 0) {
 359  373          PERROR("Could not open test socket");
 360  374          return -1;
 361  375      }
 362  376  
 363      -    memset(&ifr, 0, sizeof(struct ifreq));
      377 +    memset(&ifr, 0, sizeof (ifr));
 364  378  
 365  379      strncpy(ifr.ifr_name, ifaceName, IFACE_NAME_LENGTH);
 366  380  
 367  381      if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) {
 368  382              DBGV("failed to request hardware address for %s", ifaceName);
 369  383              ret = -1;
 370  384              goto end;
 371  385      }
 372  386  
 373  387  
      388 +#ifdef __sun
      389 +    int af = ifr.ifr_addr.sa_family;
      390 +#else
 374  391      int af = ifr.ifr_hwaddr.sa_family;
      392 +#endif
 375  393  
 376  394      if (    af == ARPHRD_ETHER
 377  395           || af == ARPHRD_IEEE802
 378  396  #ifdef ARPHRD_INFINIBAND
 379  397           || af == ARPHRD_INFINIBAND
 380  398  #endif
 381  399          ) {
      400 +#ifdef __sun
      401 +            memcpy(hwAddr, ifr.ifr_addr.sa_data, hwAddrSize);
      402 +#else
 382  403              memcpy(hwAddr, ifr.ifr_hwaddr.sa_data, hwAddrSize);
      404 +#endif
 383  405              ret = 1;
 384  406          } else {
 385  407              DBGV("Unsupported hardware address family on %s\n", ifaceName);
 386  408              ret = 0;
 387  409          }
 388  410  end:
 389  411      close(sockfd);
 390  412      return ret;
 391  413  
 392  414  #endif /* AF_LINK */
↓ open down ↓ 174 lines elided ↑ open up ↑
 567  589                  return FALSE;
 568  590          }
 569  591          /* End of Peer multicast Ip address init */
 570  592          
 571  593          return TRUE;
 572  594  }
 573  595  
 574  596  static Boolean
 575  597  netSetMulticastTTL(int sockfd, int ttl) {
 576  598  
 577      -#ifdef __OpenBSD__
      599 +#if defined(__OpenBSD__) || defined(__sun)
 578  600          uint8_t temp = (uint8_t) ttl;
 579  601  #else
 580  602          int temp = ttl;
 581  603  #endif
 582  604  
 583  605          if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL,
 584  606                         &temp, sizeof(temp)) < 0) {
 585  607              PERROR("Failed to set socket multicast time-to-live");
 586  608              return FALSE;
 587  609          }
 588  610          return TRUE;
 589  611  }
 590  612  
 591  613  static Boolean
 592  614  netSetMulticastLoopback(NetPath * netPath, Boolean value) {
 593      -#ifdef __OpenBSD__
      615 +#if defined(__OpenBSD__) || defined(__sun)
 594  616          uint8_t temp = value ? 1 : 0;
 595  617  #else
 596  618          int temp = value ? 1 : 0;
 597  619  #endif
 598  620          DBG("Going to set multicast loopback with %d \n", temp);
 599  621  
 600  622          if (setsockopt(netPath->eventSock, IPPROTO_IP, IP_MULTICAST_LOOP, 
 601  623                 &temp, sizeof(temp)) < 0) {
 602  624                  PERROR("Failed to set multicast loopback");
 603  625                  return FALSE;
↓ open down ↓ 137 lines elided ↑ open up ↑
 741  763  
 742  764          return result;
 743  765  }
 744  766  
 745  767  Boolean
 746  768  hostLookup(const char* hostname, Integer32* addr)
 747  769  {
 748  770          if (hostname[0]) {
 749  771                  /* Attempt a DNS lookup first. */
 750  772                  struct hostent *host;
      773 +#ifdef __sun
      774 +                host = getipnodebyname(hostname, AF_INET, AI_DEFAULT, &errno);
      775 +#else
 751  776                  host = gethostbyname2(hostname, AF_INET);
      777 +#endif
 752  778                  if (host != NULL) {
 753  779                          if (host->h_length != 4) {
 754  780                                  PERROR("unicast host resolved to non ipv4"
 755  781                                         "address");
 756  782                                  return FALSE;
 757  783                          }
 758  784                          *addr = 
 759  785                                  *(uint32_t *)host->h_addr_list[0];
 760  786                          return TRUE;
 761  787                  } else {
↓ open down ↓ 1073 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX