#include #include #include #include #include #include #include #include #include "message.h" int unix_socket_fd; struct licks_message message; struct sockaddr_un localaddr; struct sockaddr_un remoteaddr; socklen_t remoteaddr_len; char *ikd_path="/tmp/ikd"; int main(int argc, char **argv) { int l,i; // create socket unix_socket_fd=socket(PF_LOCAL,SOCK_DGRAM,0); if(unix_socket_fd==-1) { perror("socket"); exit(0); } printf("socket %d\n",unix_socket_fd); // bind to socket, localaddr is the pid sprintf(localaddr.sun_path,"/tmp/client%d",getpid()); localaddr.sun_family=AF_LOCAL; // localaddr.sun_len=strlen(localaddr.sun_path)+1; if(bind(unix_socket_fd,(struct sockaddr *)&localaddr,sizeof(struct sockaddr_un))) { perror("bind"); exit(0); } printf("bound\n"); message.type=MSG_CHAR_ARRAY; for(i=0;i<32;i++) { message.char_array[i]=i; } remoteaddr.sun_family=AF_LOCAL; // remoteaddr.sun_len=strlen(ikd_path); strcpy(remoteaddr.sun_path,ikd_path); l=sendto(unix_socket_fd,&message,sizeof(message),0,(struct sockaddr *)&remoteaddr,sizeof(struct sockaddr_un)); printf("sendto: %d\n",l); if(l==-1) { perror("sendto"); } remoteaddr_len=sizeof(struct sockaddr_un); l=recvfrom(unix_socket_fd,&message,sizeof(struct licks_message),0,(struct sockaddr *)&remoteaddr,&remoteaddr_len); printf("recvfrom: %d\n",l); // printf("sun_len: %d\n",remoteaddr.sun_len); printf("sun_addr: %s\n",remoteaddr.sun_path); printf("message type: %d\n",message.type); for(i=0;i<32;i++) { if(!(i%8)) { printf("\n"); } printf("%02x ",message.char_array[i]); } printf("\n"); close(unix_socket_fd); unlink(localaddr.sun_path); return 0; }