-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprocesses.c
More file actions
54 lines (46 loc) · 1.4 KB
/
processes.c
File metadata and controls
54 lines (46 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Code for virtual processes
*/
////
// Include files
////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libarrays.h>
#include <libevents.h>
#include "netether.h"
#include "netip.h"
#include "stack.h"
////
// Constants
////
////
// Global variables
////
////
// Processus implementing an UDP echo
////
#define UDP_ECHO_PROMPT "> "
unsigned char udp_echo( unsigned char type, SocketAddress to,SocketAddress from, unsigned char *data,int size){
printf("\n%sudp_echo: %s type=%x\n", BMAGENTA, BLACK,type);
if(type==PROCESS_DATA){
printf("%sudp_echo: %s(%s,%hu)%s",BLUE, BBLACK, ipAddress2String(from.address),from.port, BLACK);
printf("%s->(%s,%hu)%s\n", BBLUE, ipAddress2String(to.address),to.port, BLACK);
printf("%s size : %d%s\n", BBLUE, size, BLACK);
data=(unsigned char *)realloc(data,size+2);
memmove(data+2,data,size);
memcpy(data,UDP_ECHO_PROMPT,strlen(UDP_ECHO_PROMPT));
return stackUDPSendDatagram(from.address,from.port,data,size+2);
}
/*if(type==PROCESS_ERROR){
printf("Error port unreachable : (%s,%hu)",ipAddress2String(from.address),from.port);
printf("->(%s,%hu)\n",ipAddress2String(to.address),to.port);
printf(" size : %d\n", size);
data=(unsigned char *)realloc(data,size+2);
memmove(data+2,data,size);
memcpy(data,UDP_ECHO_PROMPT,strlen(UDP_ECHO_PROMPT));
return stackUDPSendDatagram(from.address,from.port,data,size+2);
}*/
return 0;
}