Subversion Repositories shark

Rev

Rev 951 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1063 tullio 1
 
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program; if not, write to the Free Software
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 *
17
 */
18
 
951 trimarchi 19
#include <kernel/kern.h>
20
#include <drivers/udpip.h>
21
 
22
#include <stdlib.h>
23
#include <string.h>
24
#include <unistd.h>
25
 
26
UDP_ADDR target, local;
27
int      socket;
28
IP_ADDR  bindlist[5];
29
char local_ip[20], target_ip[20], buff[10];
30
static int pkt_number=0;
31
 
32
typedef struct tests_udp_header {
33
  char id[12];
34
  unsigned int pkt_number;
35
  unsigned int size;
36
} tests_udp_header;
37
 
38
#define HEADER "TEST"
39
#define LOCAL_ADDR "192.168.82.246"
40
#define REMOTE_ADDR "192.168.82.205"
41
 
42
/* Init the network stack */
43
int init_network(void)
44
{
45
  struct net_model m = net_base;
46
 
47
  strcpy(local_ip,  LOCAL_ADDR);
48
  strcpy(target_ip, REMOTE_ADDR);
49
 
50
  ip_str2addr(local_ip,&(local.s_addr));
51
  /* set the source port */
52
  local.s_port = 24000;
53
 
54
  /* target IP string to addr */
55
  ip_str2addr(target_ip,&(bindlist[0]));
56
  memset(&(bindlist[1]), 0, sizeof(IP_ADDR));
57
  /* bind */
58
  socket = udp_bind(&local, NULL);
59
 
60
  /* target IP string to addr */
61
  ip_str2addr(target_ip,&(target.s_addr));
62
  /* target port */
63
  target.s_port = 24000;
64
 
65
  net_setudpip(m, local_ip, "255.255.255.255");
66
 
67
  if (net_init(&m) != 1) {
68
    cprintf("Network: Init Error.\n");
69
    return -1;
70
  }
71
 
72
  return 0;
73
 
74
}
75
 
76
 
77
int udp_print(char *str, ...)
78
{
79
  static char cbuf[1024];
80
  char *p=cbuf;
81
  va_list parms;
82
  int result;
83
  int err=0;
84
 
85
  p+=sizeof(tests_udp_header);
86
  va_start(parms,str);
87
  result = vsprintf(p,str,parms);
88
  va_end(parms);
89
  ((tests_udp_header *)cbuf)->pkt_number=pkt_number;
90
  strncpy(cbuf,HEADER, strlen(HEADER)+1);  
91
  pkt_number++;
92
  ((tests_udp_header *)cbuf)->size=result;
93
 
94
  err=udp_sendto(socket, cbuf, sizeof(tests_udp_header)+result,&target);
95
  sleep(1);
96
  return err;
97
}
98