Menu

[Solved]4 Write Function Mactonum Takes Character String Argument Pointer Struct Containing 3 Unsi Q37136534

4. You are to write a function mactonum() that takes a character string as its argument and a pointer to a struct containing

4. You are to write a function mactonum() that takes a character string as its argument and a pointer to a struct containing 3 unsigned shorts. The character string will be in the form of an Ethernet MAC address, which consists of six pairs of hexadecimal digits separated by colons. For example an input string of “08:00:20:f5:cc:al” should return three unsigned shorts with the values 0x8000, 0x20fS, and 0xccal. The function should return 0 if the MAC address is badly formed and 1 otherwise You have the function ctoh0 which takes a pointer to a pointer to char and returns the integer value of the hexadecimal number starting at the first character in the string. ctoh0 increments the pointer to char to the first non-hexadecimal character it encounters struct mac unsigned short macaddr [3] int ctoh (char **buf) ( int n- 0, hdigit; char *p; while (1) else if (**buf >= ‘a, && **buf <= ‘f’) buf – ‘a+10; bufA’+10; else break; n = n * 16 + hdígit; (*buf) +ti return n; int mactonum (char *in, struct mac *out) Show transcribed image text 4. You are to write a function mactonum() that takes a character string as its argument and a pointer to a struct containing 3 unsigned shorts. The character string will be in the form of an Ethernet MAC address, which consists of six pairs of hexadecimal digits separated by colons. For example an input string of “08:00:20:f5:cc:al” should return three unsigned shorts with the values 0x8000, 0x20fS, and 0xccal. The function should return 0 if the MAC address is badly formed and 1 otherwise You have the function ctoh0 which takes a pointer to a pointer to char and returns the integer value of the hexadecimal number starting at the first character in the string. ctoh0 increments the pointer to char to the first non-hexadecimal character it encounters struct mac unsigned short macaddr [3] int ctoh (char **buf) ( int n- 0, hdigit; char *p; while (1) else if (**buf >= ‘a, && **buf

Expert Answer


Answer to 4. You are to write a function mactonum() that takes a character string as its argument and a pointer to a struct contai… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *