Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!esosun!ucsdhub!hp-sdd!artecon!tony From: tony@artecon.artecon.UUCP (Anthony D. Parkhurst) Newsgroups: comp.unix.questions Subject: Another problem with recvfrom socket call Message-ID: <438@artecon.artecon.UUCP> Date: Tue, 5-May-87 13:50:39 EDT Article-I.D.: artecon.438 Posted: Tue May 5 13:50:39 1987 Date-Received: Thu, 7-May-87 06:39:39 EDT Organization: Artecon Inc., San Diego Lines: 97 Keywords: help Ok, I am now using SOCK_DGRAM, and the recvfrom call is successful, except that it doesn't put the sender's address in the 'from' parameter. Also, the manual says that if the from parameter is non-zero (not a null pointer), then it fills in the sender's address. This implies that if I don't want the address, I can just pass a NULL pointer, But, this errors with "Bad Address". ( BTW, I am using Sun 3.2 ) (Oh, BTW, please don't tell me that this will only work with AF_INET and NOT AF_UNIX, I would rather it work in the UNIX domain :-) Here are the program frags: Server: #include #include #include #define SOCKNAME "/tmp/tonys" main() { int s,ns; /* socket descriptors */ static struct sockaddr name = {AF_UNIX,SOCKNAME}; static struct sockaddr nname; int nnamelen; int imsg; if ((s=socket(AF_UNIX,SOCK_DGRAM,0)) < 0){ perror("cant open socket"); exit(-1); } if(bind(s,&name,sizeof(name)) < 0){ perror("cant bind to socket"); exit(-2); } nnamelen = sizeof(nname); if(recvfrom(s,&imsg,sizeof(imsg),0,&nname,&nnamelen) < 0){ perror("server recvfrom error"); exit(-5); } fprintf(stderr,"Recv int: %d\n",imsg); fprintf(stderr,"Recv family: %d, nname: %s\n",nname.sa_family,nname.sa_data); /* Works fine to here, gets the proper message, however, the result in nname is : nname.sa_family == 1, nname.sa_data == "" (no name or address */ /* SO, I can't return a message since I don't have the sender's address */ client: #include #include #include #define SOCKNAME "/tmp/tonys" #define SOCKNNAME "/tmp/tonyc" main() { int s,ns; /* socket descriptors */ static struct sockaddr name = {AF_UNIX,SOCKNAME}; static struct sockaddr nname = {AF_UNIX,SOCKNNAME}; int namelen; int nnamelen; int imsg; if ((s=socket(AF_UNIX,SOCK_DGRAM,0)) < 0){ perror("cant open socket"); exit(-1); } if(bind(s,&nname,sizeof(nname)) < 0){ perror("cant bind to socket"); exit(-2); } imsg = 345; /* arbitrary */ if(sendto(s,&imsg,sizeof(imsg),0,&name,sizeof(name)) < 0){ perror("send error"); exit(-6); } /* works to here */ -- **************** Insert 'Standard' Disclaimer here: OOP ACK! ***************** * Tony Parkhurst -- {hplabs|sdcsvax|ncr-sd|hpfcla|ihnp4}!hp-sdd!artecon!adp * * -OR- hp-sdd!artecon!adp@nosc.ARPA * *******************************************************************************