MCPcopy Create free account
hub / github.com/cppla/ServerStatus / net_addr_str

Function net_addr_str

server/src/system.c:617–640  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

615}
616
617void net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port)
618{
619 if(addr->type == NETTYPE_IPV4)
620 {
621 if(add_port != 0)
622 str_format(string, max_length, "%d.%d.%d.%d:%d", addr->ip[0], addr->ip[1], addr->ip[2], addr->ip[3], addr->port);
623 else
624 str_format(string, max_length, "%d.%d.%d.%d", addr->ip[0], addr->ip[1], addr->ip[2], addr->ip[3]);
625 }
626 else if(addr->type == NETTYPE_IPV6)
627 {
628 if(add_port != 0)
629 str_format(string, max_length, "[%x:%x:%x:%x:%x:%x:%x:%x]:%d",
630 (addr->ip[0]<<8)|addr->ip[1], (addr->ip[2]<<8)|addr->ip[3], (addr->ip[4]<<8)|addr->ip[5], (addr->ip[6]<<8)|addr->ip[7],
631 (addr->ip[8]<<8)|addr->ip[9], (addr->ip[10]<<8)|addr->ip[11], (addr->ip[12]<<8)|addr->ip[13], (addr->ip[14]<<8)|addr->ip[15],
632 addr->port);
633 else
634 str_format(string, max_length, "[%x:%x:%x:%x:%x:%x:%x:%x]",
635 (addr->ip[0]<<8)|addr->ip[1], (addr->ip[2]<<8)|addr->ip[3], (addr->ip[4]<<8)|addr->ip[5], (addr->ip[6]<<8)|addr->ip[7],
636 (addr->ip[8]<<8)|addr->ip[9], (addr->ip[10]<<8)|addr->ip[11], (addr->ip[12]<<8)|addr->ip[13], (addr->ip[14]<<8)|addr->ip[15]);
637 }
638 else
639 str_format(string, max_length, "unknown type %d", addr->type);
640}
641
642static int priv_net_extract(const char *hostname, char *host, int max_host, int *port)
643{

Callers 3

NetToStringMethod · 0.85
NewClientCallbackMethod · 0.85
DelClientCallbackMethod · 0.85

Calls 1

str_formatFunction · 0.85

Tested by

no test coverage detected