-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmsg_send.c
36 lines (30 loc) · 972 Bytes
/
msg_send.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
#include "unp.h"
#define PATH_LEN 15
/*the parameter dest_path needs to change into int pnum < port value , sun_path name>*/
ssize_t msg_send(int sockfd, SA* peer_addr, socklen_t plen, char* dest_ipaddr, char *dest_path, char* msg, int flag){
int n;
socklen_t len;
char c_flag[2];
unsigned char buffer[MAXLINE];
if(sprintf(c_flag, "%d", flag) < 0){
err_sys("[ERROR]: sprintf error");
}
bzero(buffer, MAXLINE);
strcat(buffer, c_flag);
strcat(buffer, "|");
strcat(buffer, dest_ipaddr);
strcat(buffer, "|");
strcat(buffer, dest_path);
strcat(buffer, "|");
strcat(buffer, msg);
printf("in msg_send:\n");
printf("%d\n", flag);
printf("%s\n", dest_ipaddr);
printf("%s\n", dest_path);
printf("%s\n", msg);
len = plen;
if((n = sendto(sockfd, buffer, strlen(buffer), 0, peer_addr, len)) < 0){
return (-1);
}
return n;
}