-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_lib.c
54 lines (38 loc) · 1.14 KB
/
time_lib.c
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
#include "time_lib.h"
#if ODR_DEBUG
#define dprintf(fmt, args...) printf(fmt, ##args)
#else
#define dprintf(fmt, args...)
#endif
int msg_recv(int sockfd,char* msg_recvd,char* ip,int* src_port)
{
rpacket packet;
int ret;
memset(&packet,0,sizeof(rpacket));
dprintf("in %s waiting for data sockfd %d\n",__FUNCTION__,sockfd);
ret=recvfrom(sockfd,(char *)&packet, sizeof(rpacket),0,NULL,NULL);
dprintf("data read from sockfd in %s\n",__FUNCTION__);
if(ret!=sizeof(rpacket))
{
printf("data read error from UDS in %s\n",__FUNCTION__);
return -1;
}
memcpy(msg_recvd,packet.msg,MSG_LEN);
memcpy(ip,packet.ip,IP_LEN);
*src_port = packet.src_port;
return 0;
}
int msg_send(int sockfd, char* ip,int dest_port,char* msg,int flag)
{
spacket packet;
struct sockaddr_un servaddr;
memset(&packet,0,sizeof(packet));
memset(&servaddr,0,sizeof(servaddr));
servaddr.sun_family =AF_LOCAL;
strcpy(servaddr.sun_path,UNIX_D_PATH);
memcpy(packet.ip,ip,IP_LEN);
packet.dest_port = dest_port;
strcpy(packet.msg,msg);
packet.force_flag = flag;
return sendto(sockfd,(char *)&packet,sizeof(packet),0,(struct sockaddr*)&servaddr,sizeof(servaddr));
}