0
#include <arpa/inet.h>

char buf[INET6_ADDRSTRLEN] = {};
int af = AF_INET;
unsigned char addr[4] = {0x7f, 0x0, 0x0, 0x1};

printf("Address: %s\n", inet_ntop(af, addr, buf, sizeof buf));

Is it valid to pass unsigned char array to inet_ntop() call? The code above works, but the man page says API expects network address structure in the second argument.

Mark
  • 6,052
  • 8
  • 61
  • 129

1 Answers1

0

I see that one implementation uses unsigned long as the one member of struct in_addr addr. If you compile on a system where unsigned long is not 4 bytes - I could foresee trouble. If a system have stricter alignment requirements for struct in_addr than char [], again I could foresee trouble.

In the end, it seems you are looking for assurance that this weak code will be OK going forward. I wish you luck.

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256