Rev 1405 | Go to most recent revision | 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 | |||
18 | #include <kernel/kern.h> |
||
19 | #include <drivers/udpip.h> |
||
20 | |||
21 | #include <stdlib.h> |
||
22 | #include <string.h> |
||
23 | #include <unistd.h> |
||
24 | |||
25 | /* Init the network stack */ |
||
26 | int init_network(char *local_ip) |
||
27 | { |
||
28 | |||
29 | struct net_model m = net_base; |
||
30 | |||
31 | net_setudpip(m, local_ip, "255.255.255.255"); |
||
32 | |||
33 | if (net_init(&m) != 1) { |
||
34 | cprintf("Network: Init Error.\n"); |
||
35 | return -1; |
||
36 | } |
||
37 | |||
38 | return 0; |
||
39 | |||
40 | } |
||
41 | |||
42 | int main(int argc, char **argv) |
||
43 | { |
||
44 | UDP_ADDR target, local; |
||
45 | char local_ip[20], target_ip[20], buff[10]; |
||
46 | int socket, i; |
||
47 | IP_ADDR bindlist[5]; |
||
48 | |||
49 | strcpy(local_ip, "192.168.1.10"); |
||
50 | strcpy(target_ip, "192.168.1.1"); |
||
51 | |||
1550 | pj | 52 | if (init_network(local_ip)) exit(1); |
1405 | giacomo | 53 | |
54 | /* local IP string to addr */ |
||
55 | ip_str2addr(local_ip,&(local.s_addr)); |
||
56 | /* set the source port */ |
||
57 | local.s_port = 100; |
||
58 | |||
59 | /* target IP string to addr */ |
||
60 | ip_str2addr(target_ip,&(bindlist[0])); |
||
61 | memset(&(bindlist[1]), 0, sizeof(IP_ADDR)); |
||
62 | /* bind */ |
||
63 | socket = udp_bind(&local, NULL); |
||
64 | |||
65 | /* target IP string to addr */ |
||
66 | ip_str2addr(target_ip,&(target.s_addr)); |
||
67 | /* target port */ |
||
68 | target.s_port = 100; |
||
69 | |||
70 | for (i = 0; i < 5; i++) { |
||
71 | strcpy(buff, "qwerty\n"); |
||
72 | cprintf("Send packet: %s\n", buff); |
||
73 | udp_sendto(socket, buff, strlen(buff), &target); |
||
74 | sleep(1); |
||
75 | } |
||
76 | |||
77 | cprintf("The End.\n"); |
||
78 | |||
1550 | pj | 79 | exit(1); |
1405 | giacomo | 80 | |
81 | return 0; |
||
82 | } |