rwu@bellcore.bellcore.com (03/30/89)
Has anyone run into problems with the bind() call on the SUN 386i? I have a program which runs fine on a SUN 4 under 4.0.1 but fails on the 386i under 4.0.1. I create an internet stream socket successfully, but then the subsequent bind call fails with an error return of EADDRNOTAVAIL. Any ideas as to what I might be doing wrong? The offending section of code is attached below. Ron Underwood UUCP: bellcore!rwu ARPA: rwu@bellcore.com (201) 829-3317 Bell Communications Research 435 South St. Room 2D-392 Morristown, NJ 07960-1961 __________ main() { struct servent *service; struct protoent *protocol; struct sockaddr_in name; struct sockaddr_in conn; int s,ns,pn,connlen; if (fork()) exit(0); signal (SIGCHLD, reapchild); for (s = 0; s < 20; s++) (void)close(s); (void)open("/", 0); (void)dup2(0, 1); (void)dup2(0, 2); if ((s=open("/dev/tty", 2)) >= 0) { (void)ioctl(s, TIOCNOTTY, (char *)0); (void)close(s); } logfile = fopen(LOGFILE,"a"); if(access(HISTORY,R_OK) == -1){ logmsg(errno,"Can't access history file"); exit(1); } service = getservbyname("rnews","tcp"); if(service == NULL){ logmsg(0,"Unknown service"); exit(1); } protocol = getprotobyname(service->s_proto); if(protocol == NULL){ logmsg(0,"Unknown protocol %s",service->s_proto); exit(1); } pn = protocol->p_proto; s = socket(AF_INET,SOCK_STREAM,pn); if(s == -1){ logmsg(errno,"Cannot create service socket"); exit(1); } name.sin_port = service->s_port; if(bind(s,(struct sockaddr_in *)&name,sizeof(name)) == -1){ logmsg(errno,"Socket bind failed"); exit(1); } [[ You need to "bzero(&name, sizeof(name));" before using it! If it worked on a Sun 4 then it was luck. --wnl ]]
craigt@ucbvax.berkeley.edu (Craig Thomas) (04/21/89)
mrevox!rwu@bellcore.bellcore.com writes: >Has anyone run into problems with the bind() call on the SUN 386i? The trouble is the difference in byte order for your Sun386 host and the network. Check into the man page BYTEORDER(3N). Change is needed for at least this line: > name.sin_port = service->s_port; should be: name.sin_port = htons(service->s_port); Craig Thomas 415-596-3646 {sun,lll-tis,pyramid,pacbell}!sybase!craigt Sybase, Inc., 6475 Christie Avenue, Emeryville, CA 94608 craigt@sybase.com