[Olsr-cvs] olsrd-current/src/olsr_switch main.c, 1.28, 1.29 olsr_host_switch.h, 1.10, 1.11

Bernd Petrovitsch (spam-protected)
Thu Nov 8 23:47:44 CET 2007


Update of /cvsroot/olsrd/olsrd-current/src/olsr_switch
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28726/src/olsr_switch

Modified Files:
	main.c olsr_host_switch.h 
Log Message:
Another fat commit:

The main target was:
- Fixed the misleading definition of "v4" in "struct olsr_ip_addr" fom
  "olsr_u32_t" (in network-byteorder!) to "struct in_addr". Lots of
  temporary variables to call inet_ntoa()/inet_ptoa() vanished .....
- declare "int_addr", "int_netmask" and "int_broadaddr" in "struct interface"
  as "struct sockaddr_in" since it is that what we actually want there (and
  it is similar to the IPv6 code).

To get that thoroughly via compiler errors, we get:
- We have now ip4_to_string(), ip6_to_string() and olsr_ip_to_string()
  to print a "struct in_addr", "struct in6_addr" and "union olsr_ip_addr"
  into a string buffer.

Alas, this also annoyed me since ages:
- cleanup: olsr_ip_to_string() and similar non-reentrant functions now must
  get a target buffer. To ease that, there is the "struct ipaddr_str"
  which is large enough for all of them (read: for an IPv6 address). This
  also removes the cyclic buffer there.
  All of these function return a "const char *" which can be directly used
  for printf(3) and friends.

And some cleanups:
- const'ified more functions
- converted the source to UTF-8.
- "struct sig_msg" uses an olsr_u8_t for a byte array (and not "char")
- force the few inline function to always be inlined.
- #ifdef the body of the olsr_print_hna_set() and olsr_print_neighbor_table()
  if nothing is done
- use "inline_avl_comp_ipv4()" in "avl_comp_ipv4()"
- clean up the routes on more signals. Basically we want to do this on all
  signals which terminate the program.
- killed a superflous global buffer in src/main.c

This version was breing since weeks and running for severa day in Vienna's
FunkFeuer net without any noticably problem!

Please report anything that broke!



Index: olsr_host_switch.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/olsr_switch/olsr_host_switch.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** olsr_host_switch.h	2 Aug 2007 10:20:25 -0000	1.10
--- olsr_host_switch.h	8 Nov 2007 22:47:42 -0000	1.11
***************
*** 106,110 ****
  
  struct ohs_connection *
! get_client_by_addr(union olsr_ip_addr *);
  
  int
--- 106,110 ----
  
  struct ohs_connection *
! get_client_by_addr(const union olsr_ip_addr *);
  
  int

Index: main.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/olsr_switch/main.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** main.c	2 Aug 2007 10:20:25 -0000	1.28
--- main.c	8 Nov 2007 22:47:42 -0000	1.29
***************
*** 77,81 ****
  static int ip_version;
  int ipsize;
- static char ipv6_buf[100]; /* for address coversion */
  
  olsr_u32_t logbits;
--- 77,80 ----
***************
*** 100,125 ****
  olsr_ip_to_string(const union olsr_ip_addr *addr)
  {
-   static int index = 0;
    static char buff[4][100];
!   const char *ret;
!   struct in_addr in;
!   
!   if(ip_version == AF_INET)
!     {
!       in.s_addr=addr->v4;
!       ret = inet_ntoa(in);
!     }
!   else
!     {
!       /* IPv6 */
!       ret = inet_ntop(AF_INET6, &addr->v6, ipv6_buf, sizeof(ipv6_buf));
!     }
! 
!   strncpy(buff[index], ret, 100);
! 
!   ret = buff[index];
! 
    index = (index + 1) & 3;
- 
    return ret;
  }
--- 99,109 ----
  olsr_ip_to_string(const union olsr_ip_addr *addr)
  {
    static char buff[4][100];
!   static int index = 0;
!   const char *ret = inet_ntop(ip_version,
!                               ip_version == AF_INET ? (const void *)&addr->v4 : (const void *)&addr->v6,
!                               buff[index],
!                               sizeof(buff[index]));
    index = (index + 1) & 3;
    return ret;
  }
***************
*** 142,146 ****
  
  struct ohs_connection *
! get_client_by_addr(union olsr_ip_addr *adr)
  {
    struct ohs_connection *oc = ohs_conns;
--- 126,130 ----
  
  struct ohs_connection *
! get_client_by_addr(const union olsr_ip_addr *adr)
  {
    struct ohs_connection *oc = ohs_conns;
***************
*** 160,164 ****
  {
    struct ohs_connection *oc;
!   olsr_u8_t new_addr[4];
    int i;
  
--- 144,148 ----
  {
    struct ohs_connection *oc;
!   olsr_u32_t new_addr;
    int i;
  
***************
*** 187,191 ****
    for (i = 0; i < 20; i++)
    {
!     if (recv(oc->socket, new_addr, 4, 0) == 4)
        break;
  
--- 171,175 ----
    for (i = 0; i < 20; i++)
    {
!     if (recv(oc->socket, &new_addr, sizeof(new_addr), 0) == 4)
        break;
  
***************
*** 201,206 ****
    }
  
!   memcpy(&oc->ip_addr, new_addr, 4);
!   oc->ip_addr.v4 = ntohl(oc->ip_addr.v4);
    if(logbits & LOG_CONNECT)
      printf("IP: %s\n", olsr_ip_to_string(&oc->ip_addr));
--- 185,189 ----
    }
  
!   oc->ip_addr.v4.s_addr = ntohl(new_addr);
    if(logbits & LOG_CONNECT)
      printf("IP: %s\n", olsr_ip_to_string(&oc->ip_addr));
***************
*** 277,281 ****
  
    if(logbits & LOG_FORWARD)
!     printf("Received %d bytes from %s\n", (int)len, olsr_ip_to_string(&oc->ip_addr));
  
    /* Loop trough clients */
--- 260,264 ----
  
    if(logbits & LOG_FORWARD)
!     printf("Received %ld bytes from %s\n", (long)len, olsr_ip_to_string(&oc->ip_addr));
  
    /* Loop trough clients */





More information about the Olsr-cvs mailing list