Subversion Repositories shark

Rev

Rev 1550 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1405 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
1606 tullio 18
/*
19
 * This program is free software; you can redistribute it and/or modify
20
 * it under the terms of the GNU General Public License as published by
21
 * the Free Software Foundation; either version 2 of the License, or
22
 * (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU General Public License
30
 * along with this program; if not, write to the Free Software
31
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
 *
33
 */
34
 
1405 giacomo 35
#include <kernel/kern.h>
36
#include <drivers/udpip.h>
37
 
38
#include <stdlib.h>
39
#include <string.h>
40
#include <unistd.h>
41
 
42
/* Init the network stack */
43
int init_network(char *local_ip)
44
{
45
 
46
        struct net_model m = net_base;
47
 
48
        net_setudpip(m, local_ip, "255.255.255.255");
49
 
50
        if (net_init(&m) != 1) {
51
                cprintf("Network: Init Error.\n");
52
                return -1;
53
        }
54
 
55
        return 0;
56
 
57
}
58
 
59
int main(int argc, char **argv)
60
{
61
        UDP_ADDR target, local;
62
        char local_ip[20], target_ip[20], buff[10];
63
        int socket, i;
64
        IP_ADDR bindlist[5];
65
 
66
        strcpy(local_ip,  "192.168.1.10");
67
        strcpy(target_ip, "192.168.1.1");
68
 
1550 pj 69
        if (init_network(local_ip)) exit(1);
1405 giacomo 70
 
71
        /* local IP string to addr */
72
        ip_str2addr(local_ip,&(local.s_addr));
73
        /* set the source port */
74
        local.s_port = 100;
75
 
76
        /* target IP string to addr */
77
        ip_str2addr(target_ip,&(bindlist[0]));
78
        memset(&(bindlist[1]), 0, sizeof(IP_ADDR));
79
        /* bind */
80
        socket = udp_bind(&local, NULL);
81
 
82
        /* target IP string to addr */
83
        ip_str2addr(target_ip,&(target.s_addr));
84
        /* target port */
85
        target.s_port = 100;
86
 
87
        for (i = 0; i < 5; i++) {
88
                strcpy(buff, "qwerty\n");
89
                cprintf("Send packet: %s\n", buff);
90
                udp_sendto(socket, buff, strlen(buff), &target);
91
                sleep(1);
92
        }
93
 
94
        cprintf("The End.\n");
95
 
1550 pj 96
        exit(1);
1405 giacomo 97
 
98
        return 0;
99
}