1 /* posix */ 2 #include <sys/types.h> 3 #include <unistd.h> 4 #include <stdlib.h> 5 #include <stdio.h> 6 #include <fcntl.h> 7 #include <errno.h> 8 #include <string.h> 9 10 /* bsd extensions */ 11 #include <sys/uio.h> 12 #include <sys/socket.h> 13 #include <netinet/in.h> 14 #include <sys/un.h> 15 16 #include "priv.h" 17 18 void 19 _sock_ingetaddr(Rock *r, struct sockaddr_in *ip, int *alen, char *a) 20 { 21 int n, fd; 22 char *p; 23 char name[Ctlsize]; 24 25 /* get remote address */ 26 strcpy(name, r->ctl); 27 p = strrchr(name, '/'); 28 strcpy(p+1, a); 29 fd = open(name, O_RDONLY); 30 if(fd >= 0){ 31 n = read(fd, name, sizeof(name)-1); 32 if(n > 0){ 33 name[n] = 0; 34 p = strchr(name, '!'); 35 if(p){ 36 *p++ = 0; 37 ip->sin_family = AF_INET; 38 ip->sin_port = atoi(p); 39 ip->sin_addr.s_addr = inet_addr(name); 40 if(alen) 41 *alen = sizeof(struct sockaddr_in); 42 } 43 } 44 close(fd); 45 } 46 47 } 48