[Olsr-cvs] olsrd-current/lib/txtinfo/src olsrd_txtinfo.c, 1.11, 1.12

Bernd Petrovitsch (spam-protected)
Sun Oct 14 16:11:13 CEST 2007


Update of /cvsroot/olsrd/olsrd-current/lib/txtinfo/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv31869/lib/txtinfo/src

Modified Files:
	olsrd_txtinfo.c 
Log Message:
* applied patch by John Hay <(spam-protected)>: make txtinfo plugin work with IPv6


Index: olsrd_txtinfo.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/txtinfo/src/olsrd_txtinfo.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** olsrd_txtinfo.c	17 Sep 2007 22:08:01 -0000	1.11
--- olsrd_txtinfo.c	14 Oct 2007 14:11:11 -0000	1.12
***************
*** 144,152 ****
  plugin_ipc_init(void)
  {
!     struct sockaddr_in sin;
      olsr_u32_t yes = 1;
  
      /* Init ipc socket */
!     if ((ipc_socket = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
  #ifndef NODEBUG
          olsr_printf(1, "(TXTINFO) socket()=%s\n", strerror(errno));
--- 144,155 ----
  plugin_ipc_init(void)
  {
!     struct sockaddr_storage sst;
!     struct sockaddr_in *sin;
!     struct sockaddr_in6 *sin6;
      olsr_u32_t yes = 1;
+     socklen_t addrlen;
  
      /* Init ipc socket */
!     if ((ipc_socket = socket(olsr_cnf->ip_version, SOCK_STREAM, 0)) == -1) {
  #ifndef NODEBUG
          olsr_printf(1, "(TXTINFO) socket()=%s\n", strerror(errno));
***************
*** 170,180 ****
  
          /* complete the socket structure */
!         memset(&sin, 0, sizeof(sin));
!         sin.sin_family = AF_INET;
!         sin.sin_addr.s_addr = INADDR_ANY;
!         sin.sin_port = htons(ipc_port);
        
          /* bind the socket to the port number */
!         if (bind(ipc_socket, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
  #ifndef NODEBUG
              olsr_printf(1, "(TXTINFO) bind()=%s\n", strerror(errno));
--- 173,199 ----
  
          /* complete the socket structure */
!         memset(&sst, 0, sizeof(sst));
!         if (olsr_cnf->ip_version == AF_INET) {
!            sin = (struct sockaddr_in *)&sst;
!            sin->sin_family = AF_INET;
!            addrlen = sizeof(struct sockaddr_in);
! #ifdef SIN6_LEN
!            sin->sin_len = addrlen;
! #endif
!            sin->sin_addr.s_addr = INADDR_ANY;
!            sin->sin_port = htons(ipc_port);
!         } else {
!            sin6 = (struct sockaddr_in6 *)&sst;
!            sin6->sin6_family = AF_INET6;
!            addrlen = sizeof(struct sockaddr_in6);
! #ifdef SIN6_LEN
!            sin6->sin6_len = addrlen;
! #endif
!            sin6->sin6_addr = in6addr_any;
!            sin6->sin6_port = htons(ipc_port);
!         }
        
          /* bind the socket to the port number */
!         if (bind(ipc_socket, (struct sockaddr *) &sst, addrlen) == -1) {
  #ifndef NODEBUG
              olsr_printf(1, "(TXTINFO) bind()=%s\n", strerror(errno));
***************
*** 205,215 ****
  static void ipc_action(int fd)
  {
!     struct sockaddr_in pin;
!     char *addr;  
      fd_set rfds;
      struct timeval tv;
      int neighonly = 0;
  
!     socklen_t addrlen = sizeof(struct sockaddr_in);
  
      if(ipc_open)
--- 224,236 ----
  static void ipc_action(int fd)
  {
!     struct sockaddr_storage pin;
!     struct sockaddr_in *sin4;
!     struct sockaddr_in6 *sin6;
!     char addr[INET6_ADDRSTRLEN];
      fd_set rfds;
      struct timeval tv;
      int neighonly = 0;
  
!     socklen_t addrlen = sizeof(struct sockaddr_storage);
  
      if(ipc_open)
***************
*** 224,232 ****
  
      tv.tv_sec = tv.tv_usec = 0;
!     addr = inet_ntoa(pin.sin_addr);
!     if (ntohl(pin.sin_addr.s_addr) != ntohl(ipc_accept_ip.v4)) {
!         olsr_printf(1, "(TXTINFO) From host(%s) not allowed!\n", addr);
!         close(ipc_connection);
!         return;
      }
      ipc_open = 1;
--- 245,270 ----
  
      tv.tv_sec = tv.tv_usec = 0;
!     if (olsr_cnf->ip_version == AF_INET) {
!         sin4 = (struct sockaddr_in *)&pin;
!         if (inet_ntop(olsr_cnf->ip_version, &sin4->sin_addr, addr,
!            INET6_ADDRSTRLEN) == NULL)
!              addr[0] = '\0';
!         if (!COMP_IP(&sin4->sin_addr, &ipc_accept_ip.v4)) {
!             olsr_printf(1, "(TXTINFO) From host(%s) not allowed!\n", addr);
!             close(ipc_connection);
!             return;
!         }
!     } else {
!         sin6 = (struct sockaddr_in6 *)&pin;
!         if (inet_ntop(olsr_cnf->ip_version, &sin6->sin6_addr, addr,
!            INET6_ADDRSTRLEN) == NULL)
!              addr[0] = '\0';
!        /* Use in6addr_any (::) in olsr.conf to allow anybody. */
!         if (!COMP_IP(&in6addr_any, &ipc_accept_ip.v6) &&
!            !COMP_IP(&sin6->sin6_addr, &ipc_accept_ip.v6)) {
!             olsr_printf(1, "(TXTINFO) From host(%s) not allowed!\n", addr);
!             close(ipc_connection);
!             return;
!         }
      }
      ipc_open = 1;





More information about the Olsr-cvs mailing list