From e4a6c4123683d171c03b6916986c88eabd713905 Mon Sep 17 00:00:00 2001 From: Pavel Tvrdik Date: Wed, 6 Apr 2016 15:46:02 +0200 Subject: [PATCH] Socktest: Renaming --- socktest/common.c | 14 +++++++------- socktest/common.h | 16 +++++++--------- socktest/rcv.c | 16 ++++++++-------- socktest/snd.c | 12 ++++++------ 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/socktest/common.c b/socktest/common.c index 7e763752..d825ace5 100644 --- a/socktest/common.c +++ b/socktest/common.c @@ -39,12 +39,12 @@ err_hook(sock *s, int err) return; } - printf("Err(%d): %s \n", err, s->err); + perror("err_hook: "); exit(1); } void -skt_open(sock *s) +socktest_open(sock *s) { if (sk_open(s) < 0) { @@ -63,7 +63,7 @@ skt_open(sock *s) } sock * -skt_parse_args(int argc, char *argv[], int is_send) +socktest_parse_args(int argc, char *argv[], int is_send) { int is_recv = !is_send; const char *opt_list = is_send ? "bumi:l:p:v:t:c:B:" : "bum:i:l:p:v:t:c:B:"; @@ -128,7 +128,7 @@ skt_parse_args(int argc, char *argv[], int is_send) goto usage; } - if (is_recv && s->type == SK_UDP) /* XXX: Weird */ + if (is_recv && s->type == SK_UDP) s->sport = port; else s->dport = port; @@ -148,7 +148,7 @@ skt_parse_args(int argc, char *argv[], int is_send) } static void -scan_infaces(void) +scan_interfaces(void) { /* create mockup config */ struct config *c = config_alloc("mockup"); @@ -169,11 +169,11 @@ scan_infaces(void) } void -bird_init(void) +socktest_bird_init(void) { log_switch(1, NULL, NULL); resource_init(); io_init(); if_init(); - scan_infaces(); + scan_interfaces(); } diff --git a/socktest/common.h b/socktest/common.h index a8b3f5fa..dd77cce4 100644 --- a/socktest/common.h +++ b/socktest/common.h @@ -31,13 +31,11 @@ #include "lib/unix.h" -//#define PKT_MAGIC 0x12345678 -#define PKT_MAGIC 42 - #define PKT_PORT 100 #define PKT_VALUE 0 +#define PKT_MAGIC 0x12345678 -struct my_packet +struct socktest_packet { u32 magic; u32 value; @@ -48,12 +46,12 @@ int cf_mcast; /* Set up multicast */ int cf_bcast; /* Enable broadcast */ int cf_bind; /* Bind by address */ uint cf_count; /* How many packets send */ -uint counter; /* global counter of send/recv packets */ -uint cf_value; /* a value in packet */ +uint counter; /* Global counter of send/recv packets */ +uint cf_value; /* Value in packet */ -sock *skt_parse_args(int argc, char **argv, int is_send); -void bird_init(void); -void skt_open(sock *s); +sock *socktest_parse_args(int argc, char **argv, int is_send); +void socktest_bird_init(void); +void socktest_open(sock *s); /* implementation in io.c */ int sk_write(sock *s); diff --git a/socktest/rcv.c b/socktest/rcv.c index ce9952fd..1ea5f536 100644 --- a/socktest/rcv.c +++ b/socktest/rcv.c @@ -5,7 +5,7 @@ * : -> ifa() : pkt /, ttl */ static void -rcv_print(sock *sk, struct my_packet *pkt) +rcv_print(sock *sk, struct socktest_packet *pkt) { char ifa_name[IF_NAMESIZE]; char buf[1024]; @@ -42,7 +42,7 @@ rcv_print(sock *sk, struct my_packet *pkt) static int rcv_hook(sock *sk, int size) { - struct my_packet *raw; + struct socktest_packet *raw; if (cf_count && ++counter > cf_count) exit(0); @@ -52,13 +52,13 @@ rcv_hook(sock *sk, int size) else raw = (void *) sk->rbuf; - if (size != sizeof(struct my_packet)) + if (size != sizeof(struct socktest_packet)) { printf("Received a packet with unexpected length of %d bytes \n", size); return 1; } - struct my_packet pkt = { + struct socktest_packet pkt = { .magic = ntohl(raw->magic), .value = ntohl(raw->value), .count = ntohl(raw->count), @@ -73,14 +73,14 @@ rcv_hook(sock *sk, int size) int main(int argc, char *argv[]) { - bird_init(); + socktest_bird_init(); - sock *s = skt_parse_args(argc, argv, 0); + sock *s = socktest_parse_args(argc, argv, 0); s->rx_hook = rcv_hook; s->rbsize = 1500; - s->flags |= SKF_LADDR_RX | SKF_TTL_RX | SKF_PKTINFO; + s->flags |= SKF_LADDR_RX | SKF_TTL_RX; - skt_open(s); + socktest_open(s); while (1) { diff --git a/socktest/snd.c b/socktest/snd.c index 3d866849..ee5d8c72 100644 --- a/socktest/snd.c +++ b/socktest/snd.c @@ -1,6 +1,6 @@ #include "common.h" -int +static int do_sendmsg(sock *s, void *pkt, size_t len) { memcpy(s->ttx, pkt, len); @@ -12,7 +12,7 @@ do_sendmsg(sock *s, void *pkt, size_t len) return sk_write(s); } -void +static void connected_hook(sock *s) { printf("Start sending...\n"); @@ -22,16 +22,16 @@ connected_hook(sock *s) int main(int argc, char *argv[]) { - bird_init(); + socktest_bird_init(); - sock *s = skt_parse_args(argc, argv, 1); + sock *s = socktest_parse_args(argc, argv, 1); s->tx_hook = connected_hook; s->tbsize = 1500; s->tos = IP_PREC_INTERNET_CONTROL; - skt_open(s); + socktest_open(s); - struct my_packet pkt = { + struct socktest_packet pkt = { .magic = htonl(PKT_MAGIC), .value = htonl(cf_value), };