Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
951 trimarchi 1
#include <kernel/kern.h>
2
#include <drivers/udpip.h>
3
 
4
#include <stdlib.h>
5
#include <string.h>
6
#include <unistd.h>
7
 
8
UDP_ADDR target, local;
9
int      socket;
10
IP_ADDR  bindlist[5];
11
char local_ip[20], target_ip[20], buff[10];
12
static int pkt_number=0;
13
 
14
typedef struct tests_udp_header {
15
  char id[12];
16
  unsigned int pkt_number;
17
  unsigned int size;
18
} tests_udp_header;
19
 
20
#define HEADER "TEST"
21
#define LOCAL_ADDR "192.168.82.246"
22
#define REMOTE_ADDR "192.168.82.205"
23
 
24
/* Init the network stack */
25
int init_network(void)
26
{
27
  struct net_model m = net_base;
28
 
29
  strcpy(local_ip,  LOCAL_ADDR);
30
  strcpy(target_ip, REMOTE_ADDR);
31
 
32
  ip_str2addr(local_ip,&(local.s_addr));
33
  /* set the source port */
34
  local.s_port = 24000;
35
 
36
  /* target IP string to addr */
37
  ip_str2addr(target_ip,&(bindlist[0]));
38
  memset(&(bindlist[1]), 0, sizeof(IP_ADDR));
39
  /* bind */
40
  socket = udp_bind(&local, NULL);
41
 
42
  /* target IP string to addr */
43
  ip_str2addr(target_ip,&(target.s_addr));
44
  /* target port */
45
  target.s_port = 24000;
46
 
47
  net_setudpip(m, local_ip, "255.255.255.255");
48
 
49
  if (net_init(&m) != 1) {
50
    cprintf("Network: Init Error.\n");
51
    return -1;
52
  }
53
 
54
  return 0;
55
 
56
}
57
 
58
 
59
int udp_print(char *str, ...)
60
{
61
  static char cbuf[1024];
62
  char *p=cbuf;
63
  va_list parms;
64
  int result;
65
  int err=0;
66
 
67
  p+=sizeof(tests_udp_header);
68
  va_start(parms,str);
69
  result = vsprintf(p,str,parms);
70
  va_end(parms);
71
  ((tests_udp_header *)cbuf)->pkt_number=pkt_number;
72
  strncpy(cbuf,HEADER, strlen(HEADER)+1);  
73
  pkt_number++;
74
  ((tests_udp_header *)cbuf)->size=result;
75
 
76
  err=udp_sendto(socket, cbuf, sizeof(tests_udp_header)+result,&target);
77
  sleep(1);
78
  return err;
79
}
80