Skip to content

Commit

Permalink
Fix logging multiple IPs in the same time
Browse files Browse the repository at this point in the history
Use a multiple static rotating buffers for convering the IPs to str, so that we can print multiple IPs in the same time.
Closes #3062
Reported by @jes
  • Loading branch information
bogdan-iancu committed Apr 24, 2023
1 parent 410c306 commit 0ff8256
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ip_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "dprint.h"
#include "mem/mem.h"

char _ip_addr_A_buff[IP_ADDR_MAX_STR_SIZE];
char _ip_addr_A_buffs[IP_ADDR2STR_BUF_NO][IP_ADDR_MAX_STR_SIZE];

struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask)
{
Expand Down
7 changes: 6 additions & 1 deletion ip_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,25 @@ static inline int hostent2su( union sockaddr_union* su,

/*! \brief maximum size of a str returned by ip_addr2a (including \\0') */
#define IP_ADDR_MAX_STR_SIZE 40 /* 1234:5678:9012:3456:7890:1234:5678:9012\0 */
#define IP_ADDR2STR_BUF_NO 4

/*! \brief fast ip_addr -> string converter;
* it uses an internal buffer
*/
extern char _ip_addr_A_buff[IP_ADDR_MAX_STR_SIZE];
extern char _ip_addr_A_buffs[IP_ADDR2STR_BUF_NO][IP_ADDR_MAX_STR_SIZE];
static inline char* ip_addr2a(struct ip_addr* ip)
{
static unsigned int it = 0;
int offset;
register unsigned char a,b,c;
register unsigned char d;
register unsigned short hex4;
int r;
char *_ip_addr_A_buff;
#define HEXDIG(x) (((x)>=10)?(x)-10+'A':(x)+'0')

if ((++it)==IP_ADDR2STR_BUF_NO) it = 0;
_ip_addr_A_buff = _ip_addr_A_buffs[it];

offset=0;
switch(ip->af){
Expand Down

0 comments on commit 0ff8256

Please sign in to comment.