#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "licks_message.h" int socket_fd; struct pollfd poll_pollfd; struct timespec timeout_ts; struct sockaddr_in localaddr; struct sockaddr_in remoteaddr; socklen_t remoteaddr_len; const int port=1337; void licks_socket_open() { socket_fd=socket(PF_INET,SOCK_DGRAM,0); if(socket_fd==-1) { perror("socket"); exit(0); } printf("socket %d\n",socket_fd); localaddr.sin_family=AF_INET; localaddr.sin_port=htons(port); inet_aton("0.0.0.0",&localaddr.sin_addr); if(bind(socket_fd,(struct sockaddr *)&localaddr,sizeof(struct sockaddr_in))) { perror("bind"); exit(0); } // printf("bound to %s\n",localaddr.sun_path); poll_pollfd.fd=socket_fd; poll_pollfd.events=POLLIN; remoteaddr.sin_family=AF_INET; } int licks_socket_poll() { return poll(&poll_pollfd,1,0); } void licks_socket_close() { close(socket_fd); } //void //send_message(licks_message *m, char *to) { // strcpy(remoteaddr.sin_path,to); // sendto(socket_fd,m,sizeof(licks_message),0,(struct sockaddr *)&remoteaddr,sizeof(struct sockaddr_in)); //} void send_reply(licks_message *m) { sendto(socket_fd,m,strlen(m),0,(struct sockaddr *)&remoteaddr,sizeof(struct sockaddr_in)); } char * receive_message(licks_message *m) { size_t real_len; remoteaddr_len=sizeof(struct sockaddr_in); memset(m,0,sizeof(licks_message)); real_len=recvfrom(socket_fd,m,sizeof(licks_message)-1,0,(struct sockaddr *)&remoteaddr,&remoteaddr_len); return 0; }