Pejman Moghadam / C-programming

C - inet_pton

Public domain


inet_pton : convert IPv4 and IPv6 addresses from text to binary form

#include <stdio.h>
#include <string.h>
#include <arpa/inet.h> 

int main()
{
    char *src = "83.170.42.20";
    struct in_addr dst;

    memset(&dst, 0, sizeof dst);
    inet_pton(AF_INET, src, &dst);
    printf("Presentation = %s\n", src);
    printf("Network = %X\n", dst.s_addr);

    return 0;
}

BY: Pejman Moghadam
TAG: c, inet-pton
DATE: 2014-01-21 02:04:17


Pejman Moghadam / C-programming [ TXT ]