mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-03 15:41:54 +00:00
Socktest: Renaming
This commit is contained in:
parent
a6e111ae54
commit
e4a6c41236
@ -39,12 +39,12 @@ err_hook(sock *s, int err)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Err(%d): %s \n", err, s->err);
|
perror("err_hook: ");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
skt_open(sock *s)
|
socktest_open(sock *s)
|
||||||
{
|
{
|
||||||
if (sk_open(s) < 0)
|
if (sk_open(s) < 0)
|
||||||
{
|
{
|
||||||
@ -63,7 +63,7 @@ skt_open(sock *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sock *
|
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;
|
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:";
|
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;
|
goto usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_recv && s->type == SK_UDP) /* XXX: Weird */
|
if (is_recv && s->type == SK_UDP)
|
||||||
s->sport = port;
|
s->sport = port;
|
||||||
else
|
else
|
||||||
s->dport = port;
|
s->dport = port;
|
||||||
@ -148,7 +148,7 @@ skt_parse_args(int argc, char *argv[], int is_send)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
scan_infaces(void)
|
scan_interfaces(void)
|
||||||
{
|
{
|
||||||
/* create mockup config */
|
/* create mockup config */
|
||||||
struct config *c = config_alloc("mockup");
|
struct config *c = config_alloc("mockup");
|
||||||
@ -169,11 +169,11 @@ scan_infaces(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bird_init(void)
|
socktest_bird_init(void)
|
||||||
{
|
{
|
||||||
log_switch(1, NULL, NULL);
|
log_switch(1, NULL, NULL);
|
||||||
resource_init();
|
resource_init();
|
||||||
io_init();
|
io_init();
|
||||||
if_init();
|
if_init();
|
||||||
scan_infaces();
|
scan_interfaces();
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,11 @@
|
|||||||
#include "lib/unix.h"
|
#include "lib/unix.h"
|
||||||
|
|
||||||
|
|
||||||
//#define PKT_MAGIC 0x12345678
|
|
||||||
#define PKT_MAGIC 42
|
|
||||||
|
|
||||||
#define PKT_PORT 100
|
#define PKT_PORT 100
|
||||||
#define PKT_VALUE 0
|
#define PKT_VALUE 0
|
||||||
|
#define PKT_MAGIC 0x12345678
|
||||||
|
|
||||||
struct my_packet
|
struct socktest_packet
|
||||||
{
|
{
|
||||||
u32 magic;
|
u32 magic;
|
||||||
u32 value;
|
u32 value;
|
||||||
@ -48,12 +46,12 @@ int cf_mcast; /* Set up multicast */
|
|||||||
int cf_bcast; /* Enable broadcast */
|
int cf_bcast; /* Enable broadcast */
|
||||||
int cf_bind; /* Bind by address */
|
int cf_bind; /* Bind by address */
|
||||||
uint cf_count; /* How many packets send */
|
uint cf_count; /* How many packets send */
|
||||||
uint counter; /* global counter of send/recv packets */
|
uint counter; /* Global counter of send/recv packets */
|
||||||
uint cf_value; /* a value in packet */
|
uint cf_value; /* Value in packet */
|
||||||
|
|
||||||
sock *skt_parse_args(int argc, char **argv, int is_send);
|
sock *socktest_parse_args(int argc, char **argv, int is_send);
|
||||||
void bird_init(void);
|
void socktest_bird_init(void);
|
||||||
void skt_open(sock *s);
|
void socktest_open(sock *s);
|
||||||
|
|
||||||
/* implementation in io.c */
|
/* implementation in io.c */
|
||||||
int sk_write(sock *s);
|
int sk_write(sock *s);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* <src>:<port> -> <dst> ifa(<id>) <name>: pkt <value>/<count>, ttl <ttl>
|
* <src>:<port> -> <dst> ifa(<id>) <name>: pkt <value>/<count>, ttl <ttl>
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
rcv_print(sock *sk, struct my_packet *pkt)
|
rcv_print(sock *sk, struct socktest_packet *pkt)
|
||||||
{
|
{
|
||||||
char ifa_name[IF_NAMESIZE];
|
char ifa_name[IF_NAMESIZE];
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
@ -42,7 +42,7 @@ rcv_print(sock *sk, struct my_packet *pkt)
|
|||||||
static int
|
static int
|
||||||
rcv_hook(sock *sk, int size)
|
rcv_hook(sock *sk, int size)
|
||||||
{
|
{
|
||||||
struct my_packet *raw;
|
struct socktest_packet *raw;
|
||||||
|
|
||||||
if (cf_count && ++counter > cf_count)
|
if (cf_count && ++counter > cf_count)
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -52,13 +52,13 @@ rcv_hook(sock *sk, int size)
|
|||||||
else
|
else
|
||||||
raw = (void *) sk->rbuf;
|
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);
|
printf("Received a packet with unexpected length of %d bytes \n", size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct my_packet pkt = {
|
struct socktest_packet pkt = {
|
||||||
.magic = ntohl(raw->magic),
|
.magic = ntohl(raw->magic),
|
||||||
.value = ntohl(raw->value),
|
.value = ntohl(raw->value),
|
||||||
.count = ntohl(raw->count),
|
.count = ntohl(raw->count),
|
||||||
@ -73,14 +73,14 @@ rcv_hook(sock *sk, int size)
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
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->rx_hook = rcv_hook;
|
||||||
s->rbsize = 1500;
|
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)
|
while (1)
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
int
|
static int
|
||||||
do_sendmsg(sock *s, void *pkt, size_t len)
|
do_sendmsg(sock *s, void *pkt, size_t len)
|
||||||
{
|
{
|
||||||
memcpy(s->ttx, pkt, len);
|
memcpy(s->ttx, pkt, len);
|
||||||
@ -12,7 +12,7 @@ do_sendmsg(sock *s, void *pkt, size_t len)
|
|||||||
return sk_write(s);
|
return sk_write(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
connected_hook(sock *s)
|
connected_hook(sock *s)
|
||||||
{
|
{
|
||||||
printf("Start sending...\n");
|
printf("Start sending...\n");
|
||||||
@ -22,16 +22,16 @@ connected_hook(sock *s)
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
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->tx_hook = connected_hook;
|
||||||
s->tbsize = 1500;
|
s->tbsize = 1500;
|
||||||
s->tos = IP_PREC_INTERNET_CONTROL;
|
s->tos = IP_PREC_INTERNET_CONTROL;
|
||||||
|
|
||||||
skt_open(s);
|
socktest_open(s);
|
||||||
|
|
||||||
struct my_packet pkt = {
|
struct socktest_packet pkt = {
|
||||||
.magic = htonl(PKT_MAGIC),
|
.magic = htonl(PKT_MAGIC),
|
||||||
.value = htonl(cf_value),
|
.value = htonl(cf_value),
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user