Obtain the address_parse function from the command line.

Source: Internet
Author: User

Get the parameters from the command line and check the code first:

Static void address_parse (
Bacnet_address * DST,
Int argc,
Char * argv [])
{
Unsigned Mac [6];
Unsigned port;
Int COUNT = 0;
Int Index = 0;

If (argc> 0 ){
Count =
Sscanf (argv [0], "% u. % u. % u. % u: % u ", & Mac [0], & Mac [1], & Mac [2],
& Mac [3], & Port );
If (COUNT = 5 ){
DST-> mac_len = 6;
For (Index = 0; index <4; index ++ ){
DST-> Mac [Index] = Mac [Index];
}
Encode_unsigned16 (& DST-> Mac [4], Port );
} Else {
Count =
Sscanf (argv [0], "% x: % x", & Mac [0], & Mac [1], & Mac [2],
& Mac [3], & Mac [4], & Mac [5]);
DST-> mac_len = count;
For (Index = 0; index <max_mac_len; index ++ ){
If (index <count ){
DST-> Mac [Index] = Mac [Index];
} Else {
DST-> Mac [Index] = 0;
}
}
}
}
DST-> net = 0;
DST-> Len = 0;
For (Index = 0; index <max_mac_len; index ++ ){
DST-> ADR [Index] = 0;
}
} Here, encode_unsigned16 is the number of unsigned codes. If the input address is 19.168.1.100 and the port number is 47808, it is converted to 0xbac0, And the array stores 192.168.1.100: 47808.

Int encode_unsigned16 (
Uint8_t * APDU,
Uint16_t value)
{
APDU [0] = (uint8_t) (Value & 0xff00)> 8 );
APDU [1] = (uint8_t) (Value & 0x00ff );

Return 2;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.