dsmi_set_device_ip_address
Prototype
int dsmi_set_device_ip_address (int device_id, int port_type, int port_id, ip_addr_t ip_address, ip_addr_t mask_address)
Description
Sets the IP address and mask address.
For the Ascend 310 AI Processor, this API supports only standard PCIe cards.
Parameters
Parameter |
Input/Output |
Description |
---|---|---|
device_id |
Input |
Device ID For the Ascend 310 AI Processor, the value range is 0–63. Obtain the actual device ID by calling dsmi_list_device. |
port_type |
Input |
Port type For the Ascend 310 AI Processor, only 0x00 (vNIC) is supported. The following macro can be passed to the API call: DSMI_VNIC_PORT (0) |
port_id |
Input |
Port ID (reserved). Set it to 0. |
ip_address |
Input |
#define DSMI_ARRAY_IPV4_NUM 4 #define DSMI_ARRAY_IPV6_NUM 16 typedef struct ip_addr { union { unsigned char ip6[DSMI_ARRAY_IPV6_NUM]; unsigned char ip4[DSMI_ARRAY_IPV4_NUM]; } u_addr; enum ip_addr_type ip_type; } ip_addr_t; For Ascend 310 AI Processors, the ip_addr_type struct is defined as follows. enum ip_addr_type { IPADDR_TYPE_V4 = 0U, /**< IPv4 */ IPADDR_TYPE_V6 = 6U, /**< IPv6 */ IPADDR_TYPE_ANY = 46U /**< IPv4+IPv6 ("dual-stack") */ }; |
mask_address |
Input |
#define DSMI_ARRAY_IPV4_NUM 4 #define DSMI_ARRAY_IPV6_NUM 16 typedef struct ip_addr { union { unsigned char ip6[DSMI_ARRAY_IPV6_NUM]; unsigned char ip4[DSMI_ARRAY_IPV4_NUM]; } u_addr; enum ip_addr_type ip_type; } ip_addr_t; For Ascend 310 AI Processors, the ip_addr_type struct is defined as follows. enum ip_addr_type { IPADDR_TYPE_V4 = 0U, /**< IPv4 */ IPADDR_TYPE_V6 = 6U, /**< IPv6 */ IPADDR_TYPE_ANY = 46U /**< IPv4+IPv6 ("dual-stack") */ }; |
Returns
Type |
Description |
---|---|
int |
0 on success; else, failure |
Restrictions
- Run the caller application as the root user on a physical machine. Otherwise, a permission error is returned.
Example
int ret = 0; int device_id = 0; int port_type = 0; int port_id = 0; unsigned int ip_addr = 0xC801A8C0; //192.168.1.200 unsigned int mask_addr = 0x00FFFFFF; //255.255.255.0 ip_addr_t ip_address = {0}; ip_addr_t ip_mask_address={0}; memcpy(&(ip_address.u_addr.ip4[0]),&ip_addr,4); memcpy(&(ip_mask_address.u_addr.ip4[0]),&mask_addr,4); ret = dsmi_set_device_ip_address(device_id, port_type, port_id, ip_address, ip_mask_address); if(ret != 0) { //To-do: records logs. return ret; } ...