First Version (beta test) raw ethernet
Dependencies: EthernetNetIf mbed
utils.c@0:db9ea2448fdd, 2012-07-09 (annotated)
- Committer:
- ficofer
- Date:
- Mon Jul 09 22:31:28 2012 +0000
- Revision:
- 0:db9ea2448fdd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ficofer | 0:db9ea2448fdd | 1 | /* |
ficofer | 0:db9ea2448fdd | 2 | * |
ficofer | 0:db9ea2448fdd | 3 | * utils.c functions to work with ethernet frames |
ficofer | 0:db9ea2448fdd | 4 | * |
ficofer | 0:db9ea2448fdd | 5 | * |
ficofer | 0:db9ea2448fdd | 6 | */ |
ficofer | 0:db9ea2448fdd | 7 | |
ficofer | 0:db9ea2448fdd | 8 | #include <stdio.h> |
ficofer | 0:db9ea2448fdd | 9 | #include <stdlib.h> |
ficofer | 0:db9ea2448fdd | 10 | #include <string.h> |
ficofer | 0:db9ea2448fdd | 11 | #include <inet.h> |
ficofer | 0:db9ea2448fdd | 12 | #include "mbed.h" |
ficofer | 0:db9ea2448fdd | 13 | #include "EthernetNetIf.h" |
ficofer | 0:db9ea2448fdd | 14 | #include "defines.h" |
ficofer | 0:db9ea2448fdd | 15 | #include "utils.h" |
ficofer | 0:db9ea2448fdd | 16 | #include "variables.h" |
ficofer | 0:db9ea2448fdd | 17 | |
ficofer | 0:db9ea2448fdd | 18 | extern "C" void |
ficofer | 0:db9ea2448fdd | 19 | mbed_mac_address(char *mac); |
ficofer | 0:db9ea2448fdd | 20 | |
ficofer | 0:db9ea2448fdd | 21 | static |
ficofer | 0:db9ea2448fdd | 22 | void |
ficofer | 0:db9ea2448fdd | 23 | set_to_mac( char *peth, char const *pmac ) |
ficofer | 0:db9ea2448fdd | 24 | { |
ficofer | 0:db9ea2448fdd | 25 | memcpy( peth, pmac, MAC_ADD_NUM ); |
ficofer | 0:db9ea2448fdd | 26 | } |
ficofer | 0:db9ea2448fdd | 27 | |
ficofer | 0:db9ea2448fdd | 28 | static |
ficofer | 0:db9ea2448fdd | 29 | void |
ficofer | 0:db9ea2448fdd | 30 | set_from_mac( char *peth, char const *pmac ) |
ficofer | 0:db9ea2448fdd | 31 | { |
ficofer | 0:db9ea2448fdd | 32 | memcpy( peth + MAC_ADD_NUM, pmac, MAC_ADD_NUM ); |
ficofer | 0:db9ea2448fdd | 33 | } |
ficofer | 0:db9ea2448fdd | 34 | |
ficofer | 0:db9ea2448fdd | 35 | static |
ficofer | 0:db9ea2448fdd | 36 | void |
ficofer | 0:db9ea2448fdd | 37 | set_ether_type( char *peth, unsigned ether_type ) |
ficofer | 0:db9ea2448fdd | 38 | { |
ficofer | 0:db9ea2448fdd | 39 | unsigned short etype; |
ficofer | 0:db9ea2448fdd | 40 | |
ficofer | 0:db9ea2448fdd | 41 | etype = ether_type; |
ficofer | 0:db9ea2448fdd | 42 | etype = htons(etype); |
ficofer | 0:db9ea2448fdd | 43 | memcpy( peth + 2*MAC_ADD_NUM, &etype, sizeof(unsigned short) ); |
ficofer | 0:db9ea2448fdd | 44 | } |