Search This Blog

09 September, 2015

Converting IP Address from string in dot format to 32 bit integer

C program to convert IPv4 address from String formatted in dat notation like "10.0.0.1" to a 32 bit integer in Linux

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

main()
{

    uint32_t ip;
    struct in_addr ip_addr;

    ip = inet_addr("10.0.0.1");
    printf("IP Integer: %d\n", ip);
    ip_addr.s_addr = ip;
    printf("The IP address is: %s\n", inet_ntoa(ip_addr));

}

No comments:

Post a Comment

tmux enabling mouse interaction

Add the below line to the ~/.tmux.conf setw -g mouse on save the file and exit from the tmux shell, you should be able to use your mouse to ...