I'm working on editing IPv6 addresses. I have a data structure like: uint16_t u16 [8]
, representing an IPv6 address.
Example:
ff1e: 0000: 0000: 0000: 0011: 22ff: fa 33: 4402
I want to change the specific bit groups with numbers. For example, suppose I have the variable uint16_t var
whose value is 256
. Then I would like to change the second bit group like this:
ff1e: 0256: 0000: 0000: 0011: 22ff: fee 33: 4402
Unfortunately
UIPAAP6AdD_T-> U16 [1] = heroic;
gives
ff1e: 0101: 0000: 0000: 0011: 22ff: fa 33: 4402
Hexadecimal number version I have not got any clue how this can change and it is difficult for Google (English is not my native language). Any quick suggestions?
Edit: uip_ip6addr_t
defined UPIIP_IP_APIADD_T {uint8_t u8 [16]; / * Initial, should come first. * / Uint16_t u16 [8]; } Uip_ip6addr_t;
Line to print:
printf ("% 02x% 02x:% 02x% 02x:% 02x% 02x:% 02x% 02x: % 02x% 02x:% 02x% 02x:% 02x% 02x:% 02x% 02x ", ((uint8_t *) adr) [0], ((uint8_t *) adr) [1], ((uint8_t *) edit) [2], ((uint8_t *) Endor) [3], ((uint8_t *) ADR) [4], ((UIT 8_T *) ADR) [5], ((UIT 8_T *) Endor) [6] (UIT 8_T) *] ADR [7], (UIT 8_T *) ADR) [8], (UIT 8_T *) ADR) [9], (UIT 8_T *) Endor) [10] , ((UIT 8_T *) and the endor), [11], (Uint8_t *), [12], ((uint8_t *) ADR) [13], ((uint8_t *) ADR) [14], ((uint8_t * ) Endor) [15])
This line has another IP address Prints from
Well, your code is actually working: '0101' changed from hex to decimal format, '0257' will print.
I think you should have printf ("% x:% x:% x:% x:% X:% x:% x:% x", ipaddr- & gt; u16 [ 0], ipaddr-> u16 [1], ipad-> U16 [2], ipad-> U16 [3], ipad-> U16 [4], ipad-> U16 [ 5], IPDR-> U16 [6], IPDR-> U16 [7]);
.
forma tint string printed '0257' by "% 04zu:% 04zu:% 04zu:% 04zu:% 04zu:% 04zu:% 04zu:% 04zu"
(According to your first result hex).
EDIT: I wrote a little faster, '0x101' in the comment is '0257'.
No comments:
Post a Comment