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)
{
}
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:";
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;
}
static void
-scan_infaces(void)
+scan_interfaces(void)
{
/* create mockup config */
struct config *c = config_alloc("mockup");
}
void
-bird_init(void)
+socktest_bird_init(void)
{
log_switch(1, NULL, NULL);
resource_init();
io_init();
if_init();
- scan_infaces();
+ scan_interfaces();
}
#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;
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);
* <src>:<port> -> <dst> ifa(<id>) <name>: pkt <value>/<count>, ttl <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];
static int
rcv_hook(sock *sk, int size)
{
- struct my_packet *raw;
+ struct socktest_packet *raw;
if (cf_count && ++counter > cf_count)
exit(0);
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),
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)
{
#include "common.h"
-int
+static int
do_sendmsg(sock *s, void *pkt, size_t len)
{
memcpy(s->ttx, pkt, len);
return sk_write(s);
}
-void
+static void
connected_hook(sock *s)
{
printf("Start sending...\n");
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),
};