IP Address和Integer相互转换

#include <stdio.h>
#include <WinSock2.h>
#pragma comment(lib,"ws2_32.lib")
void print_ip(int ip)
{
unsigned char bytes[4];
bytes[0] = ip & 0xFF;
bytes[1] = (ip >> 8) & 0xFF;
bytes[2] = (ip >> 16) & 0xFF;
bytes[3] = (ip >> 24) & 0xFF;
printf("%d.%d.%d.%d\n", bytes[3], bytes[2], bytes[1], bytes[0]);
}

int main(){
//print_ip(3232237185);

printf("%u\n",ntohl( inet_addr("192.168.6.129") ));
//printf("%u\n",inet_addr("192.168.6.129"));

printf("Over");
getchar();
return 0;
}

时间: 2024-11-05 23:21:58

IP Address和Integer相互转换的相关文章

在windows下运行docker的问题【Error getting IP address: ***】

环境配置系统:windows 10docker:Docker Toolbox https://www.docker.com/products/docker-toolbox 问题描述windows下安装完Docker Toolbox后运行Docker Quickstart Terminal可能会看到如下错误 Creating Machine default... Running pre-create checks... Creating machine... Error creating mach

Java Regex match IP address

Reference: [1] https://www.mkyong.com/regular-expressions/how-to-validate-ip-address-with-regular-expression/ import java.util.regex.Matcher; import java.util.regex.Pattern; public class IPAddressValidator{ private Pattern pattern; private Matcher ma

router 分配ip address(dhcp)和dhcp中继

路由器的主要功能是网络寻址,有时候也需要用来分配ip地址.但用路由器分配地址又会加大路由器的负载,所以,有的时候我们可以把分配地址的工作交给一台PC. 1.使用router分配ip address: Router>en Router#conf t Enter configuration commands, one per line.  End with CNTL/Z. Router(config)#int vlan 1 Router(config-if)#ip dhcp pool vlan1  

poj2105 IP Address(简单题)

题目链接:http://poj.org/problem?id=2105 Description Suppose you are reading byte streams from any device, representing IP addresses. Your task is to convert a 32 characters long sequence of '1s' and '0s' (bits) to a dotted decimal format. A dotted decima

Debian static ip address

1 // /etc/network/interfaces 2 auto eth0 3 iface eth0 inet static 4 address <Your ip address> 5 netmask <Your netmask> 6 gateway <Your gateway address> 7 broadcast <Your broadcast address> 8 9 // /etc/resolv.conf 10 nameserver <

If application data needs to be sent to IP address xx.xx.xx.xx, how does it work in underneath network?

This is to illustrate the communication between two separate machines which don't have a direct physical connection. Application data is generated and passed to layer 3 (network layer) which wrapps up the data with the destination IP address. Then ha

Bringing up interface eth0: Determining if ip address 10.109.67.81 is already in use for device eth0...

重启网卡出现提示: Bringing up interface eth0:  Determining if ip address 10.109.67.81 is already in use for device eth0...                                                            [  OK  ] Bringing up interface eth1:  Determining if ip address 10.109.67.83

oracle 11g RAC安装节点二执行结果错误CRS-5005: IP Address: 192.168.1.24 is already in use in the network

[[email protected] ~]# /u01/app/oraInventory/orainstRoot.sh Changing permissions of /u01/app/oraInventory. Adding read,write permissions for group. Removing read,write,execute permissions for world. Changing groupname of /u01/app/oraInventory to oins

Linux下network提示Determining if ip address

[[email protected] NetworkManager]# service network restart正在关闭接口 eth0: [确定]关闭环回接口: [确定]弹出环回接口: [确定]弹出界面 eth0: Determining if ip address 192.168.8.102 is already in use for device eth0... vi /etc/sysconfig/network-scripts/ifcfg-eth0 添加   ARPCHECK=no