ip与int之间的转化函数

来源:互联网 发布:封面ps软件 编辑:程序博客网 时间:2024/06/07 10:46
/* * purpose : transfer ip to u_int32_t * @Param IPdotdec : ip * return u_int_32 : the result u_int32_t  */u_int32_t ip2int(char IPdotdec[20]){        struct in_addr s; // IP to int        inet_pton(AF_INET, IPdotdec, (void *)&s);        return s.s_addr;}/* * purpose : transfer u_int32_t to ip * @Param u_int32_t : ip * return char * : IPdotdec */void int2ip(u_int32_t ip , char IPdotdec[20]){        struct in_addr s; // int to IP        s.s_addr = ip;        // int2ip        inet_ntop(AF_INET, (void *)&s, IPdotdec, 16);}
0 0