New file |
| | |
| | | /* |
| | | * is-little-endian.c |
| | | */ |
| | | |
| | | #include <stdio.h> |
| | | #include <stdint.h> |
| | | #include <stdlib.h> |
| | | #include <inttypes.h> |
| | | #include <byteswap.h> |
| | | |
| | | typedef unsigned char* byte_pointer; |
| | | |
| | | int is_little_endian() { |
| | | int test_num = 0xff; |
| | | byte_pointer byte_start = (byte_pointer) &test_num; |
| | | |
| | | if (byte_start[0] == 0xff) { |
| | | return 1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | int |
| | | main(int argc, char *argv[]) |
| | | { |
| | | uint64_t x; |
| | | |
| | | if (argc != 2) { |
| | | fprintf(stderr, "Usage: %s <num>\n", argv[0]); |
| | | exit(EXIT_FAILURE); |
| | | } |
| | | |
| | | x = strtoul(argv[1], NULL, 0); |
| | | printf("0x%" PRIx64 " ==> 0x%" PRIx64 "\n", x, bswap_64(x)); |
| | | |
| | | exit(EXIT_SUCCESS); |
| | | } |
| | | |
| | | |
New file |
| | |
| | | function server() { |
| | | ipcrm -a |
| | | ./dgram_mod_req_rep server 11 & |
| | | ./dgram_mod_req_rep server 12 & |
| | | ./dgram_mod_req_rep server 13 & |
| | | ./dgram_mod_req_rep server 14 & |
| | | |
| | | ./net_mod_req_rep server 5000 & |
| | | |
| | | } |
| | | |
| | | function client() { |
| | | ./net_mod_req_rep client 5000 |
| | | } |
| | | |
| | | function clean() { |
| | | ps -ef | grep -e "dgram_mod_req_rep" -e "net_mod_req_rep" | awk '{print $2}' | xargs -i kill -9 {} |
| | | ipcrm -a |
| | | } |
| | | |
| | | case ${1} in |
| | | "server") |
| | | server |
| | | ;; |
| | | "client") |
| | | client |
| | | ;; |
| | | "clean") |
| | | clean |
| | | ;; |
| | | "") |
| | | clean |
| | | server |
| | | client |
| | | ;; |
| | | *) |
| | | echo "error input" |
| | | exit 1 |
| | | ;; |
| | | esac |