Rev 1063 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include <kernel/kern.h>
#include <drivers/udpip.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
UDP_ADDR target
, local
;
int socket
;
IP_ADDR bindlist
[5];
char local_ip
[20], target_ip
[20], buff
[10];
static int pkt_number
=0;
typedef struct tests_udp_header
{
char id
[12];
unsigned int pkt_number
;
unsigned int size
;
} tests_udp_header
;
#define HEADER "TEST"
#define LOCAL_ADDR "192.168.82.246"
#define REMOTE_ADDR "192.168.82.205"
/* Init the network stack */
int init_network
(void)
{
struct net_model m
= net_base
;
strcpy(local_ip
, LOCAL_ADDR
);
strcpy(target_ip
, REMOTE_ADDR
);
ip_str2addr
(local_ip
,&(local.
s_addr));
/* set the source port */
local.
s_port = 24000;
/* target IP string to addr */
ip_str2addr
(target_ip
,&(bindlist
[0]));
memset(&(bindlist
[1]), 0, sizeof(IP_ADDR
));
/* bind */
socket
= udp_bind
(&local
, NULL
);
/* target IP string to addr */
ip_str2addr
(target_ip
,&(target.
s_addr));
/* target port */
target.
s_port = 24000;
net_setudpip
(m
, local_ip
, "255.255.255.255");
if (net_init
(&m
) != 1) {
cprintf
("Network: Init Error.\n");
return -1;
}
return 0;
}
int udp_print
(char *str
, ...
)
{
static char cbuf
[1024];
char *p
=cbuf
;
va_list parms
;
int result
;
int err
=0;
p
+=sizeof(tests_udp_header
);
va_start(parms
,str
);
result
= vsprintf(p
,str
,parms
);
va_end(parms
);
((tests_udp_header
*)cbuf
)->pkt_number
=pkt_number
;
strncpy(cbuf
,HEADER
, strlen(HEADER
)+1);
pkt_number
++;
((tests_udp_header
*)cbuf
)->size
=result
;
err
=udp_sendto
(socket
, cbuf
, sizeof(tests_udp_header
)+result
,&target
);
sleep
(1);
return err
;
}