SUN 386i bind() problem

mrevox!rwu at bellcore.bellcore.com mrevox!rwu at bellcore.bellcore.com
Thu Mar 30 12:33:30 AEST 1989


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 at 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 ]]



More information about the Comp.sys.sun mailing list