2
0

arpainet.c 568 B

12345678910111213141516171819202122232425
  1. #include <arpa/inet.h>
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "test_helpers.h"
  6. int main(void) {
  7. uint32_t hl = 0xBADFACED;
  8. uint32_t nl = htonl(hl);
  9. assert(nl == 0xEDACDFBA);
  10. hl = ntohl(nl);
  11. assert(hl == 0xBADFACED);
  12. uint16_t hs = 0xDEAD;
  13. uint16_t ns = htons(hs);
  14. assert(ns == 0xADDE);
  15. hs = ntohs(ns);
  16. assert(hs == 0xDEAD);
  17. const char* addr_str = "8.8.4.4";
  18. struct in_addr* addr = malloc(sizeof addr);
  19. inet_aton(addr_str, addr);
  20. assert(strcmp(inet_ntoa(*addr), addr_str) == 0);
  21. }